/********************************************************************** This script is provided as part of the Daz Script Documentation. The contents of this script, and\or any portion thereof, may only be used in accordance with the following license: Creative Commons Attribution 3.0 Unported (CC BY 3.0) - http://creativecommons.org/licenses/by/3.0 To contact Daz 3D or for more information about Daz Script visit the Daz 3D website: - http://www.daz3d.com **********************************************************************/ // Source: /public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/remote_operation/sub_script/start // Define an anonymous function; // serves as our main loop, // limits the scope of variables (function(){ /*********************************************************************/ // void : A function that gets the path of the current script function getScriptPath() { // Get the filename of the running script var sFileName = getScriptFileName(); // Create a file info object var oFileInfo = new DzFileInfo( sFileName ); // Declare a working variable var sPath; // If the version of the application provides the method if( typeof( oFileInfo.canonicalPath ) == "function" ){ // Get the canonical path from the file sPath = oFileInfo.canonicalPath(); //requires 4.9.3.29 or newer // If the method we prefer is not available } else { // Use the fallback to get the (absolute) path sPath = oFileInfo.path(); } // Clean up; do not leak memory oFileInfo.deleteLater(); // Return the path return sPath; }; /*********************************************************************/ // String : A function for retrieving a translation if one exists function text( sText ) { // If the version of the application supports qsTr() if( typeof( qsTr ) != "undefined" ){ // Return the translated (if any) text return qsTr( sText ); } // Return the original text return sText; }; /*********************************************************************/ // void : A function that executes a script and passes arguments to it function executeScriptWithArgs( sPath, aScriptArgs ) { // Declare working variables var sTitle, sMessage; // Define common strings var sButton = text( "&OK" ); // Create a script object var oScript = new DzScript(); // Create a file info object var oFileInfo = new DzFileInfo( sPath ); // Get the file extension var sExtension = oFileInfo.extension(); // If the path does not have a file extension, attempt to find the // script with a supported extension; doing it this way, we can debug // with an ascii file and distribute a binary (encrypted) file with // the same name... without having to update the contents of the script // or manually handle the file extensions; requires 3.0.1.5 or newer var sScriptPath = sExtension.isEmpty() ? oScript.getScriptFile( sPath ) : sPath; // Clean up; do not leak memory oFileInfo.deleteLater(); // If a script is found if( !sScriptPath.isEmpty() ){ // If the script loads if( oScript.loadFromFile( sScriptPath ) ){ // Execute the script; pass in an array of arguments; // passing in arguments requires 2.2.2.17 or newer oScript.execute( aScriptArgs ); // If the script doesn't load } else { // Define text variables for the message sTitle = text( "Read Error" ); sMessage = text( "The '%1' file could not be loaded." ).arg( sScriptPath ); // Inform the user MessageBox.information( sMessage, sTitle, sButton ); } // If a script is not found } else { // Define text variables for the message sTitle = text( "File Not Found" ); sMessage = text( "A '%1.ds(a|b|e)' file could not be found." ).arg( sPath ); // Inform the user MessageBox.information( sMessage, sTitle, sButton ); } }; /*********************************************************************/ // Define the path of the script we will call; without the file extension var sScriptPath = String( "%1/Callee_Script" ).arg( getScriptPath() ); // Execute the symmetrize script, silently executeScriptWithArgs( sScriptPath, [ App.version, sScriptPath, true ] ); // Finalize the function and invoke })();