Hi everyone,
i’m trying out the xaml coding within pyrevit.
i have a simple window that has 2 buttons: selection button and confirm button.
i want the value of the selection to be passed outside of the window when the confirm button is pressed. The problem i’m having is that the the printout and dictionary already get triggerd when the window shows back up after the selection happend ( so no confirm yet).
Is it correct to take the values outside of the window proces?
Or should i just put that all under the confirm?
That just seems tricky when u start having a bigger script. seems that the confirm would trigger something outside of the window to be the most logical but i can’t really figure this step out.
below my current code:
# -*- coding: utf-8 -*-
import datetime
starttime = datetime.datetime.today()
import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('IronPython.Wpf')
import wpf
from System import Windows
from Autodesk.Revit.DB import *
from pyrevit import forms, revit, script, UI
# doc
# ===================================================
doc = revit.doc
uidoc = revit.uidoc
# definitions
# ===================================================
class MyWindow(Windows.Window):
def __init__(self, xaml_filename):
wpf.LoadComponent(self, script.get_bundle_file(xaml_filename))
@property
def element(self):
return self.element
def Confirm(self, sender, args):
self.element = self.selection
self.Close() # Close the window after Confirm button is pressed
return self.element
def Select_Wall(self, sender, args):
self.Hide()
self.selection = revit.pick_element_by_category(BuiltInCategory.OST_Walls)
if self.selection:
self.Show() # Show the window after an element is selected
# Main
# ===================================================
window = MyWindow('ui.xaml')
window.ShowDialog()
if window.element:
print(window.element)