I tried port a code snippet from C# by @fraguada into VB script component in Grasshopper, but the VB code doesn’t seem to accept the Breps or Geometry that the C# code accepts : The line (85) that fails:
84 If Nothing = RhinoDocument.InstanceDefinitions.Find(name, True) Then
85 RhinoDocument.InstanceDefinitions.Add(name, description, basePoint, objects)
The VB script fails with message (translated from Swedish) :
“error: Coul’d not convert an object of type Rhino.Geometry.Brep to the type System.Collections.Generic.IEnumerable`1[Rhino.Geometry.GeometryBase]. (line: 85)”
Fig 1 & 2: Showing the C# & VB script components side by side with VB failing with similar code :
I can see both from the mouse-over hints and from the error message that there’s a type mismatch, but I have no idea what an “Enumerable” is in this context, and how to fix it. I thought Brep was a Brep was a Brep… kindof. Well, an object id, but…
Edit 1: When I checked, the argument type (for ‘objects’) is defined as follows :
C#: , geometry As IEnumerable<>
VB: , IEnumerable<> geometry
Same thing as far as I can see.
I have no idea why the same input comes in as valid data in one case (whatever that is, IDs I think) and “something else” in the other case. I’m lost.
So how do I cast from VB’s Object to IEnumerable(Of Geometry)?
In VB the incoming parameter is of type Object (list of Breps)
Private Sub RunScript(....ByVal objects As Object...)
while in C# the param is typed as a generic list:
RunScript(... List<GeometryBase> objects, ...)
I’m not fluent enough in the dark sayings of .NET to know how to do the type casting of the VB Object to a list, or, to extract the correct type from the list of Breps in the param objects As Object
You need to right click the ‘objects’ input, and change it to ‘list access’ since this is a list of objects in the block.
One subtle aspect to the scripting components are how the inputs are defined. For reach input, one should specify their type (type hints) and their list access (is this one thing, multiple things, or a data tree?). All of this is done by right-clicking the input.
Edit: Changing to List item was OK but didn’t do away with the problem. But when I set the Type hint to GeometryBase for the objects parameter, then it started to work as expected!