Invalid Option on STL export with rs.Command()

Hi all,

I am trying to export STL files in rs.Command() with the following code:

curDir = rs.WorkingFolder()
folderDir = curDir+'/fragments/'
os.mkdir(folderDir)
stlSettings = ' _ExportFileAs=_Binary _ExportUnfinishedObjects=_No '
stlSettings += '_UseSimpleDialog=_No _UseSimpleParameters=_No _Enter _Enter'
fragName = 'frag1'
fragId = rs.ObjectsByLayer('frag1')
rs.SelectObject(fragId)
fileName = os.path.join(folderDir, fragName+'.stl')
rs.Command('_-Export '+fileName+stlSettings)
rs.UnselectAllObjects()

However, it does not store the STL file in the folder defined in folderDir but somewhere else. In the command history it says “Invalid Option” right before it states that the file was successfully saved at the wrong directory.

What seems to be the problem? I am using Rhino 7.8.21160.05002 for Mac.

Thanks,
Simon

Slashes are escaped in Python, so I think the problem might be caused by that -

Maybe try using either

r'/fragments/'

(i.e. a ‘raw’ string)

or

'//fragments//'

(double slashes, one is escaped each time)

you can also use

os.path.join(curDir,'fragments')

to create a platform-correct path without worrying about where the slashes fall…

1 Like

Thanks, that really seemed to solve the problem :slight_smile: