How to convert surface or polysurface to mesh and save as .stl file?

hi,
What I want to do is:
S1. In Rhino

  1. get all the points data, such as coordinates, uuid
  2. get all the surface and convert them to triangle
    S2. Send all the data to server
    S3. Server do some computation
    S4. Receive the result from server, and color all the point to show the result to user

my problem is:
I don’t know how to convert surface or polysurface to triangle.

I have found that the Command “Export .stl” do the right thing I need.
then, how can I do it with Python or C#?

I try to run rs.Command("-Export test.stl").
But I can’t control the option.
I hope the result .stl file should be ascii format, not the binary one.
the demo python is like:
"_-Export %s E X _Enter _Enter D _Enter A _Enter" % (path, )
I get that E option will switch the format.
but it’s hard to know the current format.

Thanks for any help!

1 Like

First, you can mesh surfaces and polysurfaces inside Rhino without exporting with the Mesh command (rhinoscriptsyntax does not yet have the MeshObjects() method implemented). You can script it with rs.Command including all the options necessary. One way of doing it would be the following:

import rhinoscriptsyntax as rs

def MeshOptions(a,b,c,d,e,f,g,h,i,j,k):
    mo="_DetailedOptions _JaggedSeams={} _PackTextures={} ".format(a,b)
    mo+="_Refine={} _SimplePlane={} _AdvancedOptions _Angle={} ".format(c,d,e)
    mo+="_AspectRatio={} _Distance={} _Density={} _Grid={} ".format(f,g,h,i)
    mo+="_MaxEdgeLength={} _MinEdgeLength={} _Enter _Enter".format(j,k)
    return mo

msg="Select surfaces or polysurfaces to mesh"
rs.GetObjects(msg,8+16,preselect=True,select=True)
rs.Command("_-Mesh "+MeshOptions("No","Yes","Yes","Yes",0,0,0.01,0,0,0,0))
lco=rs.LastCreatedObjects()
t_meshes=[rs.MeshQuadsToTriangles(obj) for obj in lco]

You can use a similar method for exporting the object(s) as an .stl if necessary.

Let me know if this needs more clarification.

–Mitch

1 Like

Thanks very much!
That’s what I really need.
Another question is: where can I get the detail of command options for a specific command?