How to set up pose parameter by script?

Victor_BVictor_B Posts: 391

Hello.

Please, help me with these questions.

- How to set up Rotation parameter (Bend or Twist) of Left Forearm Bend of the selected figure?

- How to check selected figure is G8F?

Thank you.

Post edited by Victor_B on

Comments

  • This code of mine is how I do it. You'll need to select the node of the figure first before running this.

    Also, the nSomeValue variable is hard-coded to 0.0, so you'll need to provide a means of passing a value.

    Hope it helps.

    // Create an array of the three properties we're interested in.var aWantedProps = ["Bend", "Twist", "Side-Side"];var nSomeValue = 0.0; // You will need to figure out how to set the new values;// acquire the list of nodes in the scenevar aNodeList = Scene.getNodeList()for (i=0; i < aNodeList.length; i++){	var oNode = aNodeList[i];	// we're only interested in the selected node	if ( oNode.isSelected() )	{		print( oNode.getLabel() ); // for debug tracing		// aquire the list of properties belongint to this node		var aPropList = oNode.getPropertyList();		for (p=0; p < aPropList.length; p++)		{			var oProp = aPropList[p];			// aquire the label of this property			var sPropLabel = oProp.getLabel();			print( sPropLabel ); // for debug tracing							// Does this property belong to the list of props we want?			for (x=0; x< aWantedProps.length; x++)			{				if ( sPropLabel == aWantedProps[x] )				{					// The property's Class will give us the data type we need					var sClass = oProp.getWidgetClass();					print( sClass );											// we need the class for the PropertySettings object					if ( sClass == "DzStyledFloatPropertyWgt" )										{						oProp.setDoubleValue( nSomeValue );					}				} // if ( sPropLabel == aWantedProps[x] )			} // for (x=0; x< aWantedProps.length; x++)		}		}}

     

  • Victor_BVictor_B Posts: 391
    edited August 2019

    Thank you, Richard, for your answer, but I found decision already. In two words:

    Scene.getPrimarySelection().findNodeChildByLabel("Left Thigh Bend", true).getZRotControl().setValue(10);

    But the second question is still burning. I know this code:

    var oNode = Scene.getPrimarySelection();if (oNode) {if (oNode.getLabel() == "Genesis 8 Female") {...}}

    But I don't like it because user can change that label. Is there more reliable solution to check that selected figure is G8F?

    Thanks.

    Post edited by Victor_B on
  • Richard HaseltineRichard Haseltine Posts: 100,747
    edited August 2019

    This code of mine is how I do it. You'll need to select the node of the figure first before running this.

    Also, the nSomeValue variable is hard-coded to 0.0, so you'll need to provide a means of passing a value.

    Hope it helps.

    // Create an array of the three properties we're interested in.var aWantedProps = ["Bend", "Twist", "Side-Side"];var nSomeValue = 0.0; // You will need to figure out how to set the new values;// acquire the list of nodes in the scenevar aNodeList = Scene.getNodeList()for (i=0; i < aNodeList.length; i++){	var oNode = aNodeList[i];	// we're only interested in the selected node	if ( oNode.isSelected() )	{		print( oNode.getLabel() ); // for debug tracing		// aquire the list of properties belongint to this node		var aPropList = oNode.getPropertyList();		for (p=0; p < aPropList.length; p++)		{			var oProp = aPropList[p];			// aquire the label of this property			var sPropLabel = oProp.getLabel();			print( sPropLabel ); // for debug tracing							// Does this property belong to the list of props we want?			for (x=0; x< aWantedProps.length; x++)			{				if ( sPropLabel == aWantedProps[x] )				{					// The property's Class will give us the data type we need					var sClass = oProp.getWidgetClass();					print( sClass );											// we need the class for the PropertySettings object					if ( sClass == "DzStyledFloatPropertyWgt" )										{						oProp.setDoubleValue( nSomeValue );					}				} // if ( sPropLabel == aWantedProps[x] )			} // for (x=0; x< aWantedProps.length; x++)		}		}}

     

    Rob asks why you are using sClass = oProp.getWidgetClass() instead of getting the class of the property directly? He also points out that because you are not using a var in front of your loop variables (for i =  instead of for var i =, or just declare them before starting the outer loop) you are creating global variables, with the potential to conflict with other loops using the same names elsewhere in the script.

    Post edited by Richard Haseltine on
  • Victor_B said:

    Thank you, Richard, for your answer, but I found decision already. In two words:

    Scene.getPrimarySelection().findNodeChildByLabel("Left Thigh Bend", true).getZRotControl().setValue(10);

    But the second question is still burning. I know this code:

    var oNode = Scene.getPrimarySelection();if (oNode) {if (oNode.getLabel() == "Genesis 8 Female") {...}}

    But I don't like it because user can change that label. Is there more reliable solution to check that selected figure is G8F?

    Thanks.

    Rather than use the label, which as you say can vary, use the name (or the geometry name) - Rob also pointed that out.

  • Victor_BVictor_B Posts: 391
    edited August 2019

    Quick solution here (against global variables) is to incapsulate all this code:

    (function() {... put your code here...}());

    But the best solution is to rewrite this code with methods I mentioned in previous post.

    Post edited by Victor_B on
  • Victor_BVictor_B Posts: 391
    edited August 2019

    Rather than use the label, which as you say can vary, use the name (or the geometry name) - Rob also pointed that out.

    Ok, getName() works good. Thanks.

    Post edited by Victor_B on
  • Richard HaseltineRichard Haseltine Posts: 100,747
    edited August 2019

    Any variable that is used without being decalered through a var statement is treated as a global, as far as I am aware. Edit: yes, it is the case http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/language_reference/declarations/start#variables

    Post edited by Richard Haseltine on
Sign In or Register to comment.