pyRevit

Code
Library
WPF Template
# -*- coding: utf-8 -*-
__title__ = "WPF Tempalte"
__doc__ = """Version = 1.0
Date = 25.11.2024
________________________________________________________________
Description:
Create WPF Forms by asking Chat GPT.
________________________________________________________________
Author: Erik Frits"""
# ╦╔╦╗╔═╗╔═╗╦═╗╔╦╗╔═╗
# ║║║║╠═╝║ ║╠╦╝ ║ ╚═╗
# ╩╩ ╩╩ ╚═╝╩╚═ ╩ ╚═╝ IMPORTS
#====================================================================================================
from Autodesk.Revit.DB import *
from pyrevit import forms # By importing forms you also get references to WPF package! IT'S Very IMPORTANT !!!
import wpf, os, clr # wpf can be imported only after pyrevit.forms!
# .NET Imports
clr.AddReference("System")
from System.Windows import Window, ResourceDictionary
from System.Windows.Controls import CheckBox, Button, TextBox, ListBoxItem
# ╦ ╦╔═╗╦═╗╦╔═╗╔╗ ╦ ╔═╗╔═╗
# ╚╗╔╝╠═╣╠╦╝║╠═╣╠╩╗║ ║╣ ╚═╗
# ╚╝ ╩ ╩╩╚═╩╩ ╩╚═╝╩═╝╚═╝╚═╝ VARIABLES
#====================================================================================================
PATH_SCRIPT = os.path.dirname(__file__)
doc = __revit__.ActiveUIDocument.Document #type: Document
uidoc = __revit__.ActiveUIDocument
app = __revit__.Application
# ╔╦╗╔═╗╦╔╗╔ ╔═╗╔═╗╦═╗╔╦╗
# ║║║╠═╣║║║║ ╠╣ ║ ║╠╦╝║║║
# ╩ ╩╩ ╩╩╝╚╝ ╚ ╚═╝╩╚═╩ ╩ MAIN FORM
#====================================================================================================
# Inherit .NET Window for your UI Form
PATH_SCRIPT = os.path.dirname(__file__)
from Autodesk.Revit.DB import View, ViewSheet, FilteredElementCollector
from System.Windows.Controls import CheckBox, ListBoxItem
# -*- coding: utf-8 -*-
__title__ = "5.1 - AI: Text To Form"
__doc__ = """Version = 1.0
Date = 25.11.2024
________________________________________________________________
Description:
Create WPF Forms by asking Chat GPT.
________________________________________________________________
Author: Erik Frits"""
# Imports
from Autodesk.Revit.DB import *
from pyrevit import forms
import wpf, os, clr
clr.AddReference("System")
import System
from System.Windows import MessageBox, Window
from System.Windows.Controls import ListBoxItem,ComboBoxItem, TextBlock
from System.Windows import Visibility
# Variables
PATH_SCRIPT = os.path.dirname(__file__)
doc = __revit__.ActiveUIDocument.Document
class MyForm(Window):
def __init__(self):
# Load XAML
path_xaml_file = os.path.join(PATH_SCRIPT, 'MyForm.xaml')
wpf.LoadComponent(self, path_xaml_file)
# Show the Form
self.ShowDialog()
# Show form
UI = MyForm()

⌨️ Happy Coding!
Erik Frits