Saving As with Spaces in the Path Name

I’m trying to save a .3dm file by using python code. To do this, I’ve done the following

    rhinoPath = os.path.join(basefilePath,rhinoFile)
    command = '-_SaveAs "{}"'.format(rhinoPath+'.3dm')
    print('RHINO PATH IS', command)
    rs.Command(command, True)

The path name has spaces in it, and wherever the first space is (in this case /Shared Drives/1- Orders), the command stops and it won’t save. I’ve tried using .format, single quotes, double quotes, attaching the .3dm, not attaching the .3dm and cannot get it to work for the life of me. Any ideas?

Hello - you need to surround the path name with double-quotes (chr(34)) This is the same as typing any text input at the Rhino command line if there are spaces in the text.

-Pascal

Should I remove the quotes around the {}?

    rhinoPath = chr(34) + rhinoPath + chr(34)
    command = '-_SaveAs {}'.format(rhinoPath)
    print('RHINO PATH IS', command)
    rs.Command(command, True)

I made this adjustment and it still didn’t save. I also tried attaching a .3dm to the rhinoPath and that didn’t work either

Hello- actually, I was wrong - your original works fine here with a file that has spaces in the name… What is the final path and file name (your print statement) that you are saving?

import rhinoscriptsyntax as rs
import os

myPath = rs.DocumentPath()
myName  = rs.DocumentName()
rhinoPath = os.path.join(myPath,myName)
command = '-_SaveAs "{}"'.format(rhinoPath)
print('RHINO PATH IS', rhinoPath)
rs.Command(command, True)

-Pascal

This is what the console is putting out:
-_SaveAs
Save file name <ContusionPad.gh> ( Version=7 SaveSmall=No GeometryOnly=No SaveTextures=Yes SavePlugInData=Yes Browse )"/Volumes/GoogleDrive/Shared drives/Product/1 - Orders/5- 2021 Clients/EXAMPLE4/JohnSmith-AB-204-02/000-ABJS-204-02.3dm"
(‘RHINO PATH IS’, ‘-_SaveAs “/Volumes/GoogleDrive/Shared drives/Product/1 - Orders/5- 2021 Clients/EXAMPLE4/JohnSmith-AB-204-02/000-ABJS-204-02.3dm”’)
Save file name <ContusionPad.gh> ( Version=7 SaveSmall=No GeometryOnly=No SaveTextures=Yes SavePlugInData=Yes Browse )

ContusionPad.gh is the name of the template grasshopper file we are using ContusionPad.3dm would be the template name for the rhino file

Hi Will - my little bit of code above gets me this from the print statement:

('RHINO PATH IS', 'G:\\My Drive\\TestingMac\\this file is just junk.3dm')

But, I am on Windows. I’ll try mac.

-Pascal

Is it actually saving in that location? Everything looks ok in mine (it’s no longer splitting at the spaces) but then I check and it’s not saved

On Windows, yes, on Mac, no, as far as I can tell…

-Pascal

Interesting, any ideas on what the discrepancy is?

Not yet - I am seeing what appear to be inconsistencies in how this works on Mac but I have not yet determined if I am being a dummy or if this is really broken.

@will10 - still poking, but on mac it may work better to use -ExportAll and not -SaveAs

@will10 - I ended up quitting and rebooting and starting a brand new session of Rhino and it seems to all work correctly now with -SaveAs so long as the file name changes.

-Pascal

1 Like

So you restarted and used save as with the code from above? (#5/11)

Hi @pascal and @will10, could it be you need forward slashes on mac instead ?

_
c.