User Tools

Site Tools


Figure Metrics - No Dialog

Summary

Below is an example demonstrating how you can remotely execute the Figure Metrics script, included as part of the Measure Metrics product, by passing in a settings object to control the operation of the script without displaying its dialog.

API Areas of Interest

Example

Figure_Metrics_No_Dialog.dsa
// DAZ Studio version 4.6.2.118 filetype DAZ Script
// Define an anonymous function;
// serves as our main loop,
// 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 to run the Figure Metrics script silently
	function runSilent( oSettings ){
		// If the version number is older than 4.6.2.118
		if( App.version < 0x04060276 ){
			// Inform the user
			MessageBox.information(
				text( "This script requires %1 4.6.2.118 or newer. Update and try again." )
					.arg( App.appName ), text( "Version Error" ), text( "&OK" ) );
 
			// We can't pass in arguments to a script; we are done...
			return;
		}
 
		// Define the relative path to the Figure Metrics script
		var sRelPath = "/Scripts/Utilities/Figure Metrics.dse";
 
		// Get the content manager
		var oContentMgr = App.getContentMgr();
		// Attempt to find the script, in native directories
		var sFullPath = oContentMgr.findFile( sRelPath, DzContentMgr.NativeDirs );
 
		// If we can't find the script
		if( sFullPath.isEmpty() ){
			// Inform the user
			MessageBox.information(
				text( "Unable to locate the '%1' script.  Check mapped native content directories and try again." ).arg( sRelPath ),
				text( "Resource Error" ), text( "&OK" ) );
 
			// We are done...
			return;
		}
 
		// Create a script object
		var oScript = new DzScript();
 
		// If the script doesn't load
		if( !oScript.loadFromFile( sFullPath ) ){
			// Inform the user
			MessageBox.information(
				text( "An error occured while loading the '%1' script." ).arg( sFullPath ),
				text( "Read Error" ), text( "&OK" ) );
 
			// We are done...
			return;
		}
 
		// Execute the script; pass in an array of the argument
		oScript.execute([ oSettings ]);
	}
 
	/*********************************************************************/
	// Run the Figure Metrics script silently
	runSilent(
		{
		"configuration": "Genesis2Female",
		"measurements": "5 ft 8 in, 36-24-36",
		//"tolerance": 0.0001,
		//"maxIterations": 200,
		//"save": "Characters/Figure Metrics/G2F Hourglass"
		}
	);
 
// Finalize the function and invoke
})();

Details

The Figure Metrics script takes exactly 1 argument; an Object with no less than two (2), and up to five (5), named members that are used to control its operation. The configurable settings handled by the Figure Metrics script are as follows:

  • configuration - A required String that specifies the name of the Configuration Preset to be used for establishing the relationships between the Measure Metric nodes associated with the target figure and the properties of that figure that are used to affect the individual measurements
    • Configuration Presets are defined and stored on a per base-figure basis, within a sub directory named after the target figure, for example:
      var sPresetPath = String("%1/resources/Figure Metrics/Presets/Configurations/%2")
      	.arg( App.getAppDataPath() ).arg( oSkeleton.name );
    • Configuration Presets are JSON based and are structured such that they follow the example:
      {
      	"Genesis2Female": {
      		"Height": {
      			"Node": "Genesis2Female",
      			"Property": "Scale"
      		},
      		"BustChestCircumference": {
      			"Node": "Genesis2Female",
      			"Property": "CTRLBustCircumference"
      		},
      		"WaistCircumference": {
      			"Node": "Genesis2Female",
      			"Property": "PBMWaistCircumference"
      		},
      		"LowHipCircumference": {
      			"Node": "Genesis2Female",
      			"Property": "PBMLowHipCircumference"
      		}
      	}
      }
  • measurements - A required String that specifies the name of the Measurement Preset to be used for indicating the measurements you would like to achieve
    • Measurement Presets are defined and stored on a per base-figure basis, within a sub directory named after the target figure, for example:
      var sPresetPath = String("%1/resources/Figure Metrics/Presets/Measurements/%2")
      	.arg( App.getAppDataPath() ).arg( oSkeleton.name );
    • Measurement Presets are JSON based and are structured such that they follow the example:
      {
      	"Genesis2Female": {
      		"Height": [
      			68,
      			"in"
      		],
      		"HeadCircumference": [
      			22.33,
      			"in"
      		],
      		"BustChestCircumference": [
      			36,
      			"in"
      		],
      		"WaistCircumference": [
      			24,
      			"in"
      		],
      		"LowHipCircumference": [
      			36,
      			"in"
      		]
      	}
      }
  • tolerance - An optional floating point Number in the [.1, .00001] range that can be used to control the allowable deviation from the target measurement
    • If not specified, the last value used in the dialog will be used
    • The default value is .01
  • maxIterations - An optional integer in the [1, 200] range that can be used to control the maximum number of attempts the script will make to achieve a particular measurement
    • If not specified, the last value used in the dialog will be used
    • The default value is 100
  • save - An optional String that specifies the relative path of a Character Preset to be saved at the end of the adjustment process
    • Any path defined should exclude the file extension
    • If defined, the file will be saved in the first mapped native content directory
    • The user will not be prompted if the specified file already exists; it will simply be overwritten