Cannot create menu item from a script and MCG (2017)

Cannot create menu item from a script and MCG (2017)

I_Megaman_i
Collaborator Collaborator
941 Views
4 Replies
Message 1 of 5

Cannot create menu item from a script and MCG (2017)

I_Megaman_i
Collaborator
Collaborator
Hey

got a lil problem here, I cannot make a custom macroscript working for these two, there are a macro and a MCG (see attachment)

 

i just want to create a macro and put it in the main menu, normally, i record actions in the listener and create a macro from there, but this works only until i restarted 3ds max. after it gives an error.

I have no idea how to fix it, can you help?

 

thanks!

0 Likes
Accepted solutions (2)
942 Views
4 Replies
Replies (4)
Message 2 of 5

Swordslayer
Advisor
Advisor
Accepted solution

Multiple ways, and also depends on the macro you are creating, without posting it, it's hard to help. Post it and I'll tell you more.

 

For the scripted plugin (nice to see someone using it, btw.), you can put it in the stdscripts folder instead so that it would already be in scope when the macro is evaluated at startup. You cannot do that with the mcg, though. What you can do instead (and that applies to both the scripted plugin and the mcg) is use the global namespace operator :: to force lookup in the global scope instead of assuming a local undefined variable. So a HelicalCylinder call would be replaced with ::HelicalCylinder, for example.

Message 3 of 5

Alfred.DeFlaminis
Alumni
Alumni
Accepted solution

Hello @I_Megaman_i,

 

Based on the helpful tips by @Swordslayer I was able to hack something together here that is working for me.  Please note that I am not a programmer, I have made a couple scripts here and there but nothing on the level of Vojtech Cada.  So, there may be a better way to do this, but here is what I've found and how to do this.  From what I understand, the reason these don't work after you restart Max is that the function is declared after the script is run so there is an 'out of order' type situation going on.  Here is what I did:

 

1)  Place the helicalcyl.ms file in C:\Program Files\Autodesk\3ds Max 2017\scripts\Startup

2)  Based on the helpful hints by Swordslayer, I made two macroscripts using the following code.  I've attached them to this message, feel free to take my name out or whatever to make your own Category.  If you want to make your own files rather than use the attached ones, create two files with the following in blue inside. (Note the :: as mentioned by Vojtech.)  

Script 1) Helical_Cylinder Macroscript  (Helical_Macroscript.mcr)

macroScript Create_Helical_Cylinder category:"Alfred DeFlaminis"

--This Macroscript assumes you have Helical Cylinder installed already


(
startObjectCreation ::HelicalCylinder
)

 

Script 2) RadialClone Macroscript  (Add_RadialClone.mcr)

macroScript Add_RadialClone category:"Alfred DeFlaminis"

--This Macroscript assumes you have MCG_R_Clone_JC installed already

(
modPanel.addModToSelection (::MCG_R_Clone_JC ()) ui:on
)

 

3) Then add these files to this location: C:\Users\%username%\AppData\Local\Autodesk\3dsMax\2017 - 64bit\ENU\usermacros

 

4) Then start Max, go to Customize->Customize User Interface->Menus and add them to your desired Menu.  Restart Max and try it out!

 

I've tested this a couple times now and it's working.  You will get an error if you attempt to run the MCR_R_Clone_JC if nothing is selected.  Please try this for me and let me know if it works for you.  

 

EDIT: Updated script so object can create anywhere.  This was based on a PM I got from Swordslayer.  He also added:
"Btw, there's no need to save the macros anywhere, it's actually better to just evaluate them (CTRL+E) and they will be created there for you - and added to the customize dialog immediately, so no need for restarting max either. "

 

Best Regards,

Message 4 of 5

I_Megaman_i
Collaborator
Collaborator

it works!

 

Im not a proggrammer too, but i knew it has something to do with class declaration and 3ds didnt see it globally! so simple...argh

 

For MCG this way you wont get an error, it will be greyed out if nothing selected:

 

macroScript MCG_R_Clone_JC
category:"Scripts"
tooltip:"MCG_R_Clone_JC"

(
    on execute do AddMod ::MCG_R_Clone_JC
    on isEnabled return mcrUtils.ValidMod ::MCG_R_Clone_JC
)

Anyway, thanks to both of you!

Message 5 of 5

Alfred.DeFlaminis
Alumni
Alumni

I actually learned a lot looking into the issue in this thread, so thank you both too!

Best Regards,

0 Likes