Export issue from Rhino 7

Hi,

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()

Are you doing this in just regular Rhino 7, or are you using Rhino Inside a CPython script?

I’m working with cpython

Maybe I’m being dense, but I don’t see import rhinoinside anywhere.

How are you starting Rhino? And how are you using CPython in Rhino?

We’ve modified the rhinoscriptsyntax a bit to make it directly importable in cpython, and rhinoinside is loaded when we import rhinoscriptsyntax

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.

Command-line output for this:

Save file name ( Version=7  SaveSmall=No  GeometryOnly=No  SaveTextures=Yes  SaveNotes=No  SavePlugInData=Yes  Browse ): "C:\Users\Nathan\Documents\py\TestObj.iges"
IGES Export Type: Default ( ListTypes  UnitSystem=Millimeters  Tolerance=0.001 ): Enter
IGES Export Type: Default ( ListTypes  UnitSystem=Millimeters  Tolerance=0.001 )
Saved C:\Users\Nathan\Documents\py\TestObj.iges.
File successfully saved as C:\Users\Nathan\Documents\py\TestObj.iges.
Command: _CommandHistory

Thanks, I got that to work fine when running directly in rhino, so then the issue is likely somewhere in our rhinoscriptsyntax code.