Scripting Help [SOLVED]

Steel RatSteel Rat Posts: 394

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!

Post edited by Steel Rat on

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.

     

     

  • SevrinSevrin Posts: 6,305

    For future reference, there's a scripting section in DS Discussion 

    https://www.daz3d.com/forums/categories/daz-script-developer-discussion

  • Richard HaseltineRichard Haseltine Posts: 99,429
    edited October 2020

    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.

    Post edited by Richard Haseltine on
  • 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.

  • Steel RatSteel Rat Posts: 394

    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.

    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.

  • Steel RatSteel Rat Posts: 394

    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.

  • Steel RatSteel Rat Posts: 394
    edited October 2020

    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

     

    Post edited by Steel Rat on
  • Steel RatSteel Rat Posts: 394

    After some rather unpleasant digginfg around in the documentation

    Thank you for your sacrifice! cheeky

  • 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:

    // do the locking - split off into its own function// to allow error checkingfunction doLock ( oProperty ) {	// quit if oProperty is invalid	if ( ! oProperty ) {		return;	}	// do the locking	oProperty.lock( true );}function lockTransforms ( node ) {	// Get the transform controls for the node and lock them		// declare helper variable	var curTransform;		// Translations	curTransform = node.getXPosControl();	doLock( curTransform );	curTransform = node.getYPosControl();	doLock( curTransform );	curTransform = node.getZPosControl();	doLock( curTransform );		// Rotations	curTransform = node.getXRotControl();	doLock( curTransform );	curTransform = node.getYRotControl();	doLock( curTransform );	curTransform = node.getZRotControl();	doLock( curTransform );		// Scale	curTransform = node.getScaleControl();	doLock( curTransform );	curTransform = node.getXScaleControl();	doLock( curTransform );	curTransform = node.getYScaleControl();	doLock( curTransform );	curTransform = node.getZScaleControl();	doLock( curTransform );}// Get the child nodes of root - note that as written// *only* the children will be locked, not root itselffunction selectChildren( root ){ 	var children = root.getNodeChildren( true ); //recurse 	var n = children.length;	for( var i = 0; i < n; i++ )	{		node = children[ i ];		lockTransforms ( node );	}}// Get list of selected nodes - n.b. there is no checking here to make sure// that a parent and one or more of its children are not selected, which may lead// to redunancy (and shoudl definitely not be used with toggling instead of// setting absoluter values)var roots = Scene.getSelectedNodeList();var n = roots.length;for( var i = 0; i < n; i++ ){	selectChildren( roots[ i ] )} 

     

  • Steel RatSteel Rat Posts: 394

    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.

  • Steel RatSteel Rat Posts: 394

    I just re-tested, and it does lock the selected item along with all the children.

  • Richard HaseltineRichard Haseltine Posts: 99,429
    edited October 2020
    Steel Rat said:

    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.

    Post edited by Richard Haseltine on
  • Steel RatSteel Rat Posts: 394

    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.

  • Richard HaseltineRichard Haseltine Posts: 99,429
    edited October 2020
    Steel Rat said:

    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

    This seems to derive from one of Rob's sample scripts - please make sure you follow the license, as explained on the source page.

    Post edited by Richard Haseltine on
  • Steel RatSteel Rat Posts: 394

    It is for personal use only.

  • Steel Rat said:

    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.

  • Steel RatSteel Rat Posts: 394

    Not even sure if I can find it again, but I'll look and see what the requirements are.

  • Steel RatSteel Rat Posts: 394

    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?

  • Steel Rat said:

    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:

     

        Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

        No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

    so you should say which script(s) you used, and link to them, with a simple note on the changes you made.

Sign In or Register to comment.