Create Plugin with WPF in Revit API

Create Plugin with WPF in Revit API

Ali.sadeghi.h1994
Enthusiast Enthusiast
460 Views
1 Reply
Message 1 of 2

Create Plugin with WPF in Revit API

Ali.sadeghi.h1994
Enthusiast
Enthusiast

Hi everyone.

I want to create a plugin with WPF. I have my codes to put them in plugin but I don't know how to work with WPF in Revit API, for example, I know how to define buttons but I don't know how to link my codes to a button in WPF and click on that to run my code in Revit. (notice: I have used IExternalCommand and its execute() method to run my codes)

Does anyone know a tutorial or example for this? If you know, please suggest me and tell me the address.

Thank you.

Accepted solutions (1)
461 Views
1 Reply
Reply (1)
Message 2 of 2

Omar_Amen
Advocate
Advocate
Accepted solution

Hi Ali,

If you want to execute or interact with the Revit API from WPF or even simple windows form, then I will suggest two ways to do that,

the first way:
is to make your Revit API interacting functions in your form class and make it take an instance of (ExternalCommandData) class then from it you can get the doc and uidoc objects that you will use in your function,
so when you construct the window/form instance inside the IexternalCommand execute method you have to pass the ExternalCommandData to the form constructor, then you can execute your created function from your form/WPF when a button pressed.

the second way (Recommmended) :

is using the IExternalEventHandler interface which also contains an execute function ,
and from it you can make in ExternalEvent then you can .Rise(); this event from your form/WPF once you passed the ExternalEvent instance to the form constructor
you can check this BuildingCoder link for a detailed impelementation 

Good luck,