Hi everyone!
I am having a bit of an issue using the Design Automation API from APS to connect my app. I am well aware that using references to the RevitAPIUI shouldn't be done but my app is built in a way that I can't afford removing that reference from the entire project. In the method that is being automated using APS I do not call any method from the RevitAPIUI but my project does reference to it.
What can I do to solve this? Copying local the dll of the RevitAPIUI could help? Any leads would be very helpful.
Utterly, completely, unworkaroundably impossible. Sorry. You will have to eliminate all UI API usage to run on APS DA.
I'm pretty sure you can have the reference RevitAPIUI inside your assembly but in your Design Automation code, you cannot use it.
This means if you have a class that uses the namespace Autodesk.Revit.UI, that class gonna request the application (Design Automation) to load the assembly RevitAPIUI file on runtime throwing an exception. If you never instantiate that class in your main Design Automation code everything gonna run smoothly.
The trick part is to ensure no class from Autodesk.Revit.UI is used in runtime.
Yes, absolutely.
@ricaun wrote:The trick part is to ensure no class from Autodesk.Revit.UI is used in runtime.
@ricaun That is 100% correct. However, it is still possible for a class to reference Autodesk.Revit.UI provided those references are not used at runtime. I've encountered the same issue when writing components for WinForms, the designer crashes when I insert my component if it tries to use anything from the Revit API.
For a class to be usable by APS but still reference Autodesk.Revit.UI, there are some heavy restrictions it needs to follow.
It is possible to somewhat get around restrictions 1 and 2 by making the field/parameter of type object and casting it to the correct type whenever it is used. However, restriction 3 must still be followed: any method that casts the field/parameter to its actual type must not be called from Design Automation.
TLDR summary:
DA4R: referencing UI is OK, just make sure you don't call it!
Can't find what you're looking for? Ask the community or share your knowledge.