algorithmic modeling for Rhino

I'm trying to extract the UserStrings of any input geometry that inherits this property from GeometryBase. I'm having some trouble with type casting in C#.


Here's my current code:

var data = geometry.GetUserStrings();

In the code above, 'geometry' would point to a GeometryBase object

Here's the Error I'm receiving:

error: Unable to cast object of type 'Rhino.Geometry.PolylineCurve' to type 'System.IConvertible'. (line: 0)

Views: 140

Reply to This

Replies to This Discussion

Hi Ben,

I do not think the problem is immediately at that line. Can you post a larger sample?
What is happening to "data"?


- Giulio

You are right, it was because I was trying to cast 'geometry' to a Boolean, like I do in python, thinking that would prevent errors that occur when there is no input, like the 'Object reference not set to an instance of an object' error.


I had used this:

if (System.Convert.ToBoolean(geometry)) {
// other stuff

That is what caused the error.

is there an easy way to test if 'geometry' (or any other variable) contains an instance or not?

Hi Benjamin,

in C# this is:

geometry != null

However, there are some other tiny syntactic and semantic differences. You should read a C# book or have a look at some introductory websites to gain better insight. For example, an empty array is not equivalent to null in C#, and you need to explicitly check against it (if the case requires).


- Giulio

Thank you Giulio.

I had learned some C# before I started python, but it's been quite a while. I definitely need to find a good quick reintroduction.

I think the books by Jesse Liberty were effective. Maybe a little general.

- Giulio

Thanks! I'll check it out



Search Grasshopper


  • Add Photos
  • View All

© 2014   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service