-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectIterator.py
40 lines (33 loc) · 1.16 KB
/
ObjectIterator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import c4d
from c4d import documents as docs
class ObjectIterator :
def __init__(self, baseObject):
self.baseObject = baseObject
self.currentObject = baseObject
self.objectStack = []
self.depth = 0
self.nextDepth = 0
def __iter__(self):
return self
def __next__(self):
if self.currentObject == None :
raise StopIteration
obj = self.currentObject
self.depth = self.nextDepth
child = self.currentObject.GetDown()
if child :
self.nextDepth = self.depth + 1
self.objectStack.append(self.currentObject.GetNext())
self.currentObject = child
else :
self.currentObject = self.currentObject.GetNext()
while( self.currentObject == None and len(self.objectStack) > 0 ) :
self.currentObject = self.objectStack.pop()
self.nextDepth = self.nextDepth - 1
return obj
if __name__ == '__main__':
doc = docs.GetActiveDocument()
obj = doc.GetFirstObject()
scene = ObjectIterator(obj)
for obj in scene:
print (scene.depth, scene.depth*' ', obj.GetName())