Error at export time

I do have the following script:

import rhinoscriptsyntax as rs
import os

def AutoExportWithOrigin():
    
        ids = rs.GetObjects("select objects to export", preselect =True)
        if not ids: return
        
        bb = rs.BoundingBox(ids, rs.CurrentView())
        p1 = (bb[0]+bb[6])/2
        
#        mIds = rs.MirrorObjects(ids, p1, p1 + rs.ViewCPlane().YAxis, True)
        
#        rs.UnselectAllObjects()
#        rs.SelectObjects(mIds)

        filename = rs.SaveFileName ("Export dxf", "dxf files (*.dxf)|*.dxf||",rs.DocumentPath(),os.path.splitext(rs.DocumentName())[0])


        cmdStr = "_ExportWithOrigin " + str(bb[0]) + filename + " _Enter" # orig

        rs.Command(cmdStr)
#        rs.DeleteObjects(mIds)
        
if __name__ == '__main__': AutoExportWithOrigin()

and I do try to implement an automatic file export that opens the export dialog box into the active Rhino document folder and automatically selects the .dxf file extension for export and unfortunately I do have an error:

export_error

The filename part of the script it is implemented by me, the original script was:

cmdStr = "_ExportWithOrigin " + str(bb[0]) + " _Enter"

Please can help-me somebody to fix this issue?

Hi @Cumberland,

How about something like this?

import rhinoscriptsyntax as rs

def AutoExportWithOrigin():
    ids = rs.GetObjects("Select objects to export", preselect=True, select=True)
    if ids is None: return
    
    path = rs.DocumentPath()
    name = rs.DocumentName()
    if name is None:
        name = "Untitled"
    else:
        sname = name.split(".")
        name = sname[0]
    
    fname = rs.SaveFileName("Export DXF", "AutoCAD Drawing Exchange (*.dxf)|*.dxf||", path, name)
    if fname is None: return
    
    bbox = rs.BoundingBox(ids, rs.CurrentView())
    pt = bbox[0].ToString()
    
    cmd = "_-ExportWithOrigin {0} \"{1}\" _Enter".format(pt, fname)
    rs.Command(cmd)
    
    rs.UnselectAllObjects()

if __name__ == '__main__': 
    AutoExportWithOrigin()

– Dale

1 Like

Thank you. Now it is working as expected.