Beginner asking for help: How to select a character in the scene

Hello, 
I have just started to learn javascript to create some little tools in daz and I have already played with some variables and functions, but I really struggle to find by myself how to select a character using his name in the script and have the possibility to toggle between several characters.  
My goal is to have the possibility to select and toggle between the characters with one hotKey.
I hope I'm clear enough even if I'm a new at scripting...

Thank you!

Comments

  • DzScene has methods to get nodes in general or of specific types, including skeletons (selected or otherwise). If you want to chnage the selection state you need

    node.select( true/false );

    to gt the current selection state

    var state = node.isSelected();

  • DorlanDorlan Posts: 4

    Thank You very much Richard, I will explore in this direction, Thank you again!

  • DorlanDorlan Posts: 4

    Alwright, I finally have found a way to select only the skeleton and it works... Thanks Richard! this is my script :

    __________________________________________________

    var skel = Scene.getSkeleton(0);
    if( skel )
    {
     if( skel.inherits( "DzBone" ) )
     {
      skel = skel.getSkeleton();
     }
      skel.select( true);
      }

    _______________________________________

    Is it correct?

    Next, i have to find a way to toggle the selection between two skeletons. 

    Well, brick by brick... 

  • getSkeleton( # ) should always return null or a skeleton, but there's no harm in double checking. As for toggling, assuming you have skel1 and skel2

    if ( skel1.isSelected() ) {     skel1.select( false );     skel2.select( true );}else if ( skel2.isSelected() ) {     skel1.select( true );     skel2.select( false );}else {     // default state here     skel1.select( false );     skel2.select( true );}

    might work.

  • DorlanDorlan Posts: 4
    edited January 2020

    Great! I have tried many things without any succes for the toggle part, but now it looks very clear when you show those conditions "if and else if", yes i have created two "skel", but it seems that i have missed something because the toggle doesn't work for the moment,  but what you mean about  "getskeleton(#) should always return null or a skeleton? Maybe that is what i do wrong...  thank you very much for your help!

    This is my new version :

    var skel1 = Scene.getSkeleton(0);if( skel1 ){	 if( skel1.inherits( "DzBone" ) ){ 	  skel1 = skel1.getSkeleton();}  skel1.select( true);  }  var skel2 = Scene.getSkeleton(4);if( skel2 ){ if( skel2.inherits( "DzBone" ) ) {  skel2 = skel2.getSkeleton(); }  skel2.select( true );  } if ( skel1.isSelected()){ 	  skel1.select(false); 	  skel2.select(true); 	  }else if(skel2.isSelected()){	    skel1.select(true); 	    skel2.select(false);	}else { skel1.select (false);	   skel2.select (true);	  }

     

    Post edited by Dorlan on
Sign In or Register to comment.