Exporting STL file from Rhino V5


How may I export the stl files from rhino v5 in a way that it will carry the objects’ names over the STL file (OBJ format already does it)?

The exported files are in the form of:

solid OBJECT

endsolid OBJECT

Where I’d like OBJECT to be replaced by the object’s name assigned in Rhino.

Thanks in advance,

Hi David - as far as I know there is no provision in STL for object names as there is in OBJ.


Edit: Just noticed a related post, Export STL - object name

Hi David,

Actually there is a way, but only by using the ASCII STL format. These get big fast as they are plain text not binary, but if preserving naming is key it’s a great simple format. When reading multi-solid STLs, Rhino builds a mesh for each solid and assigns the appropriate name.

Check out the first section of this article:

Here is a simple example:

The actual STL would look like this (“multisolid.stl”):

solid Triangle01
  facet normal 0.000000000000, 0.000000000000, -1.000000000000
    outer loop
      vertex -9.778951644897, 2.685768365860, 0.000000000000
      vertex -6.060195446014, 9.847817420959, 0.000000000000
      vertex -1.928243994713, 3.856487989426, 0.000000000000
endsolid Triangle01

solid Triangle02
  facet normal 0.000000000000, 0.000000000000, -1.000000000000
    outer loop
      vertex 3.925354003906, 1.928243994713, 0.000000000000
      vertex 7.644110202789, 9.090292930603, 0.000000000000
      vertex 11.776062011719, 3.098963499069, 0.000000000000
endsolid Triangle02

solid Triangle03
  facet normal 0.000000000000, 0.000000000000, -1.000000000000
    outer loop
      vertex -3.856487989426, -6.955451488495, 0.000000000000
      vertex -0.137731716037, 0.206597566605, 0.000000000000
      vertex 3.994219779968, -5.784731864929, 0.000000000000
endsolid Triangle03

Here’s a snippet to get you started (error and bounds checking are horrible but I hope you get the idea).

def getAsciiSTLSolid(mesh, name):
    Description: Returns a text fragment for a single mesh with the given name. 
      Call this for each mesh/'solid' then join and save to a text file.
    Mesh: Rhino mesh (must be triangulated)
    Name: Name of solid in multi-solid stl.  
    indent = '  '
    tNormal = '%sfacet normal %12.12f, %12.12f, %12.12f\n'
    tVertex = '%svertex %12.12f, %12.12f, %12.12f\n'
    asciiSTL = []

    asciiSTL.append('solid %s\n' % name)
    for i in xrange(rs.MeshFaceCount(mesh)):

        fv1, fv2, fv3, fv4 = [mVerts[v] for v in fVertIndices[i]]
        asciiSTL.append(tNormal % (indent, norms[i][0], norms[i][1], norms[i][2]))
        asciiSTL.append('%souter loop\n' % (indent*2))
        asciiSTL.append(tVertex % (indent*3, fv1.X, fv1.Y, fv1.Z))
        asciiSTL.append(tVertex % (indent*3, fv2.X, fv2.Y, fv2.Z))
        asciiSTL.append(tVertex % (indent*3, fv3.X, fv3.Y, fv3.Z))
        asciiSTL.append('%sendloop\n' % (indent*2))
        asciiSTL.append('%sendfacet\n' % indent)

    asciiSTL.append('endsolid %s\n\n' % name)

    if len(asciiSTL) > 0:
        return ''.join(asciiSTL)
        return None