Hi
I try to pass info from a cliquodrome to a function handling REVIT objects (so having to be outside the WPF class)
The WFP window work fine, if I test some function inside the class, it work well to but when I call external def ...
With a basic class, no problem but with WPF ... it’s stuck 😞
here is my code :
test.xaml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="550" Width="1000" Opacity="0.8">
<Grid>
<CheckBox Content="Génie Civil" x:Name="Lot10" IsChecked="True" HorizontalAlignment="Left" Height="16" Margin="8,10,0,0" VerticalAlignment="Top" Width="100" />
<CheckBox Content="10" x:Name="ChkBox10" IsChecked="True" HorizontalAlignment="Left" Height="16" Margin="16,30,0,0" VerticalAlignment="Top" Width="50" />
<CheckBox Content="11" x:Name="ChkBox11" IsChecked="True" HorizontalAlignment="Left" Height="16" Margin="16,50,0,0" VerticalAlignment="Top" Width="50" />
<CheckBox Content="12" x:Name="ChkBox12" IsChecked="True" HorizontalAlignment="Left" Height="16" Margin="16,70,0,0" VerticalAlignment="Top" Width="50" />
<CheckBox Content="13" x:Name="ChkBox13" IsChecked="True" HorizontalAlignment="Left" Height="16" Margin="16,90,0,0" VerticalAlignment="Top" Width="50" />
<CheckBox Content="14" x:Name="ChkBox14" IsChecked="True" HorizontalAlignment="Left" Height="16" Margin="16,110,0,0" VerticalAlignment="Top" Width="50" />
<Button
Content="GO"
x:Name="BOUTTON" Click="Button_GO"
HorizontalAlignment="Left" Margin="250,450,0,0" VerticalAlignment="Top" Width="150"
/>
</Grid>
</Window>
and script.py (on pyRevit context) :
# -*- coding: utf-8 -*-
from pyrevit import forms
import os
import wpf
from System.Windows import Application, Window
def test2(data):
print "after wpf class ..."
print data
class MyWindow(Window):
def __init__(self):
wpf.LoadComponent(self, os.path.dirname(__file__) + '\\test.xaml')
def Button_GO(self, sender, e):
disciplines = []
for i in range(10, 15):
moa = eval("self.ChkBox" + str(i))
if moa.IsChecked:
disciplines.append(str(i))
print "inside wpf class"
print disciplines
test2(disciplines)
if __name__ == '__main__':
MyWindow().Show()
and...
Please help ! :'(
Solved! Go to Solution.
Solved by jerome.leignadier. Go to Solution.
The key to interacting with Revit API from outside threads is done either inside a handler of an Idling event or an External Event.You need to use an ExternalEvent to interact with Revit in a non modal windows. The ExternalEvent allows you to enter within a valid Revit API context.
Detailed explanation of driving Revit from outside can be found here:
https://thebuildingcoder.typepad.com/blog/2015/12/external-event-and-10-year-forum-anniversary.html.
To understand the concept clearly from pyRevit point of view, I would recommend you take a look at this resource specifically: https://pythoncvc.net/?p=247
Hi
Thank you for your response but ...
I have already explored these links and they have not helped me (one is in C# so the syntax difference is frozen to transpose the solution ; the other offers code that is not functional ... it is difficult to understand how to correct a code with another code that must also be corrected)
I try this one to : https://stackoverflow.com/questions/61793050/pyrevit-wpf-non-modal-trouble
but with the same result (dirty crash)
Do you have an example that works ?
Hi there,
Im not that much into Python as into C#, but having a brief look at yout problem, it sounds like casting of sender object in your events may not be correct,
Let us know whether that helped,
Best, Lukasz
Can't find what you're looking for? Ask the community or share your knowledge.