Dynamo and Python nodes: Icollection?

Hi guys, I need some help here with a Python issue. I dive deeper in the API, and very often a ICollection is needed to perform actions. AFAIK nodes always retrieves lists, I’d like to find a way to transform or convert a list into an ICollection so that it becomes an input into a Python node. don’t really know if it’s doable, I make some search on the net with no luck. Thanks.

Hey Julien,

I believe an Icollection is just an interface for collections to implement, list should already implement this in python so you can just convert between them. Check out this stack overflow and see if it helps.

Let me know if I’m misunderstanding your intention.


also, post the API methods you’re interested in and I can take a look at making something concrete.

Thanks for the answer Michael. I try to make a python node that will use the CopyElements method, and it needs the source document, an iCollection of elements, destination doc,etc. My issue is about ICollection. If I send a single element or a ist, API claims for ICollection. i need to understand how to convert a list into an I Collection. I will look at your link carefuly, but my skill may not be high enough :slight_smile:

Hopefully I 'll have a chance to make a small example soon.

This doesn’t exactly answer your question but I think this works because we’re converting this to a .net list that implements Icollection and is typed to elementID, note that we need to import system.collections.generic from .net system. This is kind of strange for python since we’re using typed lists, but it’s what the api requires.

Screen Shot 2014-04-16 at 1.24.15 PM

Great example. will try it very soon. I also discovered the need of system.collections.generic, but then I needed a coder like you. thanks again.

I managed to make it work. My goal was to copy-paste elements from a linked file to the host in one command. this seems to work. Will share it ASAP in both blog post and package. thanks!!