Hi there,
I want to export the contents of a layer as a STEP file, preserving the colours and object names. I have adapted the script below which I found elsewhere on the forums. It works fine, except that it doesn’t preserve the object names, and instead creates new ones. Is there an option somewhere I need to change which will resolve this?
import rhinoscriptsyntax as rs
import scriptcontext as sc
import os
import Rhino
sc.doc = Rhino.RhinoDoc.ActiveDoc
def SelectObjectTypes(objs):
for obj in objs:
otype=rs.ObjectType(obj)
if otype==1 or otype==4 or otype==8 or otype==16:
rs.SelectObject(obj)
def BatchExportSATByLayer():
doc_name=sc.doc.Name
ft="STP"
filt = "{} Files (*.{})|*.{}||".format(ft,ft.lower(),ft.lower())
if not doc_name:
#document hasn't been saved
msg="Main file name/folder for {} export?".format(ft)
filename=rs.SaveFileName(msg, filt)
#SaveFileName returns the complete path plus file name
if filename==None: return
else:
#document has been saved, get path
msg="Folder for {} export? (Enter to save in current folder)".format(ft)
folder = rs.BrowseForFolder(rs.WorkingFolder(), msg)
if not folder: return
filename=os.path.join(folder,doc_name)
#start the export sequence
rs.EnableRedraw(False)
layers=rs.LayerNames()
layer="Export"
if rs.IsLayerSelectable(layer):
#need to check for sublayers in name and replace "::"
layer_name=layer.replace("::","_")
e_file_name = '"{}-{}.{}" '.format(filename[:-4],layer_name,ft.lower())
rs.UnselectAllObjects()
objs=rs.ObjectsByLayer(layer, False)
SelectObjectTypes(objs)
if rs.SelectedObjects():
#runs the export using the file name/path and your settings
rs.Command("-_Export "+e_file_name+" _Enter", False)
rs.EnableRedraw(True)
if Run:
BatchExportSATByLayer()
sc.doc = ghdoc