Ah yeah, sorry, it was a bit a shambles
I did solve it, but didn't realise I could just say "and".
I found a way to do the name a bit differently, not sure what the pros and cons of each would be.
So my code was like this:
import c4d
def main():
obj = doc.SearchObject('BloodCells')
parent = obj # stores the active object in a 'parent' variable, so it always stays the same
if obj: # if there is a object selected
children = [] # create an empty list to store children
while obj: # while there is a object (the "walker" function will return None at some point and that will exit the while loop)
obj = walker(parent, obj) # set the obj to the result of the walker function
if obj: # if obj is not None
children.append(obj) # append that object to the children list
print children # print the list
childrenC = len(children) #children Count
print "There are " + str(childrenC) + " objects in the hierarchy."
if childrenC > 0:
activeChildren = []
for c in children: # Loop Through Children, each one is "c"
if c[c4d.ID_BASEOBJECT_GENERATOR_FLAG] == True: # If the object is generator-active
activeChildren.append(c) #append it into the list "activeChildren"
theName = c.GetName() #what is the Object Manager name of the current object?
#print theName
if theName == “VirusCells":
print "I found the Virus Cells Object, now you can do an action with it"
else:
print "Not what you were looking for!"
activeChildrenC = len(activeChildren)
#print “And there were " + str(activeChildrenC) + " Active Children"
def walker(parent, obj):
if not obj: return # if obj is None, the function returns None and breaks the while loop
elif obj.GetDown(): # if there is a child of obj
return obj.GetDown() # the walker function returns that child
while obj.GetUp() and not obj.GetNext() and obj.GetUp() != parent: # if there is a parent of the obj and there isn't another object after the obj and the parent object is not the same object stored in "parent"
obj = obj.GetUp() # it sets the current obj to that parent
return obj.GetNext() # and return the object that's after that parent, not under, after :)
It's probably too many lines but its more human readable, to me anyway. 🙂
Also to be clear again, for anyone else, it uses some code from Kalugin that was very nicely commented to walk the tree. Now that's it's posted I can't seem to edit the code box to put it in!
Thanks!