Grasshopper

algorithmic modeling for Rhino

I am trying to add a list of strings using the RhinoList, but I cannot see how to do this. When I define the list and then check the type I get back 'bool' even though I tried to define it as 'str'. Can anyone help me on this? I have spent a long time looking through the documentation and doing google searches and cannot find any help. Should I be using another type of list? I want to output the list from my function so that I can label items.

import Rhino

Element_ID = Rhino.Collections.RhinoList<str>()

print type(Element_ID)

print Element_ID.Add("test")

<type 'bool'>
Runtime error (MissingMemberException): 'bool' object has no attribute 'Add'
Traceback:
line 4, in script

Views: 457

Replies to This Discussion

Sorry - mis-typed the code (added a "print" by mistake)...

import Rhino

Element_ID = Rhino.Collections.RhinoList<str>()

print type(Element_ID)

Element_ID.Add("test")

<type 'bool'>
Runtime error (MissingMemberException): 'bool' object has no attribute 'Add'
Traceback:
line 4, in script

OK... I think I now understand... but please correct me if I am wrong:

I am using the wrong kind of list. The simple python list works fine. From what I have read, I think that the RhinoList is for GUIDs, rather than for generic data types. It would be helpful if the documentation explained what the <T> can represent, though.

Element_ID = []

print type(Element_ID)

Element_ID.append("test")

Output:

Element_ID [] is of type <type 'list'>

Your original request would be translated, in IronPython, to this:

import Rhino

Element_ID = Rhino.Collections.RhinoList[str]()
print type(Element_ID)
Element_ID.Add("test")

However usually a normal Python list (list() or []) will work.
If you are translating a C# sample, both should work fine.

Thanks,

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service