Grasshopper

algorithmic modeling for Rhino

Im trying to make a component that has an input that can take a list of both breps, and text.  Then in the component it would sort through the inputs.

Currently I have an input set to List Access with the Type Hint of System.Object.  It takes these inputs just fine, but then when I try to access the inputs, it gives me an error if I try to access the item which is text.

Im testing a list of 

(0) Brep

(1) TestString

(2) TestString

the code looks something like this...

int i = 0;

while(i < MyList.Count)

{

  Print(MyList[i].GetType().ToString());

  i++;

}

If I replace "MyList[i]" with "MyList[0]" it works fine.  But when I try to access the text, i get this error:

1. Object reference not set to an instance of an object. (line: 0)

Any advice?

Views: 723

Replies to This Discussion

Ah! You are correct!  Turns out the error was in a different part of the script.  Really what Im looking to do is instead of Printing the type, I want to assigin it to sepperate lists of type string, and GeometryBase... so more like this...


List<string> myString = new List<string>();
List<GeometryBase> myGeom = new List<GeometryBase>();

int i = 0;

while(i < myList.Count)

{
  if(myList[i].GetType() == typeof(string))
    myString.Add(myList[i].ToString());
  else if(myList[i].GetType() == typeof(Brep))
    myGeom.Add(myList[i]);

  else

    Print("Cannot accept Objects of type " + myList[i].GetType().ToString());

  i++;

}

I was able to get around the casting the string with the .ToString().  But have not found how to assign the brep to GeometryBase.  In Theory I would add if statements for all geometry types I want to accept.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service