Create folder to export files in rhino python


Hello everyone.

how can I create a folder to export different type of files in rhino python.

right at the start of the script I want to pront the user to select a location and create a folder, that folder will then be used to save the files the script will export.

it will be 2 .csv files and 1 .dwg file

I tried using rs.savefilename but that creates a file, not a folder.

at the moment I’m exporting just by using:

with open(“filename” + ‘.csv’,“w”) as f:

but this just exports the file in the same place I have the script saved.

can anyone help me out please
thanks so much

(Menno Deij - van Rijswijk) #2

To create a directory with Python, use os.mkdir
To save there, use os.path.join this will combine the directory name and the filename to an absolute path.

import os
import os.path

dir = r"C:\temp" 
if not os.path.exists(dir):

with open(os.path.join(dir, "filename"+'.csv'), "w") as f:


cool, thanks will give it a try.

I was wondering the same but wasn’t sure rhino could import os and os.path

thanks so much


nop didn’t work.

I need to ask the user to select the folder where to save the files.

but I think I can use rs.BrowseForFolder

(Menno Deij - van Rijswijk) #5

os and os.path are default in any Python distribution. So yeah, you can import them.

Python – move a mesh using pythonscript

How could I import a .stl file automatically then export after editing it (( using Python )) ?!