algorithmic modeling for Rhino
Hi,
Maybe this is not an error but I found the behaviour somehow strange. I wanted to use the Branch/DataItem properties of a GH_Structure, which according to the documentation should exist, but this leads to a Compile Error CS1546 requiring to use the accessor method get_branch / get_dataitem instead.
GH_Structure<GH_Number> testStructure = new GH_Structure<GH_Number>();
testStructure.Append(new GH_Number(5.0), new GH_Path(1, 2));
GH_Number x = testStructure.DataItem(new GH_Path(1, 2), 0);
List<GH_Number> y = testStructure.Branch(new GH_Path(1, 2));
However when trying to use the get_branch method it works but does not return in this case a list of GH_Number (in this case) as I would have expected, but something more generic which then needs to be converted again in the type I want to work with. Is this the way it's supposed to work or is one simply supposed to use other methods/properties to access branches/items of a GH_Structure?
I have added an example script, same thing happens when developping components in Visual Studio.
Tags:
C# doesn't support more than one indexer property per class, so you can't use the DataItem[path, int] property. As the error message suggests, you have to revert to the underlying method:
GH_Structure<GH_Number> testStructure = new GH_Structure<GH_Number>();
testStructure.Append(new GH_Number(5.0), new GH_Path(1, 2));
GH_Number x = testStructure.get_DataItem(new GH_Path(1, 2), 0);
A = x;
Thanks for the quick reply. Actually I was not so much concerned with the fact of using multiple indexers, even though the Grasshopper SDK Documentation suggests that such a property exists. But it also suggests a Branch property exists which would take an integer or a GH_Path as indexer, but none seems to work. In the example above that would be:
var y = testStructure.Branch[new GH_Path(1,2)];
Also I find it still confusing that the get_branch property returns an IList of type object instead of a List of the type which is stored in the GH_Structure (in this case a GH_Number).
This works in VB only because it can handle properties with arguments. C# cannot, with the sole exception of the 'this' indexing property. You will always have to use the method approach:
testStructure.get_Branch(new GH_Path(1,2));
Welcome to
Grasshopper
© 2025 Created by Scott Davidson.
Powered by