Message 1 of 6
Getting errors with macroscript
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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!