Python script to export STLs

Hi all,

Could someone help me tidy up this script to export a group of objects as individual STL files?

import rhinoscriptsyntax as rs

objects = rs.GetObjects("Select objects to export", 16)

for x in objects:
    name = rs.ObjectName(x)
    stlName = ((rs.DocumentName()).split('.')[0]) + "_" + name + ".stl"
    commandString = "-_Export " name "_Enter" + stlName + " _Enter " + "_Enter"



This is a quick setup that seems to work:

import rhinoscriptsyntax as rs
import os

objects = rs.GetObjects("Select objects to export", 16)

for obj in objects:
    name = rs.ObjectName(obj)
    stl_suffix = '_{}.stl'.format(name)
    stl_basename = rs.DocumentName().split('.')[0]
    stl_fullname = '{}{}'.format(stl_basename,stl_suffix)

    stl_path = rs.DocumentPath()
    full_filepath = os.path.join(stl_path,stl_fullname)
    command_string = '-_Export "{}" _Enter _Enter'.format(full_filepath)
1 Like

Thanks Willem! I just had to tweak “full_filepath = …” to be non-os and it works great.

thanks again.

Kinda late to the party here but here are a couple of scripts from my library just in case…

Fixed STL mesh settings (adjust in the script as you want), files are named with original file name plus a number (no object names) (1.9 KB)

Choice of 4 settings (coarse, medium, fine and extra-fine), numbered as above. (3.9 KB)