The question of communicating from outside with Revit is popping up with increasing frequency.
Since Revit is designed as an interactive end user tool, misusing it as a server may fail and may also violate the license agreement.
Therefore, in many cases, the cleanest (or only clean) solution will involve use of the Forge Design Automation API for Revit or DA4R.
However, it is also possible to make use of Revit as a server in a limited way via an external event.
Many aspects of this have been discussed numerous times in the past in the topic group on external events for modeless access and driving Revit from outside.
However, people sometimes prefer not to read and research, not to fish, but rather ask repeated questions and be fed, so we return to this topic again (and again).
Furthermore, our new hero Igor shared a cool wrapper for external events that makes the process easier than ever before:
Async and Await External Event Wrapper
A Revit add-in can accept requests from an external source that executes outside the valid Revit API context by implementing an external event and providing a method for the external client to raise it.
This functionality can obviously also be wrapped in an async
and await
structure.
Igor Serdyukov, also known as Игорь Сердюков or WhiteSharq has implemented such a wrapper, saying:
I thought you might be interested in my small humble invention for Revit coders. I call it
RevitTask
. You can find details in the RevitTask project GitHub page. It is also available as a nuget package. It includes two samples, a minimal test and a little more interesting example project using Revit as a server and handling requests from the browser.
Communicating with Another Process
The issue of communicating with another process was also discussed back and forth a couple of times in the past few days in the Revit API discussion forum thread on Revit add-in communicating with other process:
Question: I need to write a Revit add-in (the external command) which listens to messages from other process (not from Revit itself). In other words, the Revit add-in would be the server, another process would be a client.
I tried to use async pipe to communicate with other process but the Revit add-in doesn't listen to any messages.
I think it's because of my server-side pipe in Revit is closed as soon as the Execute
method returns and terminates.
Is there any way to keep the server pipe still alive, even after the add-in's Execute
finishes?
I think I should create a thread in Execute to resolve this issue. Is this approach feasible?
I would really appreciate any example code.
Answer: Yes. Thank you for the relevant and interesting question.
The recommended approach is to implement and use an external event for this.
The external event SDK sample illustrates:
- SDK/Samples/ModelessDialog/ModelessForm_ExternalEvent/
Many related discussions and solutions are listed by The Building Coder on External Events for Modeless Access and Driving Revit from Outside.
Also check out some more recent discussions on using IPC:
- Set Floor Level and Use IPC for Disentanglement
- Scaling an Add-In for a 4K High Resolution Screen
- Integrating a Web-Based UI
- Integrating the Helix 3D Viewer with a WPF Add-In
Response: I really appreciate your prompt answer.
I'm curious about the entry point. The only way I know in order to load my customized code is by implementing an external command, You said to forget about external command. Does Revit have any other interfaces to import customised code?
Answer: Yes.
The Revit API is completely event driven.
Many (or most? or all?) of the Revit events provide a valid Revit API context.
Look at the Autodesk.Revit.DB.Events namespace.
Response: I have one more question.
From the first link you gave me on using IPC for disentanglement, I found an example code IPC_test_revit_plugin.zip.
It includes a browser project and a Revit add-in project. Is this add-in (external command) able to listen for messages from other applications until Revit is terminated?
Answer: An external command listens to one message only, and nothing else.
The only message an external command is ever interested in is the Execute
message that it implements a handler for.
The only instance that can send that message is Revit.exe.
The only time the message is sent is when Revit.exe wishes the external command to be executed.
Response: I want to develop an add-in that can be loaded in Revit that listens to messages from another process (application) as long as Revit is running. Is it possible to implement?
Answewr: Yes, using an external event.
However, Revit is not designed for that purpose and you may violate the license agreement by doing so.
For that purpose, a DA4R application may be a more appropriate choice:
Autodesk Open Positions
Autodesk is offering a number of exciting jobs in engineering positions in various parts of the world.
Two open positions in Europe right now are for software engineers in Cambridge, UK, with the following job ids:
Here are the details on those two:
- Position Overview – Do you want to be part of Autodesk’s digital transformation of manufacturing and construction? Do you want to help create a platform company by building cloud services, applications and components? Are you passionate about engaging with colleagues across the globe and working in an Agile development environment? If this sounds like you, read on! In this position, you will play an important role in the definition and development of core technologies that make up Autodesk’s manufacturing and construction products. You will use your knowledge and enthusiasm on projects covering all aspects of the software development process. You will join a Scrum team and actively contribute to the team’s success by reviewing and assessing customer problems, architecting and implementing solutions and presenting the results. You will work within a small and supportive group in Cambridge, alongside more than 1000 developers across the company, in an environment that is both challenging and rewarding.
- Responsibilities
- Prototype, implement, and maintain production cloud services and software components
- Collaborate with teams of talented engineers to design, plan, develop, refactor, test, deliver and maintain complex features within cloud-based, web and desktop components
- Interact with the product owner and product management teams to review and implement proposed designs
- Being Agile and using LEAN methodology as an active member of a Scrum team
- Collaborate using tools such as Git, JIRA, Slack and wiki pages
- Minimum Qualifications
- Knowledge of Software Engineering Processes and Practices
- A flexible and fast learner and keen to expand your skills in the world of Desktop and cloud technologies
- First or upper-second class degree in Computer Science, Mathematics, Engineering or a related technical field
- BREP modelling, mesh modelling, JavaScript, C++ 17, Node, Docker, Python, AWS, Artifactory, CMake, Jenkins, Ansible
Good luck applying for these or other opportunities that you can find in the Autodesk career site!
You can ask me for a personal referral link if you find something that you are interested in.