[Closed] Custom Save Dialog?
Hey all,
I’m [very] new to 3ds Max and MAXScript…coming from the Maya/MEL/Python/PyMEL world. We’re trying to integrate 3dsMax into a predominantly Maya-based pipeline, and I’ve been given the task of helping to make this integration as seamless as possible. One of the goals is to integrate some custom Open and Save dialogs that have been built in QT for Maya into 3ds Max, and I’ve got a list of items I’m trying to figure out to make it happen.
My first question – when Max is initializing, what files/scripts is it looking at to set up script paths, plugin paths, etc? In Maya, we can set environment variables at the system level or via a maya.env file located in the user’s preferences directory. The environment variables control things like script paths (“MAYA_SCRIPT_PATH”), the location of the user’s home directory (“MAYA_APP_DIR”), etc. Is there anything like that in Max? Also, files named userSetup.mel and userSetup.py are automatically run when Maya starts, which provides a way to fire off other scripts that need to be run every time Maya starts. Is there a Max equivalent? I’m looking for a way to have the scripts that are in a shared repository accessible, and to possibly fire some of them off when a user starts Max on their local machine.
So the second part of this is hooking into Max’s UI. In Maya, the whole UI is built with MEL, so once I know what command is being called for a particular menu item I can override it. I simply run my own script (which I would fire off from that userSetup.mel file) that overwrites it with my own command, and write a script for that command that builds my custom menu. Is there a way to do something similar in Max?
Apologies if any of this is remedial – I’m trying to learn the things I need to just make this happen as quickly as possible. Thanks in advance for the help!!
Yup, the Scripts\Startup folder… anything in there will be loaded on Max Start, as well as stdplugs\stdscripts . In addition, you can actually add paths to your plugin.ini and max would load .ms files from there as well. Within those ms files you can load other ms files, create global variables, etc…
You can override the default toolbar / macro actions with your own scripts. For instance you can at the very least bring up the generic ‘save’ dialog which allows custom filetypes and predetermined folders using getSaveFileName to pick the file/folder to save manually (perhaps just brings you to a specific folder) and then use savemaxfile to actually save the file itself (or use savemaxfile with a custom ui completely). Overriding the toolbars is relativly straight forward as well… and isn’t too complicated either, look up menuMan in the help file.
Thanks! The menuman stuff looks like just what I need for working with the menu items
Let me make sure I understand this macroscript business properly: UI items have corresponding macro scripts, and that macroscript defines the procedures that are executed when that UI item is clicked?
I’m a little confused about the difference between a macroscript and a normal maxscript. If I want to do x when someone clicks “file/save as…”, do I write a maxscript for x or do I write a macroscript for x?
Sorry if this is confusing…I’m used to everything just being .mel I appreciate the help!
Macroscript is basically any maxscript with some additional definition info that allows you to assign it to a button or toolbar (in the help file), and will show up under customize -> customize user interface, it can even be as simple as a filein to another maxscript. When you execute a macroscript as a ‘run script’, it actually will put it into the custom scripts folder (ui\macroscripts or ui\usermacros …I don’t remember the specifics here), and not necessarily really run the code inside the macroscript scope. It will basically add it to your customize ui menu, and then you’ll have to add it to a toolbar, keyboard command, or menu to run the script. Otherwise, a ‘normal’ maxscript is one that will actually execute on it’s own, and will not show up in the customize menu. A pretty normal thing to do with a macroscipt would be to filein a separate .ms file that it represents instead. But really, you’ve got it right. If you were going to have a script browser to look at scripts on a server, you probably won’t want them all to be macroscripts for instance, you’ll want to just run the scripts, but if you want to add them to a max toolbar, then you’ll need the macroscript code which is literally this:
macroScript MyAwesomeScript
category: "AwesomeScripts"
toolTip: "MyAwesomeScript"
buttonText: "MyAwesomeScript"
Icon:#("AwesomeScripts_MyAwesomeScript" , 1) --ui/icons folder
(
-- the rest of your script code
)
That is probably an overkill of an explanation, but should get you going.
Edit: Just wanted to mention if you have a script open in the editor, you can actually do the whole drag & drop onto a toolbar, and it’ll create a macroscript for you under the drag & drop category… not something you’ll probably use, but might help you get how it works.
I’m a little confused about the difference between a macroscript and a normal maxscript. If I want to do x when someone clicks “file/save as…”, do I write a maxscript for x or do I write a macroscript for x?
The difference between a script and a macroscript is the same as between a Mel script and a shelf button or menu item calling or including a mel script.
You can’t directly modify the file/save as … command in Max.
But you can replace the menu item ‘file/save as…’ with yours:
create a macroscript
edit the file menu to remove the existing ‘file/save as…’ and insert your macroscript in the same place
maroscript File_save_as
category:"any"
tooltip: "Save as..."
(
-- include "MySaveAs.ms" or type the maxscript code here
My_File = getSaveFileName caption:"save As..."types:"Max (*.max)|*.max|MyFiles(*.ext)|*.ext|All|*.*|"
)
To modify the file menu, either make another script to programatically change the menu, or save a .cui file after you edit the file menu using the customize/customize user interface dialog.
Cool I messed for a while today with trying to edit items in that weird “File” menu that Max has, but never got it to work. I could edit stuff in the other menus though…and after talking to my sup today, it sounds like it’s not a huge deal to just add our own menu instead of replacing the default stuff in Max. I’m sure we’ll be editing some of the other stuff at some point, so I’m sure this will come in handy.
Believe me, no explanation is overkill to me… I have a whopping 3 days worth of experience in 3ds max at this point ;). It feels weird to dive into a project like this with so little knowledge of the software I’m working in, but hopefully this stuff starts sticking soon. Thanks a bunch for the help, very useful info!
Oh yeah, I’ve no idea about max 2010’s new retarded file menu… You should still be able override the Ctrl+S shortcut at least, and add your own file menu in addition to the big default one. I think the 2009 ui adds that file menu back in (in addition to the big ugly one)… but yeah, building your own will make more sense, along with overriding the ctrl-s that most people will instinctively use.