GH_Brep vs Brep

I’m a little confused as to why there are two classes representing Breps.

I’m coding in C# and it causes some type issues when I take in a GH_Brep from Grasshopper into my component that expects a Brep.

What’s the rationale for having two different types?

Brep is the geometry-only representation, GH_Brep is a wrapper object class that allows its use in Grasshopper. Every geometry class from Rhino has a wrapper class for Grasshopper. The Value property on the wrapper gives you the geometry-only object.

Normally, you should be able to get/set the geometry directly from/to the data input.
What problems do you run into?

1 Like

Thanks for the quick response.

I have an input in a compiled component that takes in either a Curve or Brep. Hence it uses:
pManager.AddGenericParameter()

So is an object that needs its type checked. Since such an object can be either the Rhino version or the Grasshopper version, I have to check for four types and cast accordingly.

Upstream of this compiled component is a C# script component (not a compiled component, a script) that spits out a Brep (at least I thought it did), but once I looked through it in Visual Studio it showed up as a Grasshopper.Kernel.Types.GH_Brep, which was a bit surprising.

I ended up doing if statements with casts/checks as such in the compiled component:

       if(sectionCurve is Grasshopper.Kernel.Types.GH_Curve || sectionCurve is Curve)
            {
                Curve _sectionCurve = null; 
                if (sectionCurve is Grasshopper.Kernel.Types.GH_Curve _sectionGH_Curve)
                {
                    GH_Convert.ToCurve(_sectionGH_Curve, ref _sectionCurve, GH_Conversion.Both);
                }
                else
                {
                    _sectionCurve = (Curve)sectionCurve;
                }
                // at this point, the _sectionCurve is Curve

           
            }


            if (sectionCurve is Grasshopper.Kernel.Types.GH_Brep || sectionCurve is Brep)
            {
                Brep _sectionBrep = null;
                if (sectionCurve is Grasshopper.Kernel.Types.GH_Brep _sectionGH_Brep)
                {
                    GH_Convert.ToBrep(_sectionGH_Brep, ref _sectionBrep, GH_Conversion.Both);
                }
                else
                {
                    _sectionBrep = (Brep)sectionCurve;
                }

               // at this point, the _sectionBrep is Brep

            }

You could probably try one of the methods in GH_Convert, that probably takes fewer lines of code.

https://developer.rhino3d.com/api/grasshopper/html/Methods_T_Grasshopper_Kernel_GH_Convert.htm

1 Like