Similar code behaves different in C# and VB - How to fix?

Hi all scripters out there,

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:

C# (OK):

79   if(null == RhinoDocument.InstanceDefinitions.Find(name, true)){
80       RhinoDocument.InstanceDefinitions.Add(name, description, basePoint, objects);

VB script (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 :

What does this mean, and how can I fix the VB code?

// Rolf

Check the input typehints on both components to make sure they match.

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… :slight_smile:

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.

Edit 2:
Unfortunately the documentation doesn’t give a VB example, only C#. :

// Rolf

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


// Rolf

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.

Ah… Thanks, I’ll try that!

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! :slight_smile:

// Rolf