Iterators is a common concept in Python world. It would be nice to be able to use `for item in collection` syntax to iterate over collection items.
I'm not sure how exactly Fusion API works. In Python I'd do something like this:
class Base:
"""Represents adsk.core.Base"""
class CollectionMixin:
"""Allows to use `for .. in` to iterate over collection."""
def __iter__(self):
return autodesk_collection_generator(self)
def autodesk_collection_generator(collection):
for index in range(collection.count):
yield collection.item(index)
class Document(Base):
"""Represents adsk.core.Document"""
class Documents(Base, CollectionMixin):
"""Container for Document.
Represents adsk.core.Documents
"""
def item(self, index):
return Document()
@property
def count(self):
return 3
With this implementation we'd be able to do this:
for item in Documents():
do_stuff_with(item)
For now it is possible to use this `autodesk_collection_generator` directly when required:
for product in autodesk_collection_generator(app.activeDocument.products):
print(product.productType)