Isotropix Forums

Custom menu - replacing/extending default menu scripts

Clarisse Scripting related topics

Custom menu - replacing/extending default menu scripts

Unread postby atnreg » Sun Feb 05, 2017 3:07 pm

Hi!

First, I HAVE read the other two threads about custom menus but they did not give help to this :)

I would like to add some functionality to some Clarisse menu items like Import Geometry.
I thought the IX_MENU.. variables would allow Clarisse to find the .py files from other path if I just duplicate the directory path and put my own path root to IX_MENU_SCRIPT_PATH. But sadly that does not work.

I have even tried to copy the whole menu tree from ./python/menus to my own folder e:/_scripts/cla/menus and set the IX_MENU_CONFIG_FILE to point there but after that the only menu that appears is File and there is only Quit. The Log says not found on each menu .py file. I'm in Windows and all paths are using '/'.

I can add my own menu_init.py to the IX_MENU_CONFIG_FILE but as I want to manipulate File/Import, that does not work as it gets populated dynamically. So instead I could make my own version of import_geometry.py etc. but I don't understand how to do that based on my experience above.

So please could someone explain two things (so that when Clarisse updates, my customizations are not lost, i.e. no changes to files in Clarisse program folder tree):
1. How to customize menus using custom folder for menu scripts
2. How to replace existing menu action scripts with custom versions

Thank you very much :)

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender,Fusion360,Houdini,ZBrush,Onyx,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 488
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Custom menu - replacing/extending default menu scripts

Unread postby bvaldes » Mon Feb 06, 2017 10:16 am

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,
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Custom menu - replacing/extending default menu scripts

Unread postby atnreg » Mon Feb 06, 2017 2:11 pm

WOW thank you VERY much for this extensive explanation :o :)
Too bad the menu items cannot be replaced but now I know EVERYTHING about customs menus and even on one page :mrgreen:

So there is no way to use my own script instead of default Clarisse 'import geometry'? I mean that wherever the Import Geometry is used, it would call my script instead. Except of course by replacing the script in Clarisse program folder but that is not a good idea as any update overwrites it and new version may have new features so it would need to me examined on everry Clarisse update :)

Thank you very much!

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender,Fusion360,Houdini,ZBrush,Onyx,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 488
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Custom menu - replacing/extending default menu scripts

Unread postby bvaldes » Mon Feb 06, 2017 2:40 pm

Hi again,

It's possible, add this line in init_menu.py:

python code

menu.move_command("name_of_your_menu>", "name_of_the_menu_that_you_want_before_yours>")
# for example:
menu.move_command("Antti's menu>", "windows>")

With this code, your menu will be between "window" and "layout".

About editing the import geometry script, it's not possible. Sorry about that.

Cheers,
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Custom menu - replacing/extending default menu scripts

Unread postby atnreg » Mon Feb 06, 2017 2:48 pm

Ok, good, then I won't try anymore :D

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender,Fusion360,Houdini,ZBrush,Onyx,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 488
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Custom menu - replacing/extending default menu scripts

Unread postby danielbokori » Fri Jan 26, 2018 2:04 pm

Is it possible to extend the menu from startup script? We are working in a network environment, and it'd be nice to have this feature, so I'm not required to add menus on each users' computer.
danielbokori
 
Posts: 13
Joined: Fri Dec 11, 2015 11:34 am

Re: Custom menu - replacing/extending default menu scripts

Unread postby bvaldes » Fri Jan 26, 2018 2:33 pm

Hi,

Yes, it's possible. You have you just have to set the content of the populate.py inside of the startup script.

Regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Custom menu - replacing/extending default menu scripts

Unread postby Braden99 » Fri Jan 25, 2019 3:25 am

What about getting the name of the menu action that was called from within the executed script.

For example if I dynamically populate a menu with item paths of a certain class type (my own in this case), I want the script that is called, to be able to invoke a method call passing along the full path. This would allow less hardcoded scripts to be made to pass along a simple string argument.

It doesn't seem like with the way the script is called, possible to get the action name, or pass it along as argument.

I tried getting the AppMainMenuItem that was clicked, by looking at last focused widget. But that approach returns a higher level widget it appears.
focused_widget = ix.application.get_top_window().get_focused_widget()

Any ideas?
Last edited by Braden99 on Fri Jan 25, 2019 7:41 am, edited 1 time in total.
Braden99
 
Posts: 50
Joined: Mon Jan 08, 2018 3:05 am

Re: Custom menu - replacing/extending default menu scripts

Unread postby desmond » Fri Jan 25, 2019 7:38 am

@antreg, you can create your own shelf, with your scripts, at least i do that, so i have a work shelf with all imports, save as etc, so i dont go to menus(spend too much time and too much clickc). you can copy the menu item functionality to your own and put it to the shelf. The in texmap and import abc are regular from clarisse, the rest is more or less custom. This shelf makes my life easier, cos most of stuff i daily use is there(and dont have to go trough menus for that).
shelf:
Image

As for installing shelves and/or write them, Clarisse Survival Kit is a great example how to check for shelves and update and install from python. Great ayanik guy work from here : https://forum.isotropix.com/viewtopic.php?f=21&t=5102 (a bit of regex and all good). Maybe its not "pure" clarisse way, but it works fantasticly.

edit:
VALDES STRIKES AGAIN!
User avatar
desmond
 
Posts: 48
Joined: Mon Feb 05, 2018 8:46 am

Re: Custom menu - replacing/extending default menu scripts

Unread postby atnreg » Fri Jan 25, 2019 7:45 am

Yes I have done that a lot and actually I have startup script that automatically populates the shelf from my tools :)

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender,Fusion360,Houdini,ZBrush,Onyx,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 488
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland


Return to Scripting
cron