Use rs.command for mesh


I am trying to automatise the meshing process of a large number of polysurfaces, keeping them in their original layer, if I am using the rhinoscriptsyntax I was thinking to do something like:

for i in range(0,len(layers)):
objects = rs.ObjectsByLayer(layers[i])
rs.Command("mesh _enter _enter ")

unfortunately the _enter _enter doesn’t work with the mesh dialog box that opens and I have to manually press ok, or enter.

I tried using rhino.common instead :
obj = rs.GetObject("")

but this, although not giving an error, doesn’t generate any mesh at all.

Any idea on how to sort this out?

Many thanks in advance



You would need to use the -dash version of the command to bypass the dialog box, then you might also need to script all the command line options for mesh - there are lots…

The mesh is created (virtually) but is not added to the document - you need to do that in additional step. something like:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

objID = rs.GetObject()
mesh=Rhino.Geometry.Mesh.CreateFromBrep(obj,[meshing parameters])  #params optional
if mesh:

HTH, --Mitch

Many thanks, this works!

However I am doing a sort of similar thing now with extrusions and it doesn’t seem to work with them, any idea why?

box = rs.BoundingBox(object)
crv = rs.AddPolyline([box[0],box[1],box[2],box[3],box[0]])
vec = rs.VectorCreate(box[4],box[0])
crv = rs.coercecurve(crv)
curve = Rhino.Geometry.Extrusion.CreateExtrusion(crv,vec)
if curve:

this gives me the error “expected extursion got nurbs surface”

This is tricky, as Rhino.Geometry.Extrusion.CreateExtrusion returns a NURBS surface, not an extrusion or Brep. And this method appears to be undocumented in the Extrusion class - it is actually under Rhino.Geometry.Surface.CreateExtrusion… I will complain about that later…

So you would need this instead:

extru = Rhino.Geometry.Extrusion.CreateExtrusion(crv,vec)
extru = Rhino.Geometry.Surface.CreateExtrusion(crv,vec)

if extru: sc.doc.Objects.AddSurface(extru)
#don't forget to redraw your view to see the object

Now, this will also fail if your object is flat, as your vector will be 0… so you might need to test for that and work around.

If you want it to actually return an extrusion object, you will need to work with Rhino.Geometry.Extrusion.Create and give it a height (not a vector).

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
box = rs.BoundingBox(object)
if box:
    crv = Rhino.Geometry.PolylineCurve([box[0],box[1],box[2],box[3],box[0]])
    if ht>0:
        #True = Cap, False = No cap
        extru = Rhino.Geometry.Extrusion.Create(crv,ht,False)
        if extru:
    else: print "Unable to create extrusion, 0 height"

Yes, I was looking for extrusion and your Rhino.Geometry.Extrusion.Create(crv,ht,False) works perfectly, many thanks again.

Just out of curiosity, when the geometry is created “virtually” but not added to the document, does its data disappear when the script finishes?

Like closing a Grasshopper definition without baking an object?

Yep, exactly.