I cannot really help you, however. I am facing the same problem. I am trying to acces the Open File Dialog from System.Windows.Forms in this manner. Because I had no luck trying to acces the RevitAPIUI File Dialog.
I managed to only acces the Task Dialog through the RevitAPIUI by copy pasting this code
import clr
#acces RevitAPI and RevitAPIUI
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
#acces all name-spaces
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import *
from Autodesk.Revit.DB.Analysis import *
from Autodesk.Revit.UI import TaskDialog, TaskDialogCommonButtons, TaskDialogCommandLinkId, TaskDialogResult
title = 'Test'
dialog = TaskDialog(title)
dialog.MainInstruction = 'Hallo'
dialog.MainContent = 'Text Content'
dialog.FooterText = 'Footer text'
dialog.VerificationText = 'Verification text'
dialog.TitleAutoPrefix = False
dialog.AllowCancellation = True
dialog.CommonButtons = TaskDialogCommonButtons.Ok
dialog.DefaultButton = TaskDialogResult.None
dialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, 'Command button text','command button sub text')
dialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, 'Command button text2', 'command button sub text 2')
result = dialog.Show()
It worked great, I could acces the TaskDialog through Python Dynamo as this image shows:
However, I want to acces the FileOpenDialog instead of a Dialog. If I give in a FileOpenDialog
in this code and type FileOpenDialog.Show().
It says I need to pass an argument into Show()
. No idea what argument I should pass. So I resorted to Winforms and copy pasted a file open dialog from the tutorial website. Which is this code;
#!/usr/bin/ipy
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Application, Form, StatusBar
from System.Windows.Forms import ToolBar, ToolBarButton, FolderBrowserDialog
from System.Windows.Forms import DialogResult
class IForm(Form):
def __init__(self):
self.Text = "FolderBrowserDialog"
toolbar = ToolBar()
toolbar.Parent = self
openb = ToolBarButton()
self.statusbar = StatusBar()
self.statusbar.Parent = self
toolbar.Buttons.Add(openb)
toolbar.ButtonClick += self.OnClicked
self.CenterToScreen()
def OnClicked(self, sender, event):
dialog = FolderBrowserDialog()
if (dialog.ShowDialog(self) == DialogResult.OK):
self.statusbar.Text = dialog.SelectedPath
Application.Run(IForm())
This however does not give me the same preview like it does on their website. It returns this instead;
While it should look like this :
When I copy pasted this code I finally got an OpenFileDialog. My aim is to let the user open an excel file through Dynamo;
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Application, Form, TextBox
from System.Windows.Forms import ToolBar, ToolBarButton, OpenFileDialog
from System.Windows.Forms import DialogResult, ScrollBars, DockStyle
class IForm(Form):
def __init__(self):
self.Text = "OpenDialog"
toolbar = ToolBar()
toolbar.Parent = self
openb = ToolBarButton()
self.textbox = TextBox()
self.textbox.Parent = self
self.textbox.Multiline = True
self.textbox.ScrollBars = ScrollBars.Both
self.textbox.WordWrap = False
self.textbox.Parent = self
self.textbox.Dock = DockStyle.Fill
toolbar.Buttons.Add(openb)
toolbar.ButtonClick += self.OnClicked
self.CenterToScreen()
def OnClicked(self, sender, event):
dialog = OpenFileDialog()
dialog.Filter = "Excel files (*.xlsx)|*.xlsx"
if dialog.ShowDialog(self) == DialogResult.OK:
f = open(dialog.FileName)
data = f.read()
f.close()
self.textbox.Text = data
Application.Run(IForm())
It looked like this and it worked, I am on Windows 10.