algorithmic modeling for Rhino
Hey all,
I'm trying to convert Rhino Breps to GH_Breps in Visual Studio for use in a custom component, but keep getting thrown "InvalidCastException". Any advice?
Have tried both casting using the GH_Brep newBrep = ((Brep) myBrep) constructor, as well as the GH_Convert method included in my current code below:
DataTree<object> objectTree = { ...output from another component, but has one branch of 100 objects (that are actually Rhino breps) }
List<GH_Brep> brepList = new List<GH_Brep>();
for (int i = 0; i < objectTree.Branch(0).Count; i++)
{
Brep convertMe = (Brep)objectTree.Branch(0)[i];
GH_Brep addMe = new GH_Brep();
GH_Convert.ToGHBrep_Primary(convertMe, ref addMe);
brepList.Add(addMe);
}
Tags:
If this is of your first times compiling gh components, you should take a look at the SDK of GH. In the GH toolbar: Help> Donwload SDK Help... and go to Examples> C #> Sample geometry.
Data collection is different from C# script and a compiled component. If you're writing with VS, then you should have something like DA.GetDataList (), or maybe instead of object class you should put GeometryBase class... or maybe I misunderstood the problem X)
new GH_Brep(convertMe);
All the GH_XXXX data types wrap other data types, so usually they have constructors which take the wrapped type.
Thanks for the quick replies guys! Daniel, my apologies, I should have been more clear. This snippet is manipulating data already passed into the component, using the DA getter like you suggested.
David, I tried this:
List<GH_Brep> brepList = new List<GH_Brep>();
for (int i = 0; i < objectTree.Branch(0).Count; i++)
{
Brep convertMe = (Brep)objectTree.Branch(0)[i];
GH_Brep addMe = new GH_Brep(convertMe);
brepList.Add(addMe);
}
And it still didn't work! Am I misunderstanding the method?
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by