I want to use python to convert brep or subd to mesh, I haven’t found a suitable api so far, I think I prefer to use RhinoScriptSyntax api but there is no such method as “onmesh()” in this api, there seems to be such method in rhinocommon, But rhinocommon is obscure and I’m not very good at using it. Can anyone provide a start or a hint? Thanks
Hi @tom33,
Have a look at this:
https://developer.rhino3d.com/api/rhinocommon/rhino.docobjects.rhinoobject/meshobjects
– Dale
1 Like
Sir, I’m not sure what I should do next
import Rhino as rh
from Rhino.Input.Custom import *
from Rhino.DocObjects import ObjectType
from Rhino.Geometry import *
from Rhino.Commands import Result
def RunCommand():
gm = rh.Input.Custom.GetObject()
gm.SetCommandPrompt("Select")
gm.GeometryFilter = ObjectType.AnyObject
gm.GeometryAttributeFilter = GeometryAttributeFilter.ClosedMesh
gm.SubObjectSelect = False
gm.GroupSelect = True
gm.GetMultiple(1, 0)
if gm.CommandResult() != Result.Success:
return gm.CommandResult()
go = RunCommand()
rt = rh.DocObjects.RhinoObject.MeshObjects(go)
Hi @tom33,
Try this:
#! python 3
import Rhino
import scriptcontext as sc
import System
def __MeshableTypes():
types = Rhino.DocObjects.ObjectType.Surface
types = types | Rhino.DocObjects.ObjectType.PolysrfFilter
types = types | Rhino.DocObjects.ObjectType.Extrusion
types = types | Rhino.DocObjects.ObjectType.SubD
return types
def TestTom():
rc, objrefs = Rhino.Input.RhinoGet.GetMultipleObjects("Select objects to mesh", False, __MeshableTypes())
if rc != Rhino.Commands.Result.Success:
return
in_objects = []
for objref in objrefs:
in_objects.append(objref.Object())
mp = Rhino.Geometry.MeshingParameters.DocumentCurrentSetting(sc.doc)
rc, meshes, attributes = Rhino.DocObjects.RhinoObject.MeshObjects(in_objects, mp)
if rc == Rhino.Commands.Result.Success:
for i in range(0, len(meshes)):
id = sc.doc.Objects.AddMesh(meshes[i], attributes[i])
if id != System.Guid.Empty:
sc.doc.Objects.Select(id, True, True, True)
sc.doc.Views.Redraw()
if __name__ == "__main__":
TestTom()
– Dale
1 Like
This is useful Sir. Thank you very much. One problem is that the scriptcontext module does not seem to be explained in the api on the official website
Here is the source code:
– Dale
1 Like