Announcements
Visit Fusion 360 Feedback Hub, the great way to connect to our Product, UX, and Research teams. See you there!
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Support for `for .. in` operation for collections

Support for `for .. in` operation for collections

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)

 

 

2 Comments
colin.smith
Alumni
We appreciate your time in submitting your idea. This item has been archived due to a lack of votes. Please feel free to resubmit if you feel this is still a valid idea.
colin.smith
Alumni
Status changed to: RUG-jp審査通過
 

Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea  

Autodesk Design & Make Report