|
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 (parentModel, selectParent = 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.
|