Hi all: Sorry to have to avail myself of the forums again, but I’m running into a bit of a blocker here with MAXScript.
Is there any way to pass arguments from MAXScript to Python through python.Execute/ExecuteFile? (kind of like how in duberPython you can pass an array of args to RunFromFile() )
I have a MAXScript UI that I’m trying to have, when a button is pressed, execute an external py file but also pass states of the other UI items (checkboxes, comboboxes etc.) as arguments to the python file when being run. I’ve been exploring if it’s possible to launch the py file with command-line arguments or similar, but haven’t been able to get anywhere so far; python.Execute and ExecuteFile seem pretty limited in their behaviour…
Anyone who has done this sort of MAXScript/Python bridging stuff, I’d really appreciate any pointers you could offer here. Thanks!
(Can’t comment much on 2015 and its python integration as we’re still on 2013, but here’s a legacy solution: )
If the script is strictly external and doesn’t interact with 3ds max, you could get away with DOScommand() and HiddenDOScommand(). You could format the arguments to strings, pass them in the command string, then parse them from sys.argv on the script side.
DOScommand ("python \"C:\\path\ o\\your\\script.py\" " + arg1 as string + " " + arg2 as string + " " + and_so_on as string)
HiddenDOScommand() works similar, it’s what you’d use if you want the CMD window not to show.
There’s only so much that can do, though. The command length is limited by windows and dealing with CMD quirks rarely means happy times.
If all else fails, there’s always writing and reading a temp file…
[QUOTE=Zhalktis;26892](Can’t comment much on 2015 and its python integration as we’re still on 2013, but here’s a legacy solution: )
If the script is strictly external and doesn’t interact with 3ds max, you could get away with DOScommand() and HiddenDOScommand(). You could format the arguments to strings, pass them in the command string, then parse them from sys.argv on the script side.
DOScommand ("python \"C:\\path\ o\\your\\script.py\" " + arg1 as string + " " + arg2 as string + " " + and_so_on as string)
HiddenDOScommand() works similar, it’s what you’d use if you want the CMD window not to show.
There’s only so much that can do, though. The command length is limited by windows and dealing with CMD quirks rarely means happy times.
If all else fails, there’s always writing and reading a temp file…[/QUOTE]
Hi, thanks Zhalktis!
I actually started with shellExecute first, but unfortunately the script being run does make use of MaxPlus, so I quickly realized that it wasn’t going to be a feasible solution…the real issue here is that I can’t see anything in the 2015 Python API that would allow me to query any MAXScript rollout dialog control states, which is why I need to pass those in as args at runtime on a button press or something…
I tried doing a subprocess.Popen from within the MAXScript file, but unfortunately that doesn’t work the way I hoped it would (it launches a second instance of 3ds max instead of spawning a sub process of the Python interpreter), so I’m currently out of ideas…
[QUOTE=Mambo4;26904]Write the dialog settings to text file, and read them from python?[/QUOTE]
Yep, that’s what I ended up doing…kind of messy though, but unfortunately I don’t see a better solution at the moment.
Thanks all! If anyone DOES have a more elegant way of doing this, I’m all ears!
Basically you use the python.execute to run python as normal. But you have to format your string in maxscript so it contains the arguments before it is executed. Still hacky but better then a file. You can also return values by doing the same in maxscript and calling MaxPlus.Core.EvalMAXScript(maxScript) and declare a variable.