Type Box not recognized

Strange, in C# ScriptComponents the following code works fine ("if (obj is Box)") but not in Visual Studio. Why is that? Inspection shows that I have a valid obejct of the right type, but the code doesn’t enter the if-block:

Edit: More of the code:

if (obj is Box)
{
    bbox = (Box)obj;
    ...
}
else if (obj is Brep)
{
    brep = (Brep)obj;
    ...

It seems I cannot read either Box or Brep with the same input (as generic object or Brep) and then cast it to either. But in the ScriptComponent this code was no problem (with input hint set to System.Object). Can you @DavidRutten (or someone else) shed some ligth on this?

// Rolf

How are you bringing the geometry in? When I had these issues I brought them in with a Geometry input and referenced them as IGH_GeometricGoo.

Hm. I had used Generic. I’ll try with IGH_GeometricGoo and see if that works better.

// Rolf

Also note that a Box could be an Extrusion object. Grasshopper usually casts these to Breps automatically since it has no internal support for extrusions.

Yes, this is one of the reasons why I handle both Box type and Brep type in the code.

It seems it works now when I changed read-type to IGH_GeometryGoo.

Perfetto!

// Rolf

1 Like