RabbitMQ: connect to external application from Revit

RabbitMQ: connect to external application from Revit

longt61
Advocate Advocate
1,914 Views
9 Replies
Message 1 of 10

RabbitMQ: connect to external application from Revit

longt61
Advocate
Advocate

I am trying to connect an external application (an exe app) to Revit and vice versa in order to get some Revit element information for my app using RabbitMQ.

The idea is that I will have a producer (message sender) and a consumer (message listener) in both my external app and my custom Revit app. When the information is required, a message containing the request will be sent from the external app to the Revit app; after that, the required information will be sent from the Revit app to the external app. However, even I follow the tutorial example of RabbitMQ here , the Revit app can not create a connection for RabbitMQ, but it works perfectly fine if I create 2 separate executable apps for producer and listener.

I am at the early stage and just using localhost with default port for my apps and they only run on the same machine. What could possibly be wrong in my case? Thank you all in advance

0 Likes
Accepted solutions (2)
1,915 Views
9 Replies
Replies (9)
Message 2 of 10

jeremytammik
Autodesk
Autodesk

You say nothing at all about how you have implemented your Revit add-in, so it is impossible to answer off-hand.

 

All I can do is provide some basic information on the architecture of a Revit add-in:

 

The Revit API is entirely event driven. You cannot, ever, ever, make a call to the Revit API unless you are in a valid Revit API context. Such a context is provided by a Revit callback method, so you need to subscribe to some event and implement an event handler for it in order to be able to use the API at all. 

 

The most common event handler is made by implementing an external command and implementing its Execute method.

 

If your external RabbitMQ app is expected to drive the functionality, your only choice in the Revit API is probably to implement an external event. All you need to know about external events is discussed in The Building Coder topic group:

 

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

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 10

longt61
Advocate
Advocate

I am sorry for the lack of information. My situation is as follow:

1. I have an external WPF app and an Revit add-in app, both has a RabbitMQ producer and a RabbitMQ consumer to send and receive message from the other app.

2. During the start up of the Revit app, I implement and external event to pick some element.

3. Whenever user click on a button in my external WPF app, the WPF producer sends message to the consumer in Revit app to raise a the Revit external event.

4. After user has finished/ cancel the picking operation, the Revit producer sends a message to the WPF consumer about the picked elements data.

The problem is that both the Revit producer and consumer can not create a Connection to RabbitMQ localhost. Even if the producer and consumer are on different process, they should be able to connect to RabbitMQ and transfer data through RabbitMQ queue. I actually saw this idea implemented with an older version  of RabbitMQ (sending data for AutoCAD to Revit).

What did I possibly do wrong here? Feel free to ask for more information if it is required. Your help is much appreciated.

0 Likes
Message 4 of 10

jeremytammik
Autodesk
Autodesk

That sounds like a perfectly viable solution to me. Congratulations on the design. Sorry, no idea what might be wrong with it.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 10

longt61
Advocate
Advocate
Accepted solution

At first, I was worry about my design that there might be something I don't know about Revit API context that might cause the problem. After some debugging,  it turned out that the problem come from RabbitMQ Client it self. I get the latest version of RabbitMQ at the time (6.10) yet some method can not be found in System.Memory in the downloaded packet as shown in image below.

 

RabbitMq.png

 

Well, I guess it is time to take the problem somewhere else. Thank you for your help.

Just leave it here in case someone might need it. Any further ideas or suggestions on the matter is still appreciated.

0 Likes
Message 6 of 10

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

Revit itself uses System.Memory.dll in another version than RabbitMQ.Client does.

Revit wins...

 

 

Similar problem using CEFsharp.

https://thebuildingcoder.typepad.com/blog/2019/04/set-floor-level-and-use-ipc-for-disentanglement.ht...

 

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 7 of 10

jeremytammik
Autodesk
Autodesk

Glad to hear you are making progress with this.

 

Congratulations once again on choosing the suitable architecture to interact with the Revit API.

 

Good luck resolving this completely.

 

It would be nice to hear about the details of your final solution, once you have it up and running.

 

Thank you.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 8 of 10

longt61
Advocate
Advocate

Thank you for the helpfull information; no wonder the code did not work even though I did copy the required dlls files to the executing location of may apps. The example of the working Revit app - RabbitMQ I mentioned in my original question was from older versions (Revit 2018 and RabbitMQ 5.x I do not recall exactly).

Due to this fact, it means that my apps can not be version independent then. Do you have any further information about where these version specific dlls used by Revit ? Might be from global assembly cache (which I highly suspect since some features of Revit 2019.2 require .Net framework 4.7.2 installed) or some special other places? Might be I can down grade my RabbitMQ to an older version to match with my Revit.

 

0 Likes
Message 9 of 10

Revitalizer
Advisor
Advisor

Hi,

 

I see

 

C:\Program Files\Autodesk\Revit 2021\System.Memory.dll
C:\Program Files\Autodesk\Revit 2021\AddIns\FabricationPartBrowser\System.Memory.dll

 

Each other add-in which is loaed into Revit before your one will come with its dll versions.

 

I think you could use ILMerge to create a dll which includes both your addin's dll and its dependencies.

This may avoid dll version problems.

I didn't use it myself, I must admit. Just an idea.

 

 

Revitalizer

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 10 of 10

longt61
Advocate
Advocate

Thank you for your suggestion, but I am using an older version of Revit (2019.2) and the System.Memory.dll is no where to be found, except from the ouput of RebbitMQ of course. 

Further more, it seems that I need an alternative solution since my dll files contain Revit.APIUI.dll which is not marked as managed code. 

I really appreciate your suggestion.

0 Likes