[Closed] Launch script from commandline with arguements
Hi there,
this seems really simple but i’m stuck (as usual!)
I have a script for batch import and batch export. I want to fire it up from the command line.
I know that i can launch max using something like:
3dsmax -U MAXScript batchexporter.ms
but how can i pass the input and output directories to the script via the command line?
currently the script has a pair of buttons. which prompt for the directory but i’d like to make it read from the command line arguements.
Is this possible if so how?
Many thanks
David
i can’t give an answer of your question, but try to force the script to read the input and the output dirs from ini or txt file.
thats one idea but it would be difficult to be able to run this batch import more than once at the same time – e.g. on a server handling requests from many people…
i read somewhere that i can pass maxscript written on the command prompt… might this help us?
I never did something like that but from reading the help file cant you do something like:
3dsmax -mxs “global inputdir = @“C:\TEST_INPUT”;global outputdir = @“C:\TEST_OUTPUT”;filein batchexporter.ms”
or
3dsmax -mxs “global inputdir = @“C:\TEST_INPUT”;global outputdir = @“C:\TEST_OUTPUT”” -U MAXScript batchexporter.ms
Dunno if this works but it’s worth the shot, then in your batchexporter.ms script you would replace the input and output path to those two variables created.
Hope this helps, cheers!
thanks – i’ve just tried this however max seems to open then immediately die and close without giving me any error boxes… how can i work out whats going on ?
How about trying to open max with a path to a script that defines the global path directories? then you can call a filein at the end of this script to run your batch exporter.
i.e.
3dsmax -U MAXScript definebatchexporter.ms
[I]definebatchexporter.ms[/I]
Global BatchEx_InDir = getdir #scripts
Global BatchEx_OutDir = getdir #export
filein (getdir #scripts + "batchexporter.ms")
Pete that would work but then he couldn’t pass the input and output dir as a command line argument which it seems what he wants maybe because he needs to run this several times with different I/O paths.
I guess that with my solution the problem might be in the syntax, I’ll try to have a look at it tomorrow.
Cheers!
You’re right Artur. I’ll have to dig out my unity research and see what I read about this I can’t remember off the top of my head. From what the help says, it’s possible to specify the -mxs switch before sending the -MAXSCRIPT switch to open the file. The thing I can’t work out is how to enclose the string within the string in the commandline argument. I’d be interested if you can do something with the syntax to pass the globals before executing the script file.
edit – Just looked over some files, in the examples I saw the Unity class builds the .ms file from a string before calling it via commandline. You could try to hardcode folder paths into this if you are using this method.
One idea that I had was to add the in/out directories to an XML file (or .ini if you like) from the C# class and let max read them in when it executes the script by commandline.
However the process.start issue stopped me from getting further, then, as always something else came along. :rolleyes: The other thing i thought is if you can hook up an external dotnet class to the current max instance, then you might be able to use the managedservices.dll to send functions, variables etc via the MaxscriptSDK. I’ve only used it in an assembly that is started within the max window.
Apologies if this is sliding off topic to the original question!
I just thought of something that also might work. You could write your script so that it runs inside a function that has two args:
global batchio
Function batchio idir odir =
(
…code goes here…
)
Then you would save this in the startup folder, so it runs every time max gets open.
After just call 3dsmax -mxs “batchio @“C:\TEST_INPUT” @“C:\TEST_OUTPUT” “
Again sorry if this doesn’t work but I’m not on my workstation and I’m writing this by heart.
hey guys, i’m following your discussion but i can’t understand the point. why the export/import batch has to be done by command line? is there any reason to do it faster, parallel, safer? where is the goal?
Hello Denis,
The example I have used this for is for interop from a 3rd party application like Unity. You can use C# classes from there and trigger max to open exported meshes, add things like a pro-optimize mod, collapse, and save to another directory, ready to be reimported to your project.
The big problem I had was to do with the fact that the system.process class always opens a new instace of max, it wont use the current instance. I never did work out how to get it to fire the commandline without opening a new session. (no joy looking on the web either from what I remember but you might know a clever way with window handles??) :-/
hi Pete.
that’s exactly what i worry about. every time with command line running you have to open a new max instance.
why is not easier to open max once and call open/import/export batch script after?