algorithmic modeling for Rhino
So Im writing a plugin in C# in Visual Studio, and have these two basic classes:
Class: FlatPanel or Curved Panel (both implement IPanel)
List <PanelComponent> panelComponents;
Class: PanelComponent
List <GeometryBase> geoms;
Dict <string, string> props;
In Grasshopper, I am feeding a (custom) "Unwrap Panel Contents" component a tree of panels in the format {a;b}(n). In this tree, "a" corresponds to the building floor and "b" corresponds to the location on the floor; n is always a single item, the panel class.
I'm trying to write the "Unwrap Panel Contents" component such that when it "unwraps" the panel, it does so in a structured way. Ideally, I want the output structure to be in the format {a;b;c}(n), where a and b are the same as above, c corresponds to the index of the panel component, and n is a list of stuff.
I've hit a few stumbling points...
I defined "PanelGoo" and had it implement "GH_Goo<IPanel>". I'm not sure what to put in these:
public override bool IsValid
public override string TypeDescription
public override string TypeName
public override IGH_Goo Duplicate()
public override string ToString()
In solveInstance, I'm stuck after just these lines:
GH_Structure<PanelGoo> panels = new GH_Structure<PanelGoo>();
if (!DA.GetDataTree<PanelGoo>(0, out panels)) return;
for (int i = 0; i < panels.PathCount; i++)
{
GH_Path pth = panels.Path[i];
IPanel panel = panels.Branch[pth];
}
I get two errors:
Property, indexer, or event 'GH_Structure<PanelGoo>.Path[int]' is not supported by the language; try directly calling accessor method 'GH_Structure<PanelGoo>.get_Path(int)'
Property, indexer, or event 'GH_Structure<PanelGoo>.Branch[GH_Path]' is not supported by the language; try directly calling accessor method 'GH_Structure<PanelGoo>.get_Branch(GH_Path)'
Side note:
I also tried using GetData/ Item access instead, hoping that maybe the output would get "tree'd" after leaving SolveInstance, but that doesn't seem to work, I just get a single list from each output, no structure.
I've been studying this thread obsessively:
http://www.grasshopper3d.com/forum/topics/custom-data-type-gh-geome...
Been trying to deconstruct the code examples, but not making much progress. Could anyone offer some guidance on handling a tree as an input?
Thanks
Tags:
This seems closer to working, but Im still getting an error:
'object' does not contain a definition for 'panelComponents' and no extension method 'panelComponents' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
It seems like I can traverse the GH_Structure alright, but as soon as I try to use any of the Panel class's methods or properties, I hit an error. I think I need to cast or convert out of IGH_Goo back into the panel class..?
GH_Structure<IGH_Goo> panelsTree = new GH_Structure<IGH_Goo>();
if (!DA.GetDataTree<IGH_Goo>(0, out panelsTree)) return;
IList <GH_Path> allPaths = panelsTree.Paths;
List<string> pathStrings = new List<string>();
DataTree<GeometryBase> outputGeometries = new DataTree<GeometryBase>();
foreach (GH_Path onePath in allPaths) {
foreach (System.Collections.IList panelsBranch in panelsTree.Branches) {
foreach (GH_ObjectWrapper wrappedObject in panelsBranch) {
var panel = wrappedObject.Value;
foreach (PanelComponent panelComponent in panel.panelComponents) {
outputGeometries.EnsurePath(onePath);
outputGeometries.AddRange(panelComponent.geom, onePath);
}
}
}
pathStrings.Add(onePath.ToString());
}
DA.SetDataTree(0, outputGeometries);
DA.SetDataList(1, pathStrings);
I have something that I think is almost working... It compiles, but when I test it, I get this error:
"An exception of type 'System.InvalidCastException' occurred in Ocammy.gha but was not handled in user code
Additional information: Unable to cast object of type 'Rhino.Geometry.Brep' to type 'Grasshopper.Kernel.Types.IGH_GeometricGoo'."
Am I making some obvious mistake? I attached my code, also.
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