Execute or raise command in Revit from another Application (WinForm) / .EXE

Execute or raise command in Revit from another Application (WinForm) / .EXE

Anonymous
Not applicable
1,727 Views
2 Replies
Message 1 of 3

Execute or raise command in Revit from another Application (WinForm) / .EXE

Anonymous
Not applicable

Hi,

 

We've been looking for a way to raise / execute a command in Revit from our application (which is a WinForm but could also be just a DLL)

 

The goal is : 

 

From Revit, we get the objects selected by the user, and we send to our own Winform the list of the IDs of the selected objects. (We want to get a value like perimeter, area, volume ...)

 

Then, in our software, we store the list of IDs (with values like area, perimetre, count ...)

 

But what we hope to do is, for our user, select back in Revit, by the list of IDs, the objects that the user would have sent from Revit (to remember to what object is associated an area, perimetre, volume ... in our application).

 

We would like, from our winform, make Revit select the objects that we have stored by IDs. For example, call a Revit API with the list of the IDs to make him select the objects associated

 

I don't know if it's understandable, or just if it is possible to realize that.

 

Thanks a lot,

 

TeamDev

0 Likes
Accepted solutions (1)
1,728 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor
Accepted solution

There have been many discussions regarding this.

 

I've in the past considered FileWatcher and Pipes but I've found recently an interesting way. I've included the solution as a zip file.

 

This may have been suggested before and I don't know of any limitations yet regarding message length etc. The mechanism included in the solution is adapted from:

https://www.codeproject.com/articles/19570/inter-process-communication-with-c

 

The mechanism:

  1. Open and hide a form during OnStartup. In that form override WndProc to receive messages
  2. In the non-revit app find the hidden window by a GUID name and send it a message
  3. Within WndProc of the form receive the message WM_COPYDATA and raise an ExternalEvent in Revit to process the message.

 

The solution contains an ExternalCommand for picking an element and sending it's ID to the non-Revit app and an ExternalApplication that receives the messages from the non-Revit app. i.e.

 

Step 1 (Revit to non-Revit):

 

200805a.png

Step 2 (non-Revit to Revit):

 

200805b.png

 

I'm sending a string but if you can send a string then perhaps you can send serialised object etc.

 

This could also be useful for running a progress bar in it's own process without having to call DoEvents.

Message 3 of 3

Anonymous
Not applicable

Thanks a lot @RPTHOMAS108  !

 

We've been looking for just the direction and you delivered us a golden gift ! 

 

It's absolutely perfect, thanks for the sample and your time !

 

TeamDev

0 Likes