Convert GeometryBase input To Brep


private void RunScript(GeometryBase geometry, ref object Result)
  {
    if (null != geometry)
      Result = geometry.GetType().ToString();
   if(Result== "Rhino.Geometry.Brep")
    Brep x = geometry;}

How does convert geometry Base To Brep Or Mesh …?

Hi
Try Brep.TryConvertBrep Method

1 Like
var brep = geometry as Brep;
1 Like

i test this method but One thing is not correct.

   if (null != geometry)
    { Result = geometry.GetType().ToString();
      if(Result == "Rhino.Geometry.Brep")
      { var x = geometry  as Brep;
        A = x;}
      else if(Result == "Rhino.Geometry.Mesh")

      { var x = geometry  as Mesh;
        A = x;}
      else if(Result == "Rhino.Geometry.SubD")
      { var x = geometry  as SubD;
        A = x;}}
    else
    {A = "input Geometry must be Brep or Mesh or SubD";}



  private void RunScript(GeometryBase geometry, ref object Result, ref object Geometry, ref object Re)
  {
    if (null != geometry)
    { Result = geometry.GetType().ToString();
      if(Result == "Rhino.Geometry.Brep")
      { var x = geometry  as Brep;


        Geometry = x.MergeCoplanarFaces(RhinoDocument.ModelAbsoluteTolerance);
        Re = Geometry;
        Geometry = x;
      }
      else if(Result == "Rhino.Geometry.Mesh")

      { var x = geometry  as Mesh;
        Geometry = x.MergeAllCoplanarFaces(RhinoDocument.ModelAbsoluteTolerance, RhinoDocument.ModelAngleToleranceRadians);
        Re = Geometry;
        Geometry = x;}
      else if(Result == "Rhino.Geometry.SubD")
      { var x = geometry  as SubD;
        subd = x.MergeAllCoplanarFaces(RhinoDocument.ModelAbsoluteTolerance, RhinoDocument.ModelAngleToleranceRadians);
        Re = Geometry;
        Geometry = x;}
      else
      {Geometry = "input Geometry must be Brep or Mesh or SubD";}}

@Mahdiyar
MergeAllCoplanarFaces+++.gh (30.6 KB)

You should click on the error-bubble and read the acutal error-messages.

convert result to an object of type “string”.
in line 75 suddendly a object “subd” appears without being initialized.
read up on what parameters the mergeallcoplanarfaces() method takes for the mesh Mesh Class and subd SubD Class

thanks i success To slove that error![aa|690x235]
and this component is MergeAllCoplanarFaces for Brep Mesh and SubD

 private void RunScript(GeometryBase geometry, bool MeshToSubd, ref object Geometry, ref object Result)
  {
    if (null != geometry)
    { string R = geometry.GetType().ToString();
      if(R == "Rhino.Geometry.Brep")
      { var x = Brep.TryConvertBrep(geometry);


        Geometry = x.MergeCoplanarFaces(RhinoDocument.ModelAbsoluteTolerance);
        Result = Geometry;
        Geometry = x;
      }
      else if(R == "Rhino.Geometry.Mesh" && MeshToSubd == false)

      { var x = geometry  as Mesh;
        Geometry = x.MergeAllCoplanarFaces(RhinoDocument.ModelAbsoluteTolerance, RhinoDocument.ModelAngleToleranceRadians);
        Result = Geometry;
        Geometry = x;}
      else if(R == "Rhino.Geometry.Mesh" && MeshToSubd)

      { var x = geometry  as Mesh;
        var y = SubD.CreateFromMesh(x);
        Geometry = y.MergeAllCoplanarFaces(RhinoDocument.ModelAbsoluteTolerance, RhinoDocument.ModelAngleToleranceRadians);
        Result = Geometry;
        Geometry = y;}
      else if((R == "Rhino.Geometry.SubD"))
      { var x = geometry  as SubD;
        Geometry = x.MergeAllCoplanarFaces(RhinoDocument.ModelAbsoluteTolerance, RhinoDocument.ModelAngleToleranceRadians);
        Result = Geometry;
        Geometry = x;}
      else
      {Geometry  = geometry;}}
  }

MergeAllCoplanarFaces+A.gh (27.5 KB)