Rs.OpenFileName, rs.SaveFileName


#1

…these functions actually do neither open nor save files. Which functions do?
I need to open multiple dxf files and save them as rhino files, tried to write a script
Thanks in advance for help


#2

They give you the complete file path and name so that you can script it with rs.Command() something like:

rs.Command("-_Open "+filepathname)  (or _Import)

or

rs.Command("-_Save "+filepathname) (or _Export)

HTH, --Mitch


#3

Thanks for prompt. It works; howevwer in loop of over thousand files I would like to omit the Open file window for each one.

for nazwa in elementy:
#otworz = nazwa+".dxf" this does not work
otworz = rs.OpenFileName(“Open”, “dxf format |.dxf||", None, nazwa, “3dm”)
rs.Command ("-open "+otworz)
#zapisz = rs.SaveFileName(“Save”, "rhino format |
.3dm||”, None, nazwa, “3dm”)
rs.Command ("-save "+nazwa)


#4

Use the dash version of -Open to bypass the dialog, sorry I did not type the dash in my sample (corrected)…

–Mitch


#5

Thanks for quick reply,
I do (in rs.Command), see fourth and sixth line of code above.
rs.OpenFilename invokes dialog for each file.
I tried second line of code instead of third, but all saved files were the same, as first opened file.
Code as above gives good saved files, but Open dialog appears before every opened file


#6

OK, I didn’t understand… If you don’t want the Open file dialog, don’t use OpenFileName()… It’s purpose is to bring up the dialog… :smile:

If you’re trying to batch open files, you’re going to need to first get a folder - either with rs.BrowseForFolder() or just hard code the folder path as a string if you know its location. Then you will need to iterate through all the files in that folder. You will need to import python’s os module to access the appropriate file operations. Something like:

for filename in os.listdir(folder):
    if filename.endswith(".dxf"):
            fullpath=os.path.join(folder,filename).lower()
            rs.Command("_-Open "+chr(34)+fullpath+chr(34)+" _Enter _Enter", False)
            # do your stuff...

This is off the top of my head - I think you need the second “Enter” to accept the default open options for .dxf files. If it’s .3dm files you’re opening, you don’t need it…

–Mitch


#7

Thanks for effort to find code.
As the time for exploring came to end, and the work had to be done, I found a compromise with code as follows:

for nazwa in elementy:
otworz = rs.OpenFileName(“Open”, “dxf format |*.dxf||”, None, nazwa, “3dm”)
rs.Command ("-open “+otworz+” Enter")
rs.Command ("-save "+nazwa)

It requires one Enter hit per one file; acceptable compared to three keystrokes needed before (your tip with " Enter", line 3, helped).
At more leisure time I’ll look into code using OS module, it needs some learning on my side.
Finally, thanks for help


#8

Thanks for effort to find code.

As the time for exploring came to end, and the work had to be done, I found a compromise with code as follows:

for nazwa in elementy:

otworz = rs.OpenFileName("Open", "dxf format |*.dxf||", None, nazwa, "3dm")

rs.Command ("-open "+otworz+" Enter")

rs.Command ("-save "+nazwa)

It requires one Enter hit per one file; acceptable compared to three keystrokes needed before (your tip with " Enter", line 3, helped).

At more leisure time I’ll look into code using OS module, it needs some learning on my side.

Finally, thanks for help