How to shutdown daz3d with script

What is the script for shutting down daz3d? I wrote a java script to call daz script to render an animation and do something else, but I cannot continue my code unless I close daz3d first. I think there is a fairly easy command for that, but I cannot find it.

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,882

    I'm not sure that there is a shut-down command in DazScript, that would make malicious code rather easy.

  • hphoenixhphoenix Posts: 1,335

    Well, it isn't THAT malicious.  Run the script, it closes DS.  You'd lose what you hadn't saved in that session, but you could get it back, and you wouldn't run the script again.

     

    You should be able to use FindAction() to find the "DzExit" action.  Then just call trigger() on that action.  Should work.....haven't tested, May see if I can do this tonight.

    According to the wiki pages on DzActionMgr(), you'd get a reference to it from DzMainWindow().   Then you can use it to call FindAction().  

     

    So something along the lines of:

    MainWindow->getActionMgr()->FindAction("DzExit")->trigger();

     

  • hphoenixhphoenix Posts: 1,335

    Okay, I got it.  Here you go:

    // DAZ Studio version 4.8.0.59 filetype DAZ Script	var oAction;	var mw = MainWindow;	var am = mw.getActionMgr();	var oAction = am.findAction("DzExitAction");	oAction.trigger();

    When executed, it will cause DAZ Studio to exit just like clicking on "File" then "Exit".

    NOTE:  It may not actually succeed, as if DS needs to save something first, it WILL pop up the "Do you want to save the changes to...." dialog.

     

  • mjc1016mjc1016 Posts: 15,001

    Yep, pops up the save dialog...just like File > Exit.

  • hphoenixhphoenix Posts: 1,335

    Well, one COULD check the scene and see if it needs saving, and do a "save" action before calling the "exit" action.  But for a general purpose script, that's probably not a good idea.  For the OPs particular purpose, it might work just fine.

     

  • hphoenix said:

    Well, one COULD check the scene and see if it needs saving, and do a "save" action before calling the "exit" action.  But for a general purpose script, that's probably not a good idea.  For the OPs particular purpose, it might work just fine.

     

    Thanks so much for your code!!!

    I'm wondering how can I quit Daz3d without saving because I won't make any changes to the file and I want the code to continue when I'm not in front of the computer.

  • hphoenixhphoenix Posts: 1,335
    hphoenix said:

    Well, one COULD check the scene and see if it needs saving, and do a "save" action before calling the "exit" action.  But for a general purpose script, that's probably not a good idea.  For the OPs particular purpose, it might work just fine.

     

    Thanks so much for your code!!!

    I'm wondering how can I quit Daz3d without saving because I won't make any changes to the file and I want the code to continue when I'm not in front of the computer.

    Well, if the scene doesn't change, it won't NEED saving, and the save dialog won't pop up.  If you aren't rendering to a preview window, that wouldn't be a problem either, but if the preview window is open, it might have to be closed first.

    Test the code and see if it does what you need.  If not, we'll need to know more about the exact sequence of events so we can know what else might need to be done.

     

  • rbtwhizrbtwhiz Posts: 2,250

    What is the script for shutting down daz3d? I wrote a java script to call daz script to render an animation and do something else, but I cannot continue my code unless I close daz3d first. I think there is a fairly easy command for that, but I cannot find it.

    Take a look at DzScene and DzMainWindow.

    Attempt to save potential modifications:

    if( Scene.needsSave() ){	Scene.saveScene( Scene.getFilename() );}MainWindow.close();

    Do not attempt to save modifications:

    Scene.clear();MainWindow.close();

    -Rob

  • hphoenixhphoenix Posts: 1,335
    edited June 2016

    Well, THAT put us in our place.  And here I thought I was being clever......cheeky

     

    But seriously, thanks for showing us the 'correct' way to shutdown DS via script.  So the MainWindow is the central event loop control, so that when it closes, the rest of the app goes through its shutdown process?  And won't Scene.clear() prompt you if your scene isn't saved?  Or is there a different parameter/method for that?

     

     

    Oh, and btw Rob.....I came across a slight bug/issue.  If you are debugging in the Script IDE, and you pop up a modal dialog in script that doesn't have a cancel option?  DS effectively locks up, and you have to kill it from the Task Manager.  I had this happen last night with a startProgress(...) call as I was stepping through the code......no way to close it and couldn't stop the debugger/script.

    Is this a known problem?

    Post edited by hphoenix on
  • RenhaRenha Posts: 12

    Hello.

    I've tried both methods, and both leaves Daz process running, consuming 0% of CPU but keeping all the memory Studio was using.

    How to deal with that?

  • Seven193Seven193 Posts: 1,080
    edited February 2019

    This thread was posted 3 years ago.  Maybe it doesn't work anymore.

    But, I have a different question.  Can a script or plugin prevent Daz Studio from shutting down if they click File -> Exit?
    If so, how?

    Many times I have accidently shut down Daz Studio after rendering for hours, forgetting to save my render.  And when DS does shut down, it flushes the temporary folder, so there's nothing there to recover.

    Post edited by Seven193 on
  • hphoenixhphoenix Posts: 1,335
    Renha said:

    Hello.

    I've tried both methods, and both leaves Daz process running, consuming 0% of CPU but keeping all the memory Studio was using.

    How to deal with that?

    The DS process can take a while to shutdown completely (even after an Exit)......up to several minutes.  If it's not completely shut down after that, then your process is hung.  At that point, you'd be better off simply killing the process programmatically using an external call (or a simple C/C++ or Java executable that looks for it and does a kill).

     

  • hi, is there any news about the shutdown ?

     

    if i run inside the script ide console, Daz3D is closing without any problems, after few seconds the process is gone. if i run the same command inside the script, Daz3D is inside the taskmanager forever. its easy to recreate, i can provide the script and sample scene.

    Scene.clear();MainWindow.close();
Sign In or Register to comment.