Problem about save pose parameters and set the parameter to another character

Hi,

I'm trying to use Daz script saving pose parameters (Position,rotation,scale), set the saved pose parameters to another character.

Here is the script I used to save all 233 labeled bone's parameter into 233 json files.

for example:

function save_pose(){

var aNodeList = Scene.getNodeList();

print(aNodeList.length);

for (i=1; i <aNodeList.length; i++){

var node = aNodeList[i];

var label= node.getLabel();

json_path = String("%1%2.json").arg("C:/Users/momo/Desktop/json/bone").arg(i);

var file = new DzFile(json_path);

file.open( DzFile.WriteOnly );

var oldNodeWSPos = node.getWSPos();

var oldNodeWSRot = node.getWSRot();

var oData = {};

var oSettings = new DzSettings();

if( oSettings.fromString( JSON.stringify( oData ) ) ){

oSettings.setFloatValue("Posx", oldNodeWSPos.x);

oSettings.setFloatValue("Posy", oldNodeWSPos.y);

oSettings.setFloatValue("Posz", oldNodeWSPos.z);

oSettings.setFloatValue("Rotx", oldNodeWSRot.x);

oSettings.setFloatValue("Roty", oldNodeWSRot.y);

oSettings.setFloatValue("Rotz", oldNodeWSRot.z);

};

var sTemplateData = oSettings.toJsonString();

var nResult = file.write( sTemplateData );

print(sTemplateData);

node.select( false );

file.close();

}}

 

Then get the parameters from json , set the parameters to another character.

The script should works well, but look at the result actually didn't set well.

code:

function set_pose(){

var aNodeList = Scene.getNodeList()

print(aNodeList.length)

for (i=1; i <aNodeList.length; i++){

var oNode = aNodeList[i];

var label= oNode.getLabel();

print(label);

json_path = String("%1%2.json").arg("C:/Users/momo/Desktop/json/bone").arg(i);

var oFile = new DzFile(json_path);

if (oFile.open (DzFile.ReadOnly)) {

var oData;

oData = JSON.parse (oFile.read());

Scene.getPrimarySelection().findNodeChildByLabel(label, true).getXRotControl().setValue(oData["Rotx"]);

Scene.getPrimarySelection().findNodeChildByLabel(label, true).getYRotControl().setValue(oData["Roty"]);

Scene.getPrimarySelection().findNodeChildByLabel(label, true).getZRotControl().setValue(oData["Rotz"]);

}} }

 

when I just change one bone, for example:

Scene.getPrimarySelection().findNodeChildByLabel("Left Collar", true).getXRotControl().setValue(50);

this could works well!

Can anyone help? Thanks!

Comments

  • Why are you suing a dzSettinsg object at all? Why are you wanting these files at all, given that a pose preset can already do the job? You might try breaking soem of those steps down into severl lines, to make troubleshooting easier. Also, although I doubt it's an actual issue, you might pull the var statements for node and label outside the loop.

  • The problem is that you are storing the node values using getWSRot and getWSPos which are world positions, and then you are loading those values into  node.getXRotControl(), those are two different things. Use this instead when saving your values to the file:

    oSettings.setFloatValue("Rotx", node.getXRotControl().getValue());
    oSettings.setFloatValue("Roty", node.getYRotControl().getValue());
    oSettings.setFloatValue("Rotz", node.getZRotControl().getValue());

    ... same for PosXYZ

  • Richard Haseltine said:

    Why are you suing a dzSettinsg object at all? Why are you wanting these files at all, given that a pose preset can already do the job? You might try breaking soem of those steps down into severl lines, to make troubleshooting easier. Also, although I doubt it's an actual issue, you might pull the var statements for node and label outside the loop.

    I want to use the script to get the pose parameter so that I could add little random noise to get lots of similar but new poses automatically!

  • vholf said:

    The problem is that you are storing the node values using getWSRot and getWSPos which are world positions, and then you are loading those values into  node.getXRotControl(), those are two different things. Use this instead when saving your values to the file:

    oSettings.setFloatValue("Rotx", node.getXRotControl().getValue());
    oSettings.setFloatValue("Roty", node.getYRotControl().getValue());
    oSettings.setFloatValue("Rotz", node.getZRotControl().getValue());

    ... same for PosXYZ

    Thank you for the code! I tried it but still got a different pose... Is this worked well in your Daz?

Sign In or Register to comment.