Autodesk.Revit.UI.UIApplication
Autodesk.Revit.UI.UIApplication is a class in the Autodesk Revit API that represents a running instance of the Revit application. It provides access to various application-related objects such as documents, views, and panels, as well as methods for creating and managing them.
Properties
- ActiveUIDocument: Gets the current active document as a UIDocument object.
- Closing: Gets a boolean value indicating whether the Revit application is currently closing.
- ControlledApplication: Gets the controlling application for the current session.
- Documents: Gets a list of all open documents in the current Revit session.
- RibbonPanels: Gets a list of all ribbon panels in the current Revit session.
- Views: Gets a list of all open views in the current Revit session.
- WindowHandle: Gets the window handle for the Revit application's main window.
Methods
- CreateNewProjectDocument(templatePath: str): Creates a new project document using the specified template.
- CreateNewFamilyDocument(templatePath: str): Creates a new family document using the specified template.
- OpenAndActivateDocument(filePath: str): Opens the specified document and sets it as the active document.
- OpenSharedParameterFile(filePath: str): Opens the specified shared parameter file and adds it to the current session.
- SwitchToTaskDialogLanguage(langId: int): Changes the language used for task dialogs to the specified language ID.
- WriteJournalComment(comment: str): Writes a comment to the journal file for the current session.
Events
- DialogBoxShowing: Occurs when a dialog box is displayed in the Revit application.
- DocumentChanged: Occurs when the active document is changed.
- DocumentClosed: Occurs when a document is closed in the Revit application.
- Idling: Occurs when the Revit application is idle and ready to process further operations.
Example
new_doc = uiapp.CreateNewProjectDocument(templatePath)
uiapp.OpenAndActivateDocument(new_doc.PathName)
active_doc = uiapp.ActiveUIDocument.Document
views = uiapp.ActiveUIDocument.GetOpenUIViews()
ribbon_tab = uiapp.CreateRibbonTab("New Tab")
ribbon_panel = uiapp.CreateRibbonPanel(ribbon_tab, "New Panel")
ribbon_btn = ribbon_panel.AddItem(NewPushButtonData("New Button", "NewButton.png", "Namespace.Class.Method"))
uiapp.WriteJournalComment("Script executed successfully")
Remarks
- The UIApplication object can be accessed from within a Revit add-in using the
Revit.UI.UIApplication
property in the IExternalCommand
interface.
- The
DialogBoxShowing
event can be used to intercept and handle dialog boxes that are displayed during the execution of an add-in.
- The
Idling
event can be used to perform background processing or idle-time updates in an add-in.