Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® MotionBuilder® / Python / how to select branches?
  RSS 2.0 ATOM  

how to select branches?
Rate this thread
 
22906
 
Permlink of this thread  
avatar
  • Location: Los Angeles CA
  • Total Posts: 99
  • Joined: 16 May 2008 02:40 AM

Hi,

I want to select branches for an item that appears in the scene list on the navigator tab in the GUI. I’m able to select the objects that appear in the schematic view, but how can I select everything else in the branch, in particular, shaders, materials, lights, constraints, and groups?

thx,
BRian



MotionBuilder 7.5 thru ...
3dsMax 2.5 thru ...

Replies: 0
avatar
  • Serguei
  • Posted: 17 February 2009 08:17 PM

I couldn’t find a method in the SDK to do this so here’s a function I use to select children.
It could be expanded to add a selection filter as well.

def selectChildren (parentModelselectParent True):
    
# Get model children
    
children parentModel.Children
    
    
# Check if any children exist
    
if (len (children) != 0):
        
# Loop through the children
        
for child in children:
            
# Select the child
            
child.Selected True
            
            
# Get any children
            
selectChildren (child)
    
    
# Select parent
    
parentModel.Selected selectParent
    
    
# Return status
    
return True


Replies: 0
avatar

thanks, but my script can select children already, but it doesn’t select a shader that is in the branch. A shader wouldn’t be a child right?



MotionBuilder 7.5 thru ...
3dsMax 2.5 thru ...

Replies: 0
avatar
  • Serguei
  • Posted: 17 February 2009 09:10 PM

If I recall even though MB abstracts certain object types like materials outside the main scene graph in the Navigator, the actual nodes still exist in the hierarchy and should be selected as children.



Replies: 0
avatar
  • StephG
  • Posted: 18 February 2009 03:41 AM

f I remember my experience I wound up using parentmodel.Components.

You have to do two things when doing it that way: you have to stop the recursion when you reach a constraint. I listed the types in this thread:
http://area.autodesk.com/for...tify-what-a-component-is/

The second thing you have to do, is before you try to use the “if component.Is(99):” query to stop the recursion, you have to make sure it has that attribute by first using “if hasattr("Is"):" It’s also a good idea to make sure it has a “Name” attribute and “Selected” attribute the same way. But it will get *everything” that is a child.

So with a little modification to the script above:

def selectChildren (parentModelselectParent True):
    
# Get model children
    
children parentModel.Components
    
    
# Check if any children exist
    
if (len (children) > 0):  # I use ">" because "!=" lets "-1" proceed 
        # Loop through the children
        
for child in children:
            
# Select the child
            
if not hasattr("Name"):
                 continue
            if 
hasattr("Is");
                 if 
child.Is(99):#99 is the number for constraints
                     
continue
            if 
hasattr("Selected"):
                 
child.Selected True
            
#Just to be safe
            
try: 
                 
# Get any children
                 
selectChildren (child)
            
except:
                 continue
    
    
# Select parent
    
parentModel.Selected selectParent
    
    
# Return status
    
return True

The only reason I use the “Name” attribute as a test, is that if it doesn’t, it’s something you really don’t want to continue further with.

BTW, if you follow to that former thread listed above, follow the advice to count down from 100 for a match because other objects will answer to ...Is(40) besides Models, as an example. Some components answer to multiple .Is matches.



Replies: 0