Python winforms folder browser dialog

Hi guys,

I need some help cracking this…

I can’t get this python code to pass the folder directory out as a string.

Any ideas?

Python%20error

Code:
indent preformatted text by 4 spaces
import clr
clr.AddReference(“System.Windows.Forms”)
clr.AddReference(“System.Drawing”)

from System.Windows.Forms import Application, Button, Form, Label, TextBox, CheckBox, FolderBrowserDialog, OpenFileDialog, DialogResult, ComboBox, FormBorderStyle

clr.AddReference(‘RevitAPI’)
clr.AddReference(‘RevitAPIUI’)
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

mpath =

dialog = FolderBrowserDialog()

if (dialog.ShowDialog() == DialogResult.OK):
mpath.Text = dialog.SelectedPath()

OUT = mpath

Hey Simon!

		dialog= FolderBrowserDialog()
		dr = dialog.ShowDialog()
		if dr == DialogResult.OK:
			mpath.Text = dialog.SelectedPath()
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")

from System.Windows.Forms import Application, Button, Form, Label, TextBox, CheckBox, FolderBrowserDialog, OpenFileDialog, DialogResult, ComboBox, FormBorderStyle

clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

mpath = ""

dialog = FolderBrowserDialog()

if (dialog.ShowDialog() == DialogResult.OK):
mpath = dialog.SelectedPath

OUT = mpath

Hi @Mostafa_El_Ayoubi,

Thanks for your rapid answer!

I have posted the final result as we managed to figure it out :wink:

By the way (we need three Python T-shirts)

1 Like

:joy: DM me your address