Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 4141

Extrusion and other types of Brep like geometries conversion to Brep

$
0
0

Instead of doing the if statement below is it possible to cast rhino_obj.Geometry to brep in one single line?
Breps can be extrusions and other types, but regardless of the sub-types I want to have only
brep types.

      if rhino_obj:
          if rhino_obj.Geometry and isinstance(rhino_obj.Geometry, Rhino.Geometry.Brep):
              selected_breps.append(rhino_obj.Geometry)
          elif rhino_obj.Geometry:
              selected_breps.append(rhino_obj.Geometry.ToBrep())

full code:

def handle_brep_input(option_name: str, hide : bool = True) -> list[Rhino.Geometry.Brep]:
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt(f"Select {option_name}")
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep  # Filter to curves
    go.EnablePreSelect(True, True)
    go.SubObjectSelect = False
    go.DeselectAllBeforePostSelect = False
    res = go.GetMultiple(1, 0)

    if go.CommandResult() == Rhino.Commands.Result.Success:
        selected_breps = []
        for i in range(go.ObjectCount):
            rhino_obj = go.Object(i).Object()  # Get the RhinoObject

            if hide:
                Rhino.RhinoDoc.ActiveDoc.Objects.Hide(rhino_obj.Id, True)
                
            if rhino_obj:
                if rhino_obj.Geometry and isinstance(rhino_obj.Geometry, Rhino.Geometry.Brep):
                    selected_breps.append(rhino_obj.Geometry)
                elif rhino_obj.Geometry:
                    selected_breps.append(rhino_obj.Geometry.ToBrep())

        Rhino.RhinoDoc.ActiveDoc.Views.Redraw()  # Refresh view after hiding objects
        return selected_breps
    return []

3 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 4141

Trending Articles