Created
March 5, 2015 03:46
-
-
Save Squid3d/8e758f367dd03734f115 to your computer and use it in GitHub Desktop.
using yield to iterate c4d object/tag and materials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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