Does it need to be python? If you know the null you could just Middle Mouse click on it to select it’s children.
If it does need to be python, you can try something like this:
def GetAllObjects(obj, objList):
if obj is None: return
#Actions can go here
objList.append(obj)
#End Actions
if (obj.GetDown()):
GetAllObjects(obj.GetDown(), objList)
if (obj.GetNext()):
GetAllObjects(obj.GetNext(), objList)
return objList
def GoDownHierarchy(obj, stop, objList):
if obj is None: return
if obj==stop: return
#Actions can go here
objList.append(obj)
#End Actions
if (obj.GetDown()):
GoDownHierarchy(obj.GetDown(), stop, objList)
if (obj.GetNext()):
GoDownHierarchy(obj.GetNext(), stop, objList)
return objList
def main():
emptyList=[]
allObjs=GetAllObjects(doc.GetFirstObject(), emptyList)
null=None
for obj in allObjs:
name=obj.GetName()
if len(name.split('_')>0:
if name.split('_')[-1]=='cpk':
null=obj
break
if null != None:
emptyList2=[]
children=GoDownHierarchy(null, null.GetNext(), emptyList2)
if len(children)>0:
for id, child in children:
if id==0:
doc.SetSelection(children, c4d.SELECTION_NEW)
else:
doc.SetSelection(children, c4d.SELECTION_ADD)
So, the idea here is if you need to manage to find the null through python, we have to get all of the objects in our scene and look for it. So the first function gets every object in the scene when you pass in doc.GetFirstObject(). The function actually gets every object underneath whatever you pass in (child or siblings included). So starting at the top of the OM gets all of the objects.
So then we loop through those objects and look for an object that ends with _cpk. Once we have that, we run the second function which gets all of the children of the object you pass in. Then we just loop through all those children and set them to be selected.
I can’t guarantee this works properly as is because I wrote it from memory and this link on my website http://bretbays.com/2011/02/11/a-useful-python-snippet-addendum/ but conceptually that should work. Someone else might know of a better way to do it than this.
Hope this helps.
~Bret