I’m currently trying to export selected objects to iges files from python, which we have previously done successfully with rhino6. However, now I can’t get the old method to work, and my attempt to use RhinoDoc.ExportSelected fails. Any tips would be greatly appreciated. My code is shown below.
from rhinoscript import rhinoscriptsyntax as rs
rhinofile = 'model.3dm'
rs.scriptcontext.open(rhinofile)
# Gather objects
objs = {}
guids = rs.ObjectsByType(rs.filter.surface +
rs.filter.polysurface +
rs.filter.extrusion)
for guid in guids:
obj = rs.coercerhinoobject(guid)
if obj.Name:
if obj.Name not in objs:
objs[obj.Name] = [obj]
else:
objs[obj.Name].append(obj)
# Export
for key, val in objs.items():
rs.SelectObjects(val)
# This worked previously with Rhino6 but returns False now :
rs.Command(f'-Export "{os.path.abspath(key)}.iges" Enter')
# Tried this for Rhino7 but with error "TypeError: No method matches given arguments for ExportSelected: ()" :
rs.Rhino.RhinoDoc.ExportSelected(rs.System.String(f'{key}.iges'))
rs.UnselectAllObjects()
Does the scripted Export command work for you in regular Rhino Python in Rhino 7?
FWIW I tested a slightly adapted version of your script in Rhino 7:
import rhinoscriptsyntax as rs
import os
# Gather objects
objs = {}
guids = rs.ObjectsByType(rs.filter.surface +
rs.filter.polysurface +
rs.filter.extrusion)
for guid in guids:
obj = rs.coercerhinoobject(guid)
if obj.Name:
if obj.Name not in objs:
objs[obj.Name] = [obj]
else:
objs[obj.Name].append(obj)
# Export
for key, val in objs.items():
rs.SelectObjects(val)
rs.Command('-Export "' + os.path.abspath(key) + '.iges" Enter')
rs.UnselectAllObjects()
In a new file with just a Torus added it exports just fine.