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 []
Hi @dale, one question about all these examples: Is it expected that SubD objects are allowed to be selected if GeometryFilter does not specify them ? (I understand that Extrusion is accepted).
So far i can only prevent SubD selection if i add this ugly thing to the getter:
which can of course be an external function too. Trying something like bitwise exclusion failed here for unknown reason, it still allows srf, brep, extrusion and subd:
Hi @Petras_Vestartas, i’d do it like this using ObjRef which is what go.Objects() returns, so you can use it directly to hide and to get mesh geometry using obj_ref.Mesh() from it:
def handle_mesh_input(option_name: str, hide: bool = True) -> list[Rhino.Geometry.Mesh]:
"""Select Meshes from Rhino document."""
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt(f"Select {option_name}")
go.GeometryFilter = Rhino.DocObjects.ObjectType.Mesh
go.EnablePreSelect(True, True)
go.SubObjectSelect = False
go.DeselectAllBeforePostSelect = False
res = go.GetMultiple(1, 0)
selected_meshes = []
if go.CommandResult() == Rhino.Commands.Result.Success:
for obj_ref in go.Objects():
if hide:
Rhino.RhinoDoc.ActiveDoc.Objects.Hide(obj_ref, True)
selected_meshes.append(obj_ref.Mesh())
Rhino.RhinoDoc.ActiveDoc.Views.Redraw()
return selected_meshes
The first should give you a RhinoObject the second an ObjRef which is just a reference to it.