Dear forum,
I am writing a GH plug-in where I’ve created a class called Plank. Into the current component,which I am writing, a tree of Planks are feed. I’ve written a code that compiles, but when I try the component out, I get the following error message:
- Solution exception:Unable to cast object of type ‘Grasshopper.Kernel.Types.GH_ObjectWrapper’ to type ‘geoPlankNetworks.DataTypes.Plank’.
And this is my code
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Plank", "p", "p", GH_ParamAccess.tree);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddBrepParameter("Mid surface", "mS", "mS", GH_ParamAccess.tree);
pManager.AddBrepParameter("Top surface", "tS", "tS", GH_ParamAccess.tree);
pManager.AddBrepParameter("Bottom surface", "bS", "bS", GH_ParamAccess.tree);
pManager.AddBrepParameter("Plank solid","pS","pS",GH_ParamAccess.tree);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
GH_Structure<IGH_Goo> iPlankTree;
if (!DA.GetDataTree(0, out iPlankTree)) return;
DataTree<Brep> midSurfaces = new DataTree<Brep>();
DataTree<Brep> topSurfaces = new DataTree<Brep>();
DataTree<Brep> bottomSurfaces = new DataTree<Brep>();
DataTree<Brep> plankSolids = new DataTree<Brep>();
foreach(GH_Path path in iPlankTree.Paths)
{
foreach(Plank plank in iPlankTree.get_Branch(path))
{
midSurfaces.Add(plank.MidSurface, path);
topSurfaces.Add(plank.TopSurface, path);
bottomSurfaces.Add(plank.BottomSurface, path);
plankSolids.Add(plank.PlankSolid, path);
}
}
DA.SetDataTree(0,midSurfaces);
DA.SetDataTree(1,topSurfaces);
DA.SetDataTree(2,bottomSurfaces);
DA.SetDataTree(3,plankSolids);
}
It would be great if someone could help me out here.
Thanks,
David