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.
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') clr.AddReference('Microsoft.WindowsAPICodePack.Shell.dll') 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.
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
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
Another cross-platform solution using Eto :
import clr clr.AddReferenceByName('Eto') import Eto folder_diag = Eto.Forms.SelectFolderDialog() folder_diag.ShowDialog(None) 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?)
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: return #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.