Hi,
First of all you can't replace menu items by scripts. The best way to achieve your goals is to make a custom menu that will contain the custom import geometry script and all others scripts.
To make your custom menu, you need to create 3 files: init_menu.py, _populate.py, _show.py. Obviously, the name of the files doesn't matter you can set what you want but for the example it is easier like that.
The folder tree like this:
- Code: Select all
init_menu.py
ScriptFolders |_populate.py
|_show.py
| Script1.py
|...
python code
# init_menu.py
menu = ix.application.get_main_menu() # Get the menu container
menu.run_file("./ScriptFolders/_populate.py") # Run the script which will populate our menu
Now we have to make a choice: is the the menu static or dynamic?
- If we never want our menu to change (static menu), then we don't need a "_show.py"
- If we want to add lots of script in the folder and refresh the menu without restarting Clarisse, then the menu will be dynamic: everything will be in _show.py
Everything in _populate.py is created on Clarisse loading and everything in _show.py will be created when you click on the menu.
To make your choice, it's very simple: it depends if you use shortcuts or not?
-> If not, fill the _show.py file otherwise,
-> fill the line that contains your shortcut inside _populate.py (in order to use it without clicking on the menu first).
python code
# _populate.py
menu = ix.application.get_main_menu() # Get the menu container
menu.add_command("name_of_your_menu>") # Create the menu
menu.add_show_callback("name_of_your_menu>", "./_show.py") # Call _show.py file to fill the menu
menu.add_command("name_of_your_menu>Item Name", "./Script1.py", "Shortcut") # Create an item add_command("menu_name>item_name", "script location", "shortcut")
If you want to fill only the _populate.py file, you needn't line n°4, or else fill the _show.py:
python code
# _show.py
menu = ix.application.get_main_menu() # Get the menu container
menu.remove_all_commands("name_of_your_menu>") # Remove all the content of our menu to recreate it.
menu.add_command(("name_of_your_menu>{Separator}", "", "") # This is a separator
menu.add_command(("name_of_your_menu>Item1", "./Script1.py", "") # This is an item
menu.add_command(("name_of_your_menu>Item2", "./Script2.py", "") # This is an item
menu.add_command(("name_of_your_menu>Item3", "./Script3.py", "") # This is an item
menu.add_command(("name_of_your_menu>{Separator2}", "", "") # This is a separator
menu.add_command(("name_of_your_menu>Item4", "./Script4.py", "") # This is an item
Now we have to say to Clarisse: "Our new menu is over there so please load it at startup

"
To do that edit the clarisse.env file (
http://www.clarissewiki.com/common/configuration_and_environment.html)
- Code: Select all
IX_MENU_CONFIG_FILE=./python/menus/init_menus.py;the_path_of_your_menu/init_menus.py
Run Clarisse and enjoy !
Regards,