I have a few Nurbs generated with rs.AddSphere in my python script and I wanted to convert them into meshes within the script. However, it does appear there is a rhinoscriptsyntax MeshToNurbs command but not the opposite NurbsToMesh.
The only work around I thought was to use the grasshopper component MeshSphere, see code below, however the spheres do not seem to appear after generated, and for example I can’t change their colour. Should I do some baking somehow?
Any alternative way to convert a nurbs to a mesh (without sampling it and running a tesselation) you can think of?
import ghpythonlib.components as comps
sp1 = rs.AddSphere(pt, 2) #not needed if I use the component below
sp = comps.MeshSphere(pt,2,3,3)
rs.ObjectColor(sp, color)
Error message: Message: iteration over non-sequence of type Mesh
Rhinoscriptsyntax is missing methods to mesh Breps directly - you need to do some RhinoCommon. In addition to the primitives that can be meshed as in @diff-arch 's post above, you can mesh generic Breps something like this:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def MeshBrep(brep_id,params):
brep=rs.coercebrep(brep_id)
if brep:
mesh=Rhino.Geometry.Mesh()
mesh_parts=Rhino.Geometry.Mesh.CreateFromBrep(brep,params)
for mesh_part in mesh_parts: mesh.Append(mesh_part)
mesh.Compact()
return mesh
def TestMeshBrep():
obj_id=rs.GetObject("Select surface or polysurface to mesh",8+16,preselect=True)
if not obj_id: return
#equivalent of 'jagged and faster'
mesh_params=Rhino.Geometry.MeshingParameters.Coarse
mesh_brep=MeshBrep(obj_id,mesh_params)
if mesh_brep:
mesh_id=sc.doc.Objects.AddMesh(mesh_brep)
sc.doc.Views.Redraw()
rs.SelectObject(mesh_id)
TestMeshBrep()