Setting a controlled dial's value

Hi,

Can someone explain what's wrong with the following code.  I'm trying
to set the value of the Z Rotation in the lMetatarsals bone in a G3F figure.
In the example below, I want to set it to 2.0 but it always ends up as 5.0.

Now I've realized that the lMetatarsals are controlled by the lToe bone,
so when the lToe twists, the lMetatarsals twists by the same amount.  But I
can manually adjust the Z Rotate dial of the lMetatarsals to any value I
want.  So does the method 'setValue()' do exactly the same as adjusting the
dial manually?  It doesn't look like it.  How can I set the rotation value to
the value I want, in a script?  Or do I have to somehow unlink the 2 bones?


(function(){
  var lToeValue, lMetaValue,
      lMetaBone, lToeBone,
      lMetaCtrl, lToeCtrl;
  
  var fig = Scene.getPrimarySelection().getSkeleton();
  
  lMetaBone = fig.findBone("lMetatarsals");
  lToeBone = fig.findBone("lToe");
    
  lMetaCtrl = lMetaBone.getZRotControl();
  lToeCtrl = lToeBone.getZRotControl();
  
  lMetaValue = lMetaCtrl.getValue();
  lToeValue = lToeCtrl.getValue();  
  
  print("Values Before:  " +
        "lMetatarsals = " + lMetaValue + ",  " +
        "lToe = " + lToeValue);  
  
  lToeCtrl.setValue(3.0);
  lMetaCtrl.setValue(2.0);
  
  lToeValue = lToeCtrl.getValue();
  lMetaValue = lMetaCtrl.getValue();
  
  print("Values After:  " +
        "lMetatarsals = " + lMetaValue + ",  " +
        "lToe = " + lToeValue);  
  
})();

// Output:

// Values Before:  lMetatarsals = 0,  lToe = 0
// Values After:  lMetatarsals = 5,  lToe = 3

 

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,888

    You need soem error trapping in there - the inital assigment of fig assumes that a bone iss elected which may not be the case. I would check that a node had been returned, then check to see if it inherited DzBone and replace it with its skeleton, then check that we had a node that inherited DzSkeleton.

    Note that you are dealing with a bone that can be controlled by Pose Controls, which may wel account for your issues - you can use the getRawValue() wich will be the local setting or adjustValue() to set the final value

    http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/floatproperty_dz

  • Stretch65Stretch65 Posts: 166

    I've tried adjustValue() instead of setValue().  The output I'm getting is:

    Values Before:  lMetatarsals = 0,  lToe = 0
    Values After:  lMetatarsals = 0,  lToe = 0

     

    Why won't it work?

  • Stretch65Stretch65 Posts: 166

    Sorry, disregard my last post.  I understand now how to use adjustValue().   The parameter to adjustValue() is the value I want the rotation parameter to be, and it returns another value which I can plug into setValue().

    So for example, if I want the Z rotation of the lMetatarsals bone to be 2.0:

    var n = lMetaCtrl.adjustValue(2.0);
    lMetaCtrl.setValue(n);   // Using n will set the rotation to 2.0
Sign In or Register to comment.