Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

REVIT 2022 crashes after an external function call for a WPF window class

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
jerome.leignadier
358 Views, 4 Replies

REVIT 2022 crashes after an external function call for a WPF window class

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...

plantage REVIT-WPF.PNG

 

Please help ! :'(

4 REPLIES 4
Message 2 of 5

Hi @jerome.leignadier,

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

Carol Gitonga, Developer Advocacy and Support, ADN Open
Message 3 of 5

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 ?

Message 4 of 5

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

Message 5 of 5

I find the solution : Lesson 10. WPF forms. User Interface 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community