Notifications
Clear all

[Closed] DosCommand launches Instance2 of Max, freezes Instance1

Alright so there is a simple problem, that is annoying me.

I made a script which do the following :

Instance 1 creates a .bat file, executed by HiddenDosCommand(). The bat file just opens a new instance of Max (Instance 2), and passes a script as parameter. The problem is, as long as this script is not finished in Instance 2, Instance 1 of max is frozen, as if ShellLaunch was busy waiting for a return value from the *.bat file, itself waiting for a return value from Instance 2.

If I use donotwait:true with HiddenDosCommand, Instance 2 is launched, but :

  • It pops up the display driver dialog
  • The script is not executed

Any solution to avoid this freeze ?

8 Replies
2 Replies
 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

This sounds a bit like you wrote -v instead of -u :curious:

(@groutcho)
Joined: 11 months ago

Posts: 0
batname = symbolicPaths.getPathValue "$temp" + "\\export2010.bat"
createFile batname
batFile = openFile batname mode:"w"
format "%" ("\"C:\Program Files\Autodesk\3ds Max 2010\3dsmax.exe\" -U MAXScript " + filename) to:batfile
close batFile 

HiddenDosCommand batname donotwait:true prompt:false

there might be an easier and more elegant solution but you can try dotnet background worker to run your code. Search for dotnet background worker in this forum, you should find some examples if you need.

Thanks, I’ll look into that.

 lo1

If launching another instance is important, you can run a dotnet process:

(dotnetClass "System.Diagnostics.Process").Start ((getDir #maxRoot) + "3dsmax.exe") ("/u \"" + yourmaxscriptfile + "\"")

It will not wait by default.

If you do want to block the thread until the process exits, use the .WaitForExit() method on the process instance returned.

Thanks, I’ll try that

 lo1

Does not work for me at all, I receive this message on HiddenDosCommand:

-- Error! CreateProcess(cmd /e:on /d /c "C:\U...

But I think I should point out a few things in your code nonetheless:

[ul]
[li]createFile command already returns a filestream value, there is no need to use openFile after it. e.g.:
[/li]

batFile = createFile batname

[li]in the format command you are escaping the ” characters properly, but not the backslash characters. This would be a problem if you had any directory names that start with T or N.
[/li]

\"C:\\Program Files\\Autodesk\\3ds Max 2010\\3dsmax.exe\"

[li]The Prompt argument of hiddenDosCommand is not a boolean, it accepts a string that can optionally be displayed in the status bar of the opened 3dsmax instance.
[/li][/ul]

This is the same code using a dotnet process, which does work:

batname = symbolicPaths.getPathValue "$temp" + "\\export2010.bat"
batFile = createFile batname
filename = @"c:	est.ms"
format "%" ("\"C:\\Program Files\\Autodesk\\3ds Max 2009\\3dsmax.exe\" -U MAXScript \"" + filename + "\"") to:batfile
close batFile 

procInfo = dotNetObject "System.Diagnostics.ProcessStartInfo" batName
procInfo.useShellExecute = off
procInfo.createNoWindow = on
proc = (dotNetClass "System.Diagnostics.Process").start procInfo

--proc.WaitForExit() --if you wanted to block until the process is killed

Thanks for the advice. Now with (dotnetClass “System.Diagnostics.Process”), I don’t need to create a bat file anymore. The parameter “-U MAXScript” work fine.