Skip to content

Instantly share code, notes, and snippets.

@Squid3d
Created March 5, 2015 03:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Squid3d/8e758f367dd03734f115 to your computer and use it in GitHub Desktop.
Save Squid3d/8e758f367dd03734f115 to your computer and use it in GitHub Desktop.
using yield to iterate c4d object/tag and materials
import c4d
def walk_objects(obj):
if obj:
yield obj
for x in walk_objects(obj.GetDown()): # happily fail on tags and materials
yield x
for x in walk_objects(obj.GetNext()):
yield x
if __name__=='__main__':
obj = doc.GetFirstObject()
tag = obj.GetFirstTag()
mat = doc.GetFirstMaterial()
# to iterate through object heirarchies
for o in walk_objects(obj):
print o.GetName()
# iterate through tags on first object
for t in walk_objects(tag):
print t.GetName()
# and mats
for m in walk_objects(mat):
print m.GetName()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment