Scripting Help [SOLVED]
Not sure if this is the right forum for this, but...
I often select a body part of a figure, then select all children, then lock the pose for selected items. Then apply a pose, then unlock the selected items again.
I'd love to be able to just select a part, like a forearm or shoulder, and run a script to selected all children and lock selected items pose. And a second script to unlock when needed.
I copied MjCasual's script for mjcSelectAllMyChildren that he posted a few years back in the freebies forum. But don't know anything about DAZ scripting. I can follow what's being done, but don't know the functions and objects that are available to access.
Here is that code:
var roots = Scene.getSelectedNodeList();var n = roots.length;for( var i = 0; i < n; i++ ){ selectChildren( roots[ i ] )} function selectChildren( root ){ var children = root.getNodeChildren( true ); //recurse var n = children.length; for( var i = 0; i < n; i++ ) { var node = children[ i ]; node.select( true ); }}
Can anyone point me in the right direction?
Thanks!
Comments
After some rather unpleasant digginfg around in the documentation I think, emphasis on think because this seems so very wrong:
that after
node.select( true );
add:
var lock node.getDisableTransformControl();
then:
lock = 1;
to lock
or
lock = 0;
to unlock
But I'm not 100% sure. The documentation on this is a mess. There should be a DzNode::setDisableTransformControl() but it doesn't seem to exist.
For future reference, there's a scripting section in DS Discussion
https://www.daz3d.com/forums/categories/daz-script-developer-discussion
getDisableTransformControl() is getting the control, not its value, which is why there is no set equivalent - you can't replace an existing property in that way. Rather than lock = true/false you need lock.setBoolValue( true/false ), as otherwise you are replacing the (pointer to) the control with a Boolean value.
Thanks. I knew somethings wasn't right about that. It just didn't feel right but I didn't have time tyo test it myself after all the time it took to hunt down the documentation.
So, does that mean after node.select, adding lock.setBoolValue( true/false ) will lock or unlock the selected node, or does something else need to happen? I'm going to run some tests here shortly.
That didn't work. Lock needs to be attached to something. node.lock... Also didn't work.
And you're right, Kenshaw, the documentation is a mess. The only reference to "lock" that I can find is in the actions section. Just don't know how to get that to work here.
Ok I got it! Thanks to the comments here, I was able to chase down a sample to execute an action. And using the DzLockNodeAction, and dzUnlockNodeAction, I got where I needed to be.
I'm not posting the code here, since I don't know what the attribution would be.
But I used a postion of the example listed here: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/actions/action_trigger/start
Thank you for your sacrifice!
Are you aware that your script is potentially selecting the same nodes more than once, and isn't affecting the actual selected nodes but only their children? That may be your intent, but I wasn't sure. Anyway, I'm not sure what getDisableTransformControl() is meant to be doing - I agree it doesn't seem to simply lock the transforms - but this will do the job without having to access actions:
Well, the iteration through the children is part of MCasual's script, I didn't change any of that.
When I tested, it seemed to lock the selected node along with the children. But I'll have to look again. The locking doesn't occur until everything is selected, so I'm pretty sure the selected node is locked/unlocked as well.
I just re-tested, and it does lock the selected item along with all the children.
Is the item parented to somethign else? Is it a figure or a prop? I was testing with a couple of parented props and for me it certainly didn't lock the selected item, just the child. Ah, right - it works with triggering the action because the selected nodes are, by definiton, selected - mine doesn't as it's acting only on the nodes found by the script.
I'm working with figures, G8 mostly. I may not want the arms to be included in a pose, so I'll select a shoulder, and click the lock script.
This seems to derive from one of Rob's sample scripts - please make sure you follow the license, as explained on the source page.
It is for personal use only.
Regardless, if you post it publicly rather than using it in private then you need to obey the license - which is hardly onerous.
Not even sure if I can find it again, but I'll look and see what the requirements are.
I found the example I used, but I don't see anyone's name attached to it. I see the CC 3.0 license, and looked in there. But still don't know what attribution would be used. So I removed it from my comment above. So you'll need to remove it from your quoted comment, and there shouldn't be any issues, right?
The requirement isn't that you name the author, as explained on the page linked from the license text:
so you should say which script(s) you used, and link to them, with a simple note on the changes you made.