accessing dForce surface values by script [solved]

meipemeipe Posts: 101

When you add a dForce modfier to a character, several simulation parameters are added to it and can be edited in the surfaces tab.

Is there a way to access them by script? If I iterate the property list of the material's shape I can find everything, except them...

Post edited by meipe on

Comments

  • PraxisPraxis Posts: 240
    edited March 2022

     

    meipe said:

    When you add a dForce modfier to a character, several simulation parameters are added to it and can be edited in the surfaces tab.

    Is there a way to access them by script? If I iterate the property list of the material's shape I can find everything, except them...

    Short answer is: You need to access the DzDForceModifier.

    Hope the following helps...

    (Also attached as DzDForceModifier.txt in case the forum does not format the code correctly).

    // May be useful to iterate the property lists of these classes:var Item = Scene.getPrimarySelection().getObject().getModifier(4042);             //  DzDForceModifiervar Item = Scene.getPrimarySelection().getWeightMapHandler().getWeightGroup(0);   //  DzDForceModifierWeightGroupvar Item = Scene.getPrimarySelection().getWeightMapHandler();                     //  DzDForceModifierWeightHandlervar Item = Scene.getPrimarySelection().getObject().getCurrentShape()             .findSimulationSettingsProvider( Scene.getPrimarySelection()             .getObject().getCurrentShape().getSimulationProviderNames()[0] );    //  DzDForceSettingsProvidervar Item = App.getSimulationMgr().getSimulationEngine( 0 );                       //  DzDForceEnginevar Item = App.getSimulationMgr().getSimulationElementObjects()[0];    

     

    //------------------------------------------------------// Sample code to access DzDForceModifier//------------------------------------------------------//  Functions prefixed with g_prxUTY_lib. are utilities in an external library (not supplied).// Build an Array of data about each dForce Node://  Each Item is an Object://    { Node            : // DzNode//    , Modifier        : // DzDForceModifier//    , Material        : // DzMaterial//    , SimSetProvider  : // DzDForceSettingsProvider//    }var P_DForceNodesArr    = new Array();function ProcessNode( P_Node, P_Level ) {       // void  // RECURSIVE function to process 1 Node and its Children  //---Process this Node---  if( P_Node.inherits( 'DzBone' ) && !P_Node.inherits( 'DzSkeleton' ) ) {    // Any Modifiers. belong to the DzBone's parent DzSkeleton,    //  so we ignore P_Node here.    //  (But we still process P_Node's Child Nodes, in case e.g. a Ring prop is parented to a Finger DzBone).  } else {    // Not a DzBone, or is a DzSkeleton    //---Process data about this Node---    if( P_Node.isVisible() || (!P_ProcessOnlyVisibleNodes) ) {      // Process this Node      // Check whether it has a dForce Modifier:      var Obj       = P_Node.getObject();      if( Obj ) {        // Check each Modifier for this DzObject:        var ListItem, SimObjType, PropInfo, WorkStr;        var NodeDone  = false;        var ModCount  = Obj.getNumModifiers();        var ModNum    = 0;        while( (ModNum < ModCount) && (!NodeDone) ) {          Modifier      = Obj.getModifier( ModNum );          ModClassName  = Modifier.className();          // Most Modifiers on a Figure are Morphs - which we ignore here.          if( ModClassName == 'DzDForceModifier' ) {            // $$$            //  print( P_Level, P_Node.getLabel() );            // May be useful:            //  Modifier.getInfluenceWeights()            //  Modifier.getStretchStiffnessWeights()            //  Modifier.getShearStiffnessWeights()            //  Modifier.getBendStiffnessWeights()            //  Modifier.getBucklingStiffnessWeights()            //  Modifier.getBucklingRatioWeights()            //  Modifier.getMassDensityWeights()            //  Modifier.getVelocitySmoothingWeights()            //  Modifier.getSurfaceSmoothingWeights()            //---Process each relevant Material/SimulationSettingsProvider for this DzObject---            var MatNum;            var MatData;            var MatDataArr  = new Array();            var Data;            var Mat = undefined;            var SimSetProvider  = undefined;            var Shp = Obj.getCurrentShape();            if( Shp ) {              // Modified from:              //    _Scripting_API_v4\Samples\_Properties\Material_Properties\v2\Material_Properties.dsa              // Each Object.getCurrentShape() can have more than 1 Material (e.g. for different Surface FaceGroups),              //  so it can have more than 1 SimulationSettingsProvider, and therefore more than 1 set of Simulation Settings, e.g.:              //    G8F_LBreast_Skin+Shell              //      DzUberIrayMaterial Skin Skin              //      DzUberIrayMaterial Shell Shell              //      DzUberIrayMaterial Nipple+Areola Nipple+Areola              //              //  print( ' ' );              //  print( P_Node.getLabel() );              for( MatNum = 0; MatNum < Shp.getNumMaterials(); MatNum++ ) {                Mat = Shp.getMaterial( MatNum );                SimSetProvider  = undefined;                if( g_prxUTY_lib.DAZVersionIsThisOrNewer( 4, 9, 3, 135 ) ) {                  SimSetProvider  = Shp.findSimulationSettingsProvider( Mat.name );   // DzDForceSettingsProvider                  //  print( '  ', Mat.className(),Mat.getName(), Mat.getLabel(), SimSetProvider );                }                if( SimSetProvider ) {                  // This Material has dForce Settings                  MatData = new Object();                  MatData.Mat            = Mat;                  MatData.SimSetProvider = SimSetProvider;                  MatDataArr.push( MatData );                }              } // For each Material for this Shape            } // Got Shp            // Save the data into P_DForceNodesArr[]:            for( MatNum = 0; MatNum < MatDataArr.length; MatNum++ ) {              MatData = MatDataArr[ MatNum ];              Mat            = MatData.Mat;              SimSetProvider = MatData.SimSetProvider;              //---Save the data associated with this Node---              Data          = new Object();              Data.Node     = P_Node;                 // DzNode                     // Always non-null              Data.Modifier = Modifier;               // DzDForceModifier           // Always non-null              Data.Material       = Mat;              // DzMaterial                 // Always non-null              Data.SimSetProvider = SimSetProvider;   // DzDForceSettingsProvider   // Always non-null              P_DForceNodesArr.push( Data );            } // For each Material            // >>> This assumes that a Node only ever has 1 DzDForceModifier:            NodeDone  = true;     // Exit this loop          } // DzDForceModifier          ModNum++;        } // For Each Modifier      } // Got Obj    } // Process this Node  } // Not a DzBone, or is a DzSkeleton  //---Process this Node's Child Nodes---  var ChildNodesArr   = P_Node.getNodeChildren( false );    // false: Don't recurse: Just return the immediate Child Nodes  var J;  for( J = 0; J < ChildNodesArr.length; J++ ) {    ProcessNode( ChildNodesArr[ J ], P_Level + 1 );         // <---RECURSIVE call  }};  // ProcessNode()//------------------------------------------------------

     

    txt
    txt
    DzDForceModifier.txt
    7K
    Post edited by Praxis on
  • meipemeipe Posts: 101
    edited March 2022

    Thank you! Richard's sample script is easy to use.

    Just set, for example at line 236

    var sPropertyName = "Contraction-Expansion Ratio";

     

    and add a line of code at the end of the script to edit the property value:

     

    oProperty.setValue(0.66);

     

    I wasn't able to use praxis's approach, but I suppose t may work.

    Post edited by meipe on
  • Not my script, but I'm glad it worked.

Sign In or Register to comment.