BrowseForFolder alternative for more efficient browsing?

BrowseForFolder creates this window with a limited interface to browse for a location. Is there an alternative in Python to get a window with better options for browsing to a folder location? Like, for example the browse window you get when you use ViewCaptureToFile.

Hi @siemen,

What you see is the Windows-standard folder picker. The dialog displayed by ViewCaptureToFile is the Windows-standard file picker. Now, there may some way to configure a OpenFileDialog class object to allow you to pick a folder. You’d need to do some Googling on this.

That said, the Microsoft.WindowsAPICodePack does include a dialog, similar to the Windows-standard file open dialog, that picks folders. Rhino 5 includes the Microsoft.WindowsAPICodePack, so referencing it isn’t too difficult.

import Rhino
import clr
import sys
sys.path.append(r'C:\Program Files\Rhinoceros 5 (64-bit)\System')
import Microsoft.WindowsAPICodePack.Dialogs as msdlg

dialog = msdlg.CommonOpenFileDialog()
dialog.InitialDirectory = Rhino.ApplicationSettings.FileSettings.WorkingFolder
dialog.IsFolderPicker = True
if (dialog.ShowDialog() == msdlg.CommonFileDialogResult.Ok):
    print dialog.FileName

Note, Rhino 6 does not include the Microsoft.WindowsAPICodePack. Thus, you will need to download it and put someplace that your scripts can reference.

– Dale


You could also use System.Windows.Forms.FolderBrowserDialog() which doesn’t require extra dependencies and works on both Windows and Mac:

from System.Windows.Forms import DialogResult, FolderBrowserDialog

fbd = FolderBrowserDialog()
dialog_result = fbd.ShowDialog()
if dialog_result == DialogResult.OK:
    print fbd.SelectedPath

@qythium, but isn’t this what rs.BrowseForFolder uses ?


Whoops, my mistake - I had tested it on a Mac and it looked so significantly different from the above screenshot I assumed it was another interface altogether

@qythium it is cool though to know this works on Mac which i have not expected :wink:


Another cross-platform solution using Eto :slight_smile: :

import clr
import Eto
folder_diag = Eto.Forms.SelectFolderDialog()
print folder_diag.Directory

Thanks Dale for your reply.

As a workaround for Rhino6 (without having to download anything), Would it be possible to somehow run the ViewCaptureToFile command, browse for the folder location without completing the command and then retrieve that chosen folder for batch exporting? (or batch viewcapturetofile’ing?)

Awesome, thanks!

Hi @siemen,

The ViewCaptureToFile command obtains a file name using RhinoGet.GetFileName.

– Dale

Thanks again for this qythium, this seems to work quite well. The only thing I’m wondering about is how to cancel the command using the escape key when the browse window is active? Usually, with rs.Get() methods I solve this by checking if the output is equal to none to return, but that doesn’t seem to work?

You would check for the return value of the ShowDialog() function, which returns a DialogResult similar to winforms:

if folder_dlg.ShowDialog(None) == Eto.Forms.DialogResult.Cancel:
#do something

Thanks, this works great again.
For these kind of things I just have no idea how/where to look for them so your help is much appreciated.