Script to toggle visibility of a node and all children nodes?

cwichuracwichura Posts: 1,042
edited December 1969 in Daz Studio Discussion

Anyone aware of a script for Studio that will toggle the visibility of a selected node and all of its children nodes in one shot? This would be useful for things like turning off the left or right collar on down through all the fingers on a set of gloves when you only want the left or right glove, for example. Obviously, one can toggle each node manually, but when there are a lot of nodes, it's a nuisance due to the UI lag when toggling nodes.

Thanks

Comments

  • SickleYieldSickleYield Posts: 7,629
    edited December 1969

    You don't have to toggle them individually. Select the root note you want to start from in the Scene Tab and right-click, then choose Select Children. Now you can toggle them all invisible simultaneously in Parameters tab--Display. Just make sure you turn off both Visible and Visible In Render.

  • Richard HaseltineRichard Haseltine Posts: 96,736
    edited December 1969

    You can multi-seelct and then turn the visibility off for all in the Parameters pane, but something like

    var startNode = Scene.getPrimarySelection();
    if ( startNode ) {
     var nodes = [ startNode ];
     nodes = nodes.concat( startNode.getNodeChildren( true ) );
     for ( var n = 0 ; n < nodes.length ; n++ ) {
      nodes[ n ].setVisible( false );
     }
    }

    and the same with nodes[ n ].setVisible( true ); to show them again.

  • SickleYieldSickleYield Posts: 7,629
    edited December 1969

    Crosspost with Mr. Kitty Cat. ;) Or you can do that.

  • cwichuracwichura Posts: 1,042
    edited December 1969

    Hmm, so the elements in the Display sub-category correspond to the node visibility icon in the Scene list? I've never actually messed with the stuff under Display. But the visibility icons in the Scene list ignore multi-selection, hence my original request. If you toggle them in the Display sub-category, does the visibility icon also change?

    And thanks Richard for the script. I'll give that a try when I'm back in the office tomorrow.

  • Richard HaseltineRichard Haseltine Posts: 96,736
    edited December 1969

    Yes, the eye in the Scene pane and the visibility button in Parameters are the same property, just different ways to access it - that's also true of the selectable control

  • srieschsriesch Posts: 4,241
    edited December 1969

    Very handy info. Thanks!

  • kitakoredazkitakoredaz Posts: 3,526
    edited May 2013

    Richarrrrrd ^^;
    one more quesiton,,, I simply make visible selection node and children , sciot

    (just change "false" to "true" ) from your auto invisible selection node and children scirpt.

    but as you know,, when I hope to visble under r-foot,, if the root genesis set invisibe,
    it can not work,,

    so I may need apply code,,

    "if root node is invsible turn root visible "
    "else you need not do anything,, it may work"

    so please tell me the ds script code to do it^^;

    ============
    or simply I need to apply ,
    anyway select root ,set root visible.

    I know it is so easy,, but where is good place to understand each ID or action etc in daz studio? ^^;
    or would not you tell me the link of them directly?

    Post edited by kitakoredaz on
  • kitakoredazkitakoredaz Posts: 3,526
    edited December 1969

    var startNode = Scene.getPrimarySelection();
    
    
    if ( startNode ) {
      var nodes = [ startNode ];
     nodes = nodes.concat( startNode.getNodeChildren( true ) );
     for ( var n = 0 ; n < nodes.length ; n++ ) {
      nodes[ n ].setVisible( true );
     };
     
     var rootNodeTemp = startNode;
     var checkRoot = rootNodeTemp.isRootNode(); 
     while(checkRoot == false){;
       rootNodeTemp = rootNodeTemp.getNodeParent();
       checkRoot = rootNodeTemp.isRootNode();
      }
     rootNodeTemp.setVisible( true ); 
     };

    is it wrong?

  • Richard HaseltineRichard Haseltine Posts: 96,736
    edited May 2013

    You could also try adding this to the loop

     for ( var n = 0 ; n < nodes.length ; n++ ) {
      nodes[ n ].setVisible( true );
      if ( nodes[ n ].inherits( "DzBone" ) {
       if ( nodes[ n ].getSkeleton() ) {
        nodes[ n ].getSkeleton().setVisible( true );
       }
      }
     }

    Or it may be more efficient to use Scene.getSelectedSkeletonList() at the start and make all of those visible before going through the nodes, though with a simple script like this the overhead of checking the same skeleton repeatedly if multiple bones are selected probably doesn't matter.

    Post edited by Richard Haseltine on
  • kitakoredazkitakoredaz Posts: 3,526
    edited December 1969

    I checked skelton and bone method and property etc,, but it was difficult to understand at first challenge how to use them,,, ^^;

    Is not there "method" which serch and direct get the root node and return it,, by current selected Node?
    like,, getRootNodeEasy() ,, I hoped and serched it,,,^^;

    "if multiple bones are selected" yes,, I know,,I thought the case,, if apply multselection, it can be more useful.
    But,,, actually,,,,I do not like scripting so ,,, ^^;
    anyway thank you much.

  • Richard HaseltineRichard Haseltine Posts: 96,736
    edited December 1969

    The skeleton is the root node of the figure - strictly speaking, the root node inherits DzSkeleton but is a derivative object in DS4, figures are now either Poser figures or TriAx figures, but in DS3 all figures (except Optitex cloth perhaps) were plain DzSkeletons.

  • Richard HaseltineRichard Haseltine Posts: 96,736
    edited May 2013

    The other way to get at the root, if you also want to get the top of a set or parented props or a group, is to use something like

    var root = node;
    while ( root.getNodeParent() } {
         root = root.getNodeParent();
    }

    which is slightly simpler than your script. You can then build an array of roots by declaring an array and using array.pushIfNotExists( root ) to make sure each root is added only once, then go through that array doing whatever it is you want (rather than getting the root for each node and performing the action on that, possibly adding unneeded repeats).

    Post edited by Richard Haseltine on
  • kitakoredazkitakoredaz Posts: 3,526
    edited December 1969

    thank you,,,, I keep tweaking,, array etc,,I may keep studying, step by step,,

    Now I check your script one by one,, about method and dzclass,,etc,,
    I now understand how to get selected multi node as array,,
    and get the qobject name,,,

    .(I do not like scripting,, but feel interesting now ^^;)

    and I may hope more quesiton,,, so where is best forum to ask these?
    nuts and bolts may ok? or new user forum?

    because my quesiton seems so basic,, i think,, eg,,
    I want to know,, save as documents which I indicate in message box.
    I saw script rdwigh wrote,,, which show all short cut,, but I hope to save it as txt.

    so I am serching way,, which class or method may work,,to save it as txt.
    anyway,, good night,sir Richard I need to sleep now ^^;

  • Richard HaseltineRichard Haseltine Posts: 96,736
    edited December 1969
Sign In or Register to comment.