So I'm just starting to dip my toes into WPF in pyRevit. I tried to implement the pyrevit.forms.WPFWindow Class like this:
# -*- coding: UTF-8 -*-
"""
Third-Party software credits:
pyRevit: repository at https://github.com/eirannejad/pyRevit
"""
import System, clr, json, sys
clr.AddReference("System.Windows.Forms")
clr.AddReference('IronPython.Wpf')
import wpf
from Autodesk.Revit.DB import *
from pyrevit import revit, script, forms
class FactorySettings(forms.WPFWindow):
def __init__(self):
forms.WPFWindow.__init__(self, script.get_bundle_file('settings.xaml'))
def something_click(self, A, B):
plantings = FilteredElementCollector(revit.doc) \
.WhereElementIsElementType() \
.OfCategory(BuiltInCategory.OST_Planting)
ui = FactorySettings()
ui.show()
This is my xaml:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:Collections="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
ShowInTaskbar="False" ResizeMode="CanResize"
WindowStartupLocation="CenterScreen"
HorizontalContentAlignment="Center"
Title="Set worksets" Width="300" SizeToContent="Height"
>
<StackPanel Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Button Content="Do something" Name="something" Click="something_click"/>
</StackPanel>
</Window>
This will open a non-modal window because of the def show(self, modal=False):
class-function.
The problem for me is that even though my click-function only calls a FilteredElementCollector
object, Revit crashes. If I do ui.show(modal=True)
it will work, but then I can't do anything in Revit UI.
What I really wanted was to do this:
def something_click(self, A, B):
if self.PHfamSymbol != None:
with forms.WarningBar(title='Place an instance of the placeholder object.'):
revit.uidoc.PromptForFamilyInstancePlacement(self.PHfamSymbol)
That will not work because the focus is still on the UI. I tried this:
def something_click(self, A, B):
if self.PHfamSymbol != None:
self.Close()
with forms.WarningBar(title='Place an instance of the placeholder object.'):
try:
revit.uidoc.PromptForFamilyInstancePlacement(self.PHfamSymbol)
except:
pass
This works, but I need to create a new instance of the UI after completing. Is it possible at all to have a non modal UI with pyRevit?