DAZ Script "Set Default Property Groups" sample

Todo:
Port from DAZ Script 1 to DAZ Script 2
Description :

This script is a very simple example, showing how to assign properties of a selected node to various logical groups that are displayed in the Parameters tab.

 
Concepts Covered :
  • Declaration/Definition of Constants (with a local scope)
  • Initializing a String variable using a String Literal
  • Initializing an Array variable using an Array Literal
  • Declaring/Defining a Custom Function
  • Using Control Statements to direct the flow of a DAZ Script
  • Using Operators to assign/validate the value of a variable
  • Assigning a Node's Properties to Property Groups
  • Informing the user of status via the cursor
  • Using Global variables and methods
 
Source : ./samples/
00001 /**********************************************************************
00002     File: setDefaultPropertyGroups.ds
00003 
00004     Copyright © 2002-2006 DAZ Productions. All Rights Reserved.
00005 
00006     This file is part of the DAZ Script Documentation.
00007 
00008     This file may be used only in accordance with the DAZ Script 
00009     license provided with the DAZ Script Documentation.
00010 
00011     The contents of this file may not be disclosed to third parties, 
00012     copied or duplicated in any form, in whole or in part, without the 
00013     prior written permission of DAZ Productions, except as explicitly
00014     allowed in the DAZ Script license.
00015 
00016     See http://www.daz3d.com to contact DAZ Productions or for more 
00017     information about DAZ Script.
00018 **********************************************************************/
00019 /*********************************************************************/
00020 // void : The main function of this script
00021 function setDefaultPropertyGroups(){
00022     // Rotation
00023     const sROTATION_GRP = "/General/Transforms/Rotation";
00024     const aROTATION_PROPS = [ "XRotate", "YRotate", "ZRotate" ];
00025     // Translation
00026     const sTRANSLATION_GRP = "/General/Transforms/Translation";
00027     const aTRANSLATION_PROPS = [ "XTranslate", "YTranslate", "ZTranslate" ];
00028     // Scale
00029     const sSCALE_GRP = "/General/Transforms/Scale";
00030     const aSCALE_PROPS = [ "Scale", "XScale", "YScale", "ZScale" ];
00031     // Misc
00032     const sMISC_GRP = "/General/Misc";
00033     // Light
00034     const sLIGHT_GRP = "/Light";
00035     const aLIGHT_PROPS = [ "Illumination", "Color", "Intensity", "Spread Angle" ];
00036     // Camera
00037     const sCAMERA_GRP = "/Camera";
00038     const aCAMERA_PROPS = [ "Perspective", "Focal Length", "DOF", "Depth of Field", "Aperature" ];
00039     // Shadow
00040     const sSHADOW_GRP = "/Shadow";
00041     const aSHADOW_PROPS = [ "Cast Shadows", "Shadow Type", "Shadow Softness", "Shadow Bias" ];
00042     
00043     // Declare local variables
00044     var i, j, numI, numJ;
00045     var oNode, oProp;
00046     
00047     // Get the number of selected nodes
00048     numI = Scene.getNumSelectedNodes();
00049     // Iterate over each selected node
00050     for( i = 0; i < numI; i++ ){
00051         // Get the selected node
00052         oNode = Scene.getSelectedNode( i );
00053         // Get the number of properties
00054         numJ = oNode.getNumProperties();
00055         // Iterate over each property
00056         for( j = 0; j < numJ; j++ ){
00057             // Get the current property
00058             oProp = oNode.getProperty( j );
00059             // Check if the property belongs in the rotation group
00060             if( aROTATION_PROPS.find( oProp.name ) != -1 ){
00061                 // Set the group for the property
00062                 oProp.setPath( sROTATION_GRP );
00063                 // NEXT!!!
00064                 continue;
00065             }
00066             // or if the property belongs in the translation group
00067             else if( aTRANSLATION_PROPS.find( oProp.name ) != -1 ){
00068                 // Set the group for the property
00069                 oProp.setPath( sTRANSLATION_GRP );
00070                 // NEXT!!!
00071                 continue;
00072             }
00073             // or if the property belongs in the scale group
00074             else if( aSCALE_PROPS.find( oProp.name ) != -1 ){
00075                 // Set the group for the property
00076                 oProp.setPath( sSCALE_GRP );
00077                 // NEXT!!!
00078                 continue;
00079             }
00080             // or if the property belongs in the light group
00081             else if( aLIGHT_PROPS.find( oProp.name ) != -1 ){
00082                 // Set the group for the property
00083                 oProp.setPath( sLIGHT_GRP );
00084                 // NEXT!!!
00085                 continue;
00086             }
00087             // or if the property belongs in the camera group
00088             else if( aCAMERA_PROPS.find( oProp.name ) != -1 ){
00089                 // Set the group for the property
00090                 oProp.setPath( sCAMERA_GRP );
00091                 // NEXT!!!
00092                 continue;
00093             }
00094             // or if the property belongs in the shadow group
00095             else if( aSHADOW_PROPS.find( oProp.name ) != -1 ){
00096                 // Set the group for the property
00097                 oProp.setPath( sSHADOW_GRP );
00098                 // NEXT!!!
00099                 continue;
00100             }
00101             // or... the property belongs in a default miscellaneous group
00102             else
00103                 // Set the group for the property
00104                 oProp.setPath( sMISC_GRP );
00105         }
00106     }
00107 }
00108 
00109 /*********************************************************************/
00110 // Set the busy cursor to let the user know we're working
00111 setBusyCursor();
00112 // Do... that thing that we do
00113 setDefaultPropertyGroups();
00114 // We're done working, let the user know
00115 clearBusyCursor();

Generated on Thu Sep 24 12:21:07 2009

Copyright © 2002 - 2009 DAZ 3D, Inc.