declan
(Declan Halpin)
November 27, 2018, 6:00pm
1
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!!
Willem
(Willem Derks)
November 27, 2018, 11:14pm
2
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
declan
(Declan Halpin)
November 28, 2018, 1:58pm
3
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