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: 

How to call Execute in class using RevitApi in WPF

6 REPLIES 6
Reply
Message 1 of 7
roma_petrovich_2023
946 Views, 6 Replies

How to call Execute in class using RevitApi in WPF

I have a class containing functionality that works with Revit, I need to bind to a button on a WPF form, an action that would launch a class that works with Revit. I am new to this, so I would like a detailed answer with a code example. I have already read many forums, but did not find the answer.

6 REPLIES 6
Message 2 of 7

You cannot call Execute yourself. The Revit external command Execute method is an event handler defined by the IExternalCommand interface and implemented by your external command:

  

https://www.revitapidocs.com/2023/ad99887e-db50-bf8f-e4e6-2fb86082b5fb.htm

  

It is only called by Revit itself, not by your, your add-in, or any other client.

 

How to implement an external command is discussed and explained in full detail in the getting started material, the Revit developer guide hello world samples, the My First Revit Plug-In tutorial video, many other YouTube tutorial videos, and numerous other places. Why should it be repeated yet again?

  

https://thebuildingcoder.typepad.com/blog/about-the-author.html#2

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 7

Hi @roma_petrovich_2023,

 

Please note that Revit API can only be used within a valid Revit API context. ExternalEvent allows you to do just that.

You can find a 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.

 

You can also find WPF tutorials with Revit on YouTube. Here are a few samples you can refer:

https://www.youtube.com/watch?v=vHsqxRAqQOg

https://www.youtube.com/watch?v=KHMwd4U_Lrs

 

  Moturi George,     Developer Advocacy and Support,  ADN Open
Message 4 of 7

Dear Roma,

If you have WPF form specifically modeless one and need to call Revit API on button click you can use ExternalEvent and raise it on button click. Progress bar example that I added today contains what you need I guess. Please find it in the link below:
https://forums.autodesk.com/t5/revit-api-forum/can-anyone-share-a-working-implementation-of-wpf-prog...

 

Cheers - Marek

Message 5 of 7
Organon
in reply to: Songohu_85

@Songohu_85,

 

Hi,

 

How did you manage to manipulate WPFs in the Macro Manager? Everytime I try it SharpDevelop crashes.

 

Regards, 


Arquitectura | Análisis CAD & BIM | Diseño Paramétrico | Programación
BIM-METADATA | LinkedIn | YouTube
Message 6 of 7
Songohu_85
in reply to: Organon

Hi, I remember that it crashed after switching back to code view from design view. In my Revit 2023 design view doesn't work at all so problem solved 😀

 

I wouldn't go into writing more complexed xaml in macro manager but this example could be done without preview.

Message 7 of 7
Organon
in reply to: Songohu_85

@Songohu_85,

 

Okay, thanks.

 

Regards,


Arquitectura | Análisis CAD & BIM | Diseño Paramétrico | Programación
BIM-METADATA | LinkedIn | YouTube

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

Post to forums  

Forma Design Contest


Rail Community