User Tools

Site Tools


Bake To Transforms - No Dialog

Summary

Below is an example demonstrating how you can remotely execute the Bake To Transforms script, silently, by passing in a settings object to control the operation of the script without displaying its dialog.

API Areas of Interest

Example

Silent_BakeToTransforms.dsa
// DAZ Studio version 4.15.0.17 filetype DAZ Script
 
// Define an anonymous function;
// limits the scope of variables
(function(){
 
	/*********************************************************************/
	// 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/bakeToTransforms" ).arg( App.getScriptsPath() );
 
	// Execute the bakeToTransforms script, silently
	executeScriptWithArgs( sScriptPath, [{
				"nodes": text( "Root" ),
				"propagation": text( "Recursive" ),
				"property_path": "Pose Controls",
				"property_type": "Modifier/Pose",
				"transforms": {
					"rotation": {
						"x": true,
						"y": true,
						"z": true
					},
					"translation": {
						"x": false,
						"y": false,
						"z": false
					},
					"scale": {
						"general": false,
						"x": false,
						"y": false,
						"z": false
					}
				},
				"visible_subs_only": false
			}]
		);
 
// Finalize the function and invoke
})();

Details

The Bake To Transforms script takes exactly 1 argument; an Object with six (6) required named members, and one (1) optional named member, that are used to control its operation. Failure to specify all required members will result in a usage message being displayed when executed.

Configurable settings handled by the Bake To Transforms script:

  • nodes - A required String that matches the text displayed for the “Nodes” option in the dialog
  • propagation - A required String that matches the text displayed for the “Propagation” option in the dialog
  • property_path - A required String that matches the text displayed for the “Property Path” option in the dialog
    • An empty String (i.e., “”) is equivalent to unchecking the “Property Path” option in the dialog
  • property_type - A required String that matches the text displayed for the “Property Type” option in the dialog
    • An empty String (i.e., “”) is equivalent to unchecking the “Property Type” option in the dialog
  • transforms - A required Object with three (3) members
    • rotation - A required Object with three (3) members
      • x - A required Boolean that indicates the checked state of the “X Axis” option in the dialog
      • y - A required Boolean that indicates the checked state of the “Y Axis” option in the dialog
      • z - A required Boolean that indicates the checked state of the “Z Axis” option in the dialog
    • translation - A required Object with three (3) members
      • x - A required Boolean that indicates the checked state of the “X Axis” option in the dialog
      • y - A required Boolean that indicates the checked state of the “Y Axis” option in the dialog
      • z - A required Boolean that indicates the checked state of the “Z Axis” option in the dialog
    • scale - A required Object with three (3) members
      • general - A Boolean that indicates the checked state of the “General” option in the dialog
      • x - A required Boolean that indicates the checked state of the “X Axis” option in the dialog
      • y - A required Boolean that indicates the checked state of the “Y Axis” option in the dialog
      • z - A required Boolean that indicates the checked state of the “Z Axis” option in the dialog
  • visible_subs_only - A required Boolean that indicates the checked state of the “Visible Sub-Components Only” option in the dialog
  • preferred - An optional Boolean that indicates whether or not stored “Preferred” options are read
    • If true, preferred values will override any corresponding values set in the other members