Anybody have an App.saveStateScript example?

I can successfully trigger a script on this callback, but I can't seem to add any code to the state script because the type passed into the callback is a QVariant rather than a DzScript. The documentation is not helpful.

Here I set up the callback:

var sScript = "support/esemwy/testCallback.dsa";var oCallBackMgr = App.getCallBackMgr();var oCallBack = oCallBackMgr.createCallBack( "saveStateScript Callback", sScript, false );oCallBack.setConnection( App, "saveStateScript(DzScript&)" );

Here is the callback script that fires when Studio exits:

var oSender = CallBack.getSender();var sMessage = String( "Sender Class: %1\n" +		 "Sender Name: %2\n\n" +		 "CallBack Args: %3" )		 .arg( oSender.className() )		 .arg( oSender.name )		 .arg( CallBack.getArgCount() );var nArgs = CallBack.getArgCount();if( nArgs > 0 ){   for( var i = 0; i < nArgs; i += 1 )   {	  sMessage += String( "\nArg %1 : %2" ).arg( i ).arg( CallBack.getArg( i ) );   }}// The following code won't work because the arg is not a DzScript// var oScript = CallBack.getArg(0);// oScript.addCode("App.debug(\"HERE IS A MESSAGE\");");sMessage += String("\n===\n%1\n===").arg(DzScript(CallBack.getArg(0)).getCode());MessageBox.information( sMessage, CallBack.className(), "&OK" );

The callback runs without problem unless I actually try to do something to the state script.

Any hints? Alternatively, is there another way to run a script when Studio starts?

Thanks

Comments

  • djigneodjigneo Posts: 283

    Well, if you're getting the Script path that you're passing in (not sure if you are based on your description), could you just construct your own DzScript and continue with what you're trying to do?

    Here's an example of constructing and executing a DzScript from the path: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/remote_operation/sub_script/start

    The output that you are getting in this example would be most helpful. I only know the callback script is executing, but no idea what the informational messages are coming out as, so I'm having to speculate as to what's going on.

     

  • EsemwyEsemwy Posts: 578

    The problem I'm having is in the callback script. The signal "saveScript(DzScript&)" is supposed to send a reference to a script object that Studio will save during shutdown and then call when the program restarts. The problem is that when the callback runs, the "Callback" getArgument method returns a QVariant rather than a DzScript. As such, I can't append a code snippet that will execute when the program restarts. 

    All of this is so that I can have a script thet runs when DS starts. If there's another way to do it, I'd love to see it. Otherwise, this is the only method I've found to get a script to execute when Studio is initialized. 

  • PraxisPraxis Posts: 247
    edited February 2017

    I tried using QVariant methods like .toString() and .toStringList() on your Callback.getArg(0) example - without success, as I'm sure you did.

    This may work - its far from ideal, but it may be good enough? (I haven't tried it):

    1. Create and save a simple Scene file containing an Element that you have set up with an attached DzSimpleElementScriptData, as per this sample: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/elements/post_load_script_data_item/start, which should allow you to have a script execute when that Element loads.
    2. Then use "Edit > Preferences > Startup: Load File" to set that Scene file as the Start-up Scene.
    Post edited by Praxis on
  • EsemwyEsemwy Posts: 578
    Praxis said:

    I tried using QVariant methods like .toString() and .toStringList() on your Callback.getArg(0) example - without success, as I'm sure you did.

    This may work - its far from ideal, but it may be good enough? (I haven't tried it):

    1. Create and save a simple Scene file containing an Element that you have set up with an attached DzSimpleElementScriptData, as per this sample: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/elements/post_load_script_data_item/start, which should allow you to have a script execute when that Element loads.
    2. Then use "Edit > Preferences > Startup: Load File" to set that Scene file as the Start-up Scene.

    That's what I'm using presently. I was looking to do something a bit more elegant, for use in a freebie. 

  • ChoholeChohole Posts: 33,604
    Esemwy said:

    The problem I'm having is in the callback script. The signal "saveScript(DzScript&)" is supposed to send a reference to a script object that Studio will save during shutdown and then call when the program restarts. The problem is that when the callback runs, the "Callback" getArgument method returns a QVariant rather than a DzScript. As such, I can't append a code snippet that will execute when the program restarts. 

    All of this is so that I can have a script thet runs when DS starts. If there's another way to do it, I'd love to see it. Otherwise, this is the only method I've found to get a script to execute when Studio is initialized. 

    http://docs.daz3d.com/doku.php/public/software/dazstudio/4/change_log#4_9_4_39

  • EsemwyEsemwy Posts: 578
    Chohole said:
    Esemwy said:

    The problem I'm having is in the callback script. The signal "saveScript(DzScript&)" is supposed to send a reference to a script object that Studio will save during shutdown and then call when the program restarts. The problem is that when the callback runs, the "Callback" getArgument method returns a QVariant rather than a DzScript. As such, I can't append a code snippet that will execute when the program restarts. 

    All of this is so that I can have a script thet runs when DS starts. If there's another way to do it, I'd love to see it. Otherwise, this is the only method I've found to get a script to execute when Studio is initialized. 

    http://docs.daz3d.com/doku.php/public/software/dazstudio/4/change_log#4_9_4_39

    Cool. Thanks for the info!

Sign In or Register to comment.