Revit Design Automation API using the reference to RevitAPIUI

josepht21
Enthusiast
Enthusiast

Revit Design Automation API using the reference to RevitAPIUI

josepht21
Enthusiast
Enthusiast

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.

 

 

@jeremytammik 

0 Likes
Reply
595 Views
8 Replies
Replies (8)

jeremy_tammik
Autodesk
Autodesk

Utterly, completely, unworkaroundably impossible. Sorry. You will have to eliminate all UI API usage to run on APS DA.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

josepht21
Enthusiast
Enthusiast

Hmmm not the answer I was expecting haha. Thanks anyways!

0 Likes

ricaun
Advisor
Advisor

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.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes

jeremy_tammik
Autodesk
Autodesk

Yes, absolutely.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open

josepht21
Enthusiast
Enthusiast
So just to see if I got that right. If I have a method called MyMethod in a class called A and that is the method being run (no RevitAPIUI in it) and then another class called B that does contain the RevitAPIUI as long as I don't use the class B in A I should be good?

mhannonQ65N2
Advocate
Advocate



@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.

  1. It cannot have any property or field whose type is in Autodesk.Revit.UI.
  2. It cannot have any method with a parameter whose type is in Autodesk.Revit.UI or whose return type is in Autodesk.Revit.UI.
  3. All methods called during Design Automation must not use Autodesk.Revit.UI. If a method is not called from Design Automation, it is free to use Autodesk.Revit.UI. Whenever a method uses Autodesk.Revit.UI, the runtime will attempt to resolve Autodesk.Revit.UI immediately before the method is called for the first time.

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.

josepht21
Enthusiast
Enthusiast
Amazing! Thanks
0 Likes

jeremy_tammik
Autodesk
Autodesk

TLDR summary:

  

DA4R: referencing UI is OK, just make sure you don't call it!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes