logic problem to obtain the entire hierarchy of the object
-
https://developers.maxon.net/forum/topic/13045/alternative-way-to-iterate-list-other-than-getnext/3
In my search for a solution, I came across this post that works well and returns a list of all child objects in order. However, is there a way to save lists within other lists containing all the objects so I can keep track of the hierarchy?maybe in this structure:
hierarchy = [obj1, obj2[obj2.5, [obj2.75], obj3[obj4, [obj5]]
-
Hi @pyxelrigger ,
Unfortunately your question is out of the scope of support on this forum, namely:
We cannot provide support on learning C++, Python, or one of their popular third-party libraries.
With that's said, I'm kind of missing the main idea behind your question, in other words what are you trying to achieve?
Is it just another (e.g. simply more convenient) data structure for the hierarchy? If so, then you're free to create whatever data structure fits your need the best. For example, check a very fast draft code snippet below.
Is it that you want to track changes of the hierarchy? If so, then you might need to come up with some more complex setup, e.g. involving using the c4d.EVMSG_CHANGE message. Please, refer to a great Ferdinand's answer here: Best way to detect an object has been deleted?
Please also consider visiting our How to ask Questions section of the support procedures for your future postings.
Cheers,
IliaA super draft example of nested lists hierarchy representation:
import c4d doc: c4d.documents.BaseDocument class HierarchyObject: def __init__(self, op): self.op = op self.children = [] child = self.op.GetDown() if op else doc.GetFirstObject() # recursion entry point while child: self.addChild(HierarchyObject(child)) # recursion child = child.GetNext() def addChild(self, child): self.children.append(child) def toString(self, indentation: int = 0): indentStr: str = '\t' * indentation name: str = self.op.GetName() if self.op else '___root___' s: str = f'{indentStr}<{name}' if self.children: s += ':' for child in self.children: s += f'\n{child.toString(indentation + 1)}' s += f'\n{indentStr}' s += '>' return s def __str__(self): return self.toString() if __name__=='__main__': root: HierarchyObject = HierarchyObject(None) print(root)