Registering actions with Python

Registering actions with Python

chrisdawlud
Enthusiast Enthusiast
707 Views
4 Replies
Message 1 of 5

Registering actions with Python

chrisdawlud
Enthusiast
Enthusiast

I want to save the actions to make them persistent, but I don't know how. When I open new max session the actions are missing.

missing_actions.jpg

 

Also, by default the action table is named 'MaxPlus registered actions' but I would like to change that.

 

manager_menu = MaxPlus.MenuBuilder(Menu.menu_name)
main_menu = MaxPlus.MenuManager.GetMainMenu()

action = MaxPlus.ActionFactory.Create('HDRI Manager', 'Open', Menu.printMessage)
manager_menu.AddItem(show_action)
position = Menu.getLastPosition()
menu = MaxPlus.MenuBuilder.Create(manager_menu, main_menu, position)
 
 
0 Likes
708 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Looks like there's some code missing but I'll try to give an example of  how we did it for our menu;

 

 

MaxPlus.MenuManager.UnregisterMenu("IO Interactive")

mb = MaxPlus.MenuBuilder("IO Interactive")

action = ActionFactoryReporting.CreateRaising('',"Print  Hello",print_hello)
mb.AddItem(action)

mb.Create(MaxPlus.MenuManager.GetMainMenu())

I think the 'MaxPlus registered actions' name is coming from this;

manager_menu = MaxPlus.MenuBuilder(Menu.menu_name)

No idea what Menu.menu_name is in this context, i just send in a string instead. 

I don't remember exactly what is causing the "missing" labels but I remember seeing that at some point.

 

Now with the code above here those actions are persistent through sessions, which is why I unregister the menu every time (otherwise you flood your workspace_usersave files and certain max windows take forever to open).

 

Hope this can be of some use 🙂

 

0 Likes
Message 3 of 5

chrisdawlud
Enthusiast
Enthusiast

Thanks Martin.

I tried to keep my code short, but it's basically the same as yours. I tested your code, but I'm not sure what ActionFactoryReporting.CreateRaising is. Assuming it does the same as MaxPlus.ActionFactory.Create, I still get the same result. The action table is registered, but it's gone after I restart max. I must be missing some concept here.

max_problem.jpg

0 Likes
Message 4 of 5

Anonymous
Not applicable

Oh yeah I'm sorry I forgot to mention, my colleague extended the  MaxPlus.ActionFactory.Create function so we could output the exception, the default function only prints a string that tells you that "something went wrong" which isn't very helpful...

 

What code do you run to print that output of yours? I would like to run the same so I can compare because I honestly don't know why it's not persistent for you.

0 Likes
Message 5 of 5

chrisdawlud
Enthusiast
Enthusiast

I got it from the example shown here. I have no idea why the loop range is decremented. I just changed it, otherwise it doesn't print the last action table.

for i = 1 to actionMan.numActionTables do

 

0 Likes