BrowseForFolder method in Python might have a problem


#1

It seems to me that the title doesn’t work. Take a look at this:

import rhinoscriptsyntax as rs
strFolder = rs.BrowseForFolder(“C:”,“Select a folder”,“Title is broken”)

The title always is “Browse for Folder” regardless of what is entered in the third argument.

Thanks,

Dan


Rs.BrowseForFolder method doesn't change the Title
#2

Yeah, looks like this is the case, I don’t see a line where the title is set in the code below…

def BrowseForFolder(folder=None, message=None, title=None):
    """Display browse-for-folder dialog allowing the user to select a folder
    Parameters:
      folder[opt] = a default folder
      message[opt] = a prompt or message
      title[opt] = a dialog box title
    Returns:
      selected folder
      None on error
    """
    dlg = System.Windows.Forms.FolderBrowserDialog()
    if folder:
        if not isinstance(folder, str): folder = str(folder)
        dlg.SelectedPath = folder
    if message:
        if not isinstance(message, str): message = str(message)
        dlg.Description = message
    if dlg.ShowDialog()==System.Windows.Forms.DialogResult.OK:
        return dlg.SelectedPath

However, in looking at Windows Forms FolderBrowserDialog Class, I don’t see a title property to set, so I don’t know how you would do that…

–Mitch


(Dale Fugier) #3

I’ve added this to the Rhino.Python pile.

http://mcneel.myjetbrains.com/youtrack/issue/RH-28624


#4

on mac, there are some problems with the command as well.

Can’t give the dialog a custom title, message, or set a default location… i get this error when trying any of those:

Message: Object reference not set to an instance of an object

another thing is i can’t exit the script if pressing the Cancel button in the dialog whereas i can in similar functions such as rs.OpenFileName()

for example, this script will return whichever folder is highlighted in the dialog regardless of pressing Cancel or Open:

import rhinoscriptsyntax as rs

def foldername():

    folder = rs.BrowseForFolder()
    if not folder:
        return

    print folder

foldername()

other than that stuff… it works great :smile: