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"
    rs.Command(commandString)

Thanks!!

Hi

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)
    
    rs.SelectObject(obj)
    command_string = '-_Export "{}" _Enter _Enter'.format(full_filepath)
    rs.Command(command_string)
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)
BatchExportSTLByObjWFixedSettingsPlus.py (1.9 KB)

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

2 Likes