generative 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)
Tags:
Permalink Reply by Giulio Piacentino on February 18, 2012 at 9:48am Hi Ben,
I do not think the problem is immediately at that line. Can you post a larger sample?
What is happening to "data"?
Thanks,
- Giulio
_______________
giulio@mcneel.com
Permalink Reply by Benjamin Golder on February 18, 2012 at 11:20am 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.
Permalink Reply by Benjamin Golder on February 18, 2012 at 11:22am is there an easy way to test if 'geometry' (or any other variable) contains an instance or not?
Permalink Reply by Giulio Piacentino on February 18, 2012 at 2:13pm 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).
Thanks,
- Giulio
________________
giulio@mcneel.com
Permalink Reply by Benjamin Golder on February 18, 2012 at 2:25pm 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.
Permalink Reply by Giulio Piacentino on February 18, 2012 at 2:30pm I think the books by Jesse Liberty were effective. Maybe a little general.
- Giulio
________________
giulio@mcneel.com
Permalink Reply by Benjamin Golder on February 19, 2012 at 2:19am Thanks! I'll check it out
Added by David Stasiuk 6 Comments 18 Likes
Added by stefano 5 Comments 7 Likes
© 2013 Created by Scott Davidson.
Powered by