Maxscript: when dos the sim end!

Hi,
Im converting one of my fumeFX network sim/render scripts to support Phoenix and I need to be able to start the sim via maxscript (no probs here, A_StartSim $).. But I also need to find out when the sim stops.
With FumeFX the next line of code only executes after the sim has finished, but Phoenix is more interactive and executes it immediately!
How do I get around this?

edit:
I could redefine the OnSimulationEnd function and check the use script check box but I would rather not change this in-case its being used to to other stuff..
Also does having useScript turned on slow down the simulating like it does with FumeFX (multitasking disabled when using maxscript in simulation)

(
A_StartSim $
fn OnSimulationEnd = (print “Finished”)
)

unlike the fume, phoenix does not block the max during the sim and this is the reason why the next instruction is executed immediately after the start. the script can be used without any measurable slowing down, of course only if no action is executed in OnSimulationStep. and to the question - i think there is no other way, OnSimulationEnd is made for this purpose. if you are afrayd that it could be used for other stuff (wrom who?) you can try to keep its content (if max script is able to do this) and to redefine it after that, calling at the end the old function.

Ok. Storing the OnSimulationEnd function works fine. My other problem is that im trying to get phoenix to simulate on the network using deadline as a maxscript job.As far as I can tell this isnt possible as the maxsript code finishes and deadline believes the job is done when Phoenix has just started simming. It seems to me there needs to be a simming mode that is non interactive so simming jobs can be done in deadline or done with a batch maxscript.
This is the kind of thing I was attempting:


(
	result = undefined
	A_StartSim $
	tempOnSimulationEnd = OnSimulationEnd
	fn OnSimulationEnd =
	(
		tempOnSimulationEnd
		result = true
	)
	--while result != true do sleep 1 --This was supposed to wait untill the sim has finished then resume the script, but just locks up max.

	--Id like to do some other stuff here when the simulation has finished
	print result --deadline now knows that the job has finished
)

you are trying to organize the whole process as a continuous sequence of code, like in the good old times :slight_smile:
if the max hangs when sleep is executed, then i’m afraid with phoenix this is impossible and you have to use the event driven concept. this means - replace result=true with the real action that you need to be executed after the simulation. for example, if you need to start the rendering, just start it in OnSimulationEnd, do not use a flag and do not perform pending over this flag.

I would love to do all my processing in the OnSimulationEnd but network simulation using Deadline wont allow this as it waits for the script to finish then the network will force quit max thinking that the job has completed, probably before the first frame is even simulated. That is why I setup the example code as I did.
Phoenix will not be very production friendly with out some way to achieve network simulation or batch simulation. Im am doing some RnD for a large job and this type of functionality would be vital, especially with deadline!
What are your plans for network/batch simulation?

ok, i will try to do something for this

ok, i just made a new script function, that can wait the end of the simulation, keeping the whole max alive. this can be very confusing, because the function blocks, but the max is alive and you can change the script calling the function, or some other mad things :slight_smile: the function is named a_wait and will be available in the next build

Great! This will be very useful! Thanks :slight_smile:

How does one use A_wait? Some example would be nice!! :slight_smile:

Okay. I found it in the documentation of PhoenixFD. Sorry. :wink:

A_StartSim $PhoenixFD001
-- this holds the script execution.
A_wait $PhoenixFD001
-- after simulation finishes, the next lines are executed.
print “finished!”
[…]

Is there any MXS inteface to the restore button? The reason I ask is that I was simming a 55million cell job on our farm when all of a sudden the sim broke for some reason and started simming only 5K files. restoring from the last good frame from a local machine worked fine but there doesnt seem to be a way to get a farm job to do the same… Any ideas?

Dave

You can try tomorrow’s nightly build for this functionality. If you don’t have access to the nightlies, ask the support :slight_smile:

Restore will be done with the A_StartSim() function. It takes three parameters, two of them are optional:
node:<Simulator>
[cache: <String>]
[startframe: <integer>]

Passing just the simulator node will start a new simulation.

If you pass the path to a cache file, the effect will be that of the Load button - the simulation state will be loaded from the cache and the simulation will continue from the Starting Frame (parameter in the Simulation rollout).

And if you manually pass the startframe index too, it takes precedence over the Load function and the simulation will be RESTORED from the given frame, the same way that the Restore button works.

Also, this function will decide between simulation and re-simulation depending on the state of the Particle Resimulation and Grid Resimulation switches :slight_smile: