Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Getting errors with macroscript

Getting errors with macroscript

Alphα
Participant Participant
1,484 Views
5 Replies
Message 1 of 6

Getting errors with macroscript

Alphα
Participant
Participant

Hello,

 

I'm getting started with maxscript and I've been trying to make experiments creating a script which add a custom menu filled with my own macroscripts located in a specific folder.


I had something like this in mind : Sadly the script always returns issues concerning the syntax. 

 

fn CreateMenu Name:"Name" Title:"Title" ParentMenu: =
(
	MenuItem = menuMan.CreateMenu Name
	MenuItem.setTitle Title
	SubMenuItem = menuMan.createsubMenuItem Name MenuItem
	if ParentMenu != undefined do ParentMenu.addItem SubMenuItem -1
	MenuItem
)

-- Define the path to the script folder
scriptFolder = "C:\\Program Files\\Autodesk\\3ds Max 2023\\scripts\\SC_Tools\\"

-- Create a new menu under the main menu bar called "SC Tools"
scToolsMenu = CreateMenu Name:"SCTools" Title:"SC Tools" ParentMenu:MainMenu

-- Loop through each script file in the folder and create a new menu item for it
for scriptFile in getFiles (scriptFolder + "*.ms") do
(
    -- Load the script file into memory
    fileInMemory = openFile scriptFile
    scriptContents = readString fileInMemory
    close fileInMemory

    -- Create a new macroscript category and assign the script to it
    macroScriptName = substituteString (getFileNameFile scriptFile) " " "_"
    macroScriptCategory = macroScript macroScriptName category:"SC Tools"
    macroScriptCategory.script = scriptContents

    -- Create a new menu item for the script
    menuItem = scToolsMenu.addItem (getFileNameFile scriptFile)
    menuItem.menuItemScript = ("macroScript " + macroScriptName)
)

-- Refresh the UI to display the new menu
menuMan.updateMenuBar()

 



I've been trying to read the documentation really closely and try simple things but it seems that even the code provided by the doc isnt working.

This page seems to sum up what I'm looking to do but if I simply copy paste the code in a .ms inside the startup folder it doesnt work. 

I'm a bit confused. I'm using 3dsmax 2021 / 2023 and the script refuses to work on both. Am I missing something ?


Thanks!

0 Likes
1,485 Views
5 Replies
Replies (5)
Message 2 of 6

michael_grosberg
Advocate
Advocate


OK, so to add a menu you need an MCR file not an MS file. this adds a small wrapper around the script that has information such as the title to use in a menu or icon to use in a toolbar. Once you reformat your scripts as MCR files, I'm still not sure this will work.

https://help.autodesk.com/view/MAXDEV/2023/ENU/?guid=GUID-6E21C768-7256-4500-AB1F-B144F492F055

 

To add an MCR file you first need 3ds max to evaluate it. This should happen as long as they are inside one of the folders that are read on startup. your location should work, but it's write protected by the OS. I suggest putting them in the user macroscripts folder though:

"C:\Users\<UserName>\AppData\Local\Autodesk\3dsMax\<ReleaseNumber> - 64bit\ENU\usermacros"
this should be easier to modify on the fly.

 

Now, your macroscripts are already evaluated at startup, or you can use this:

macros.load [ <path_name_string> ]
to load all macros in a specific path.

 

lastly you add them using the macroscript name rather than the file name:

 

<Interface>menuMan.createActionItem <string>macroScriptName <string>macroScriptCategory
https://help.autodesk.com/view/MAXDEV/2023/ENU/?guid=GUID-1374EDCA-CC8B-4B43-81A5-6ED98DBE01D3

hope this helps. 

0 Likes
Message 3 of 6

Alphα
Participant
Participant

I always thought a ".mcr" file only contained a macro that is essentially a pre-recorded sequence of user actions through the listenner. 

In my case I really need to find the ".ms" files and loop for each of them. So I'm definitely more looking to write a ".ms" script right ?

0 Likes
Message 4 of 6

michael_grosberg
Advocate
Advocate

No, a macro is not what you thought, it is exactly what I said - a wrapper over a script to integrate into the UI.
I have a couple of 3ds maxscript reference links in my replay, you can read more in there.
0 Likes
Message 5 of 6

Alphα
Participant
Participant

I'm a bit lost then. May I ask you how you would takcle the script I tried to do in the first message as a .mcr ?
Or can you show me a quick example to better understand ?

Thanks for your time 🙂

0 Likes
Message 6 of 6

michael_grosberg
Advocate
Advocate

this page has everything you need to know. it's very simple really.

https://help.autodesk.com/view/MAXDEV/2023/ENU/?guid=GUID-6E21C768-7256-4500-AB1F-B144F492F055

0 Likes