Executing a script from another script; passing in arguments.
Author: Rob Whisenant, © 2008
In build 2.2.2.17, DAZ Studio was given the ability to pass an array of arguments into a DzScript object. The type of arguments that can be passed in via the array are limited to basic types; String, Number, Boolean, Array, etc. Below you will find sample code for two scripts… One for a script that does the calling and one for the script being called.
Calling Script
// The path to the script being called; ./scripts/support/MyName/MyScript.ds const sSUPPORT_PATH = String( '%1/support/MyName/MyScript.ds' ).arg( App.getScriptsPath() ); // Create a file object var oFile = new DzFileInfo( sSUPPORT_PATH ); // Get whether the file exists var bFound = oFile.exists(); // If the file doesn't exist if( !bFound ){ // Try appending a 'b'; this allows for .ds or .dsb oFile = new DzFileInfo( String( '%1b' ).arg( sSUPPORT_PATH ) ); // Get whether the file exists bFound = oFile.exists(); } // If the file is found and the version number is 2.2.2.17 or newer if( bFound && App.version >= 33686033 ){ // Create a script object const oSCRIPT = new DzScript(); // If the script loads if( oSCRIPT.loadFromFile( oFile.absFileName() ) ){ // Execute the script; pass in an array of arguments oSCRIPT.execute( new Array( App.version, sSUPPORT_PATH, bFound ) ); } }
Called Script
// Get the arguments passed in to the script const aARGS = getArguments(); // Display a message box with the arguments MessageBox.information( String( '%1' ).arg( aARGS.join( '\n' ) ), 'Arguments', '&OK' );
You are here: start » Wiki » User Pages » Rob Whisenant » TechNotes » DAZ Script Related » Executing a script from another script; passing in arguments.
