Can't modify Thigh Bend values in animation via a script

doorknob22doorknob22 Posts: 62

Limbstick is a great tool (compared to what Daz has out of the box), but it's buggy as hell. If you tell it to stick a dancing girl's foot to the floor, it (sometimes) doesn't care if the girl's thigh position is completely different between the first and last frame. Its goal was to keep the foot on the bed, and it did that. Great success! Only this creates an ugly glitch between the first frame and the last, because the foot is technically where it's supposed to be, but the whole leg is positioned completely differently.

I have this excel where I input a joint's 0 value, current value of about 10 frame before the last and the formula gives me a series of numbers which change the joints more or less smoothly in the last 10 frames so they match frame 0. I'm patient enough to do it manually but even I have my limits, so today I asked ChatGPT for a solution.

The golem enthusiastically got to work and quickly generated a script and instructed me how to run in on Daz's Script IDE. Happy, I thought that for once my premium ChatGPT subscription paid for itself, but of course the script didn't compile. To make a long story short, three hours later, ChatGPT's incompetence can only be matched by its never-ending optimism that this time the script will work.

So, three hours down the drain and almost nothing to show for it.

What I'm trying to do is populate a set of values in a character's Right Thigh Bend - Bend parameter, on frames 98 - 108. This script passes compilation (no thanks to ChatGPT) but other than that, does nothing at all. Any help would be appreciated and perhaps even be useful for others.

 

// DAZ Studio Script to modify "Right Thigh Bend - Bend" over a frame range// Get the selected figure (ensure the character is selected)var character = Scene.getPrimarySelection();if (!character) {    print("No character selected!");} else {    // Find the Right Thigh Bend - Bend parameter using its internal name    var oNode = character.findNodeChild( "rThighBend", true );        if (!oNode)            print("oNode!");    var oZRotCtrl = oNode.findPropertyByLabel( "Bend" );        if (!oZRotCtrl) {            print("oZRotCtrl!");    } else {        print(oZRotCtrl);        // Define the range of frames and values        var startFrame = 98;        var endFrame = 108;        var values = [-90.27011917,-90.14333833,-90.0165575,-89.88977667,-89.76299583,-89.636215,-89.50943417,-89.38265333,-89.2558725,-89.12909167,-89.00231083]; // Adjust values as needed        // Ensure the values array matches the frame range        if (values.length !== (endFrame - startFrame + 1)) {            print("Error: Values array size does not match frame range.");        } else {            // Apply the values over the frame range            for (var i = 0; i <= endFrame - startFrame; i++) {                var frame = startFrame + i;                var value = values[i];                                 Scene.setFrame(frame);  // Move to the specified frame                               oZRotCtrl.setValue(value);  // Set the value                               //oZRotCtrl.setKeyframe();    // Create a keyframe                //createKeyFrame.trigger();            }            print("Successfully applied values to Right Thigh Bend - Bend from frame " + startFrame + " to " + endFrame);        }    }}
Screenshot 2025-03-04 193623.jpg
1025 x 787 - 125K
Post edited by doorknob22 on

Comments

  • Richard HaseltineRichard Haseltine Posts: 102,931

    You may want to look at http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/floatproperty_dz#a_1a3d21e4b12e2694ef4c1db889f5084c7c

    Though for this I would tend to think it better to apply the desired start/end pose first, then fill in the in-between frames by posing.

  • doorknob22doorknob22 Posts: 62

    Richard Haseltine said:

    You may want to look at http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/floatproperty_dz#a_1a3d21e4b12e2694ef4c1db889f5084c7c

    Though for this I would tend to think it better to apply the desired start/end pose first, then fill in the in-between frames by posing.

     

    Thanks! This works and I managed to populate the values but... they seem a bit off. For example frame 108 is -87.96091 instead of -89.00231083, frame 107 is -88.08769 instead of -89.12909167 etc. It seems like the values in setValue are modified somehow?

    // DAZ Studio version 4.23.0.1 filetype DAZ Script

    // DAZ Studio Script to modify "Right Thigh Bend - Bend" over a frame range

    (function () {
        // Define the range of frames and values
        var startFrame = 98;
        var endFrame = 108;
        var values = [-90.27011917, -90.14333833, -90.0165575, -89.88977667, -89.76299583, -89.636215, -89.50943417, -89.38265333, -89.2558725, -89.12909167, -89.00231083]; // Adjust values as needed
        var sBoneName = "rThighBend";
        var sZRotCtrl = "Bend";

        // Ensure the values array matches the frame range
        if (values.length !== (endFrame - startFrame + 1)) {
            print("Error: Values array size does not match frame range.");
            return
        }

        // Get the selected figure (ensure the character is selected)
        var character = Scene.getPrimarySelection();
        if (!character) {
            print("No character selected!");
            return
        }

        // Find the Right Thigh Bend - Bend parameter using its internal name
        var oNode = character.findNodeChild(sBoneName, true);
        if (!oNode) {
            print("oNode!");
            return
        }

        var oZRotCtrl = oNode.findPropertyByLabel(sZRotCtrl);
        if (!oZRotCtrl) {
            print("oZRotCtrl!");
            return
        }

     

        // Apply the values over the frame range
        var nTimeStep = Scene.getTimeStep().valueOf();
        for (var i = 0; i <= endFrame - startFrame; i++) {
            var frame = startFrame + i;
            var value = values[i];
            print("value = " + value);
            print("nTimeStep = " + nTimeStep);
            oZRotCtrl.setValue(frame * nTimeStep, value);  // Set the value               
            print(oZRotCtrl.getValue(frame * nTimeStep));
        }

        print("Successfully applied values to Right Thigh Bend - Bend from frame " + startFrame + " to " + endFrame);


    })();

    Screenshot 2025-03-04 230453.jpg
    1399 x 832 - 129K
  • Richard HaseltineRichard Haseltine Posts: 102,931

    you could use

    oNode.getZRotControl();

    instead of searching - the standard transforms for a node have their own dedicated gets, which I assume are marginally faster.

    Bits of the script look as if they came from the sample scripts - if you are using those at all make sure you comply with the CC 3.0 by attribution license, as explained on the sample pages, when posting them.

  • Richard HaseltineRichard Haseltine Posts: 102,931

    Richard Haseltine said:

    you could use

    oNode.getZRotControl();

    instead of searching - the standard transforms for a node have their own dedicated gets, which I assume are marginally faster.

    or not so marginally if there are a lot of properties to search through, I am told.

    Bits of the script look as if they came from the sample scripts - if you are using those at all make sure you comply with the CC 3.0 by attribution license, as explained on the sample pages, when posting them.

  • doorknob22doorknob22 Posts: 62

    Richard Haseltine said:

    Richard Haseltine said:

    you could use

    oNode.getZRotControl();

    instead of searching - the standard transforms for a node have their own dedicated gets, which I assume are marginally faster.

    or not so marginally if there are a lot of properties to search through, I am told.

    Bits of the script look as if they came from the sample scripts - if you are using those at all make sure you comply with the CC 3.0 by attribution license, as explained on the sample pages, when posting them.

     

    Thanks!

Sign In or Register to comment.