Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Revit Design Automation API using the reference to RevitAPIUI

8 REPLIES 8
Reply
Message 1 of 9
josepht21
544 Views, 8 Replies

Revit Design Automation API using the reference to RevitAPIUI

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 

Tags (3)
Labels (3)
8 REPLIES 8
Message 2 of 9
jeremy_tammik
in reply to: josepht21

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
Message 3 of 9
josepht21
in reply to: jeremy_tammik

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

Message 4 of 9
ricaun
in reply to: josepht21

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

Message 5 of 9
jeremy_tammik
in reply to: ricaun

Yes, absolutely.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 6 of 9
josepht21
in reply to: ricaun

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?
Message 7 of 9
mhannonQ65N2
in reply to: ricaun




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

Message 8 of 9
josepht21
in reply to: mhannonQ65N2

Amazing! Thanks
Message 9 of 9
jeremy_tammik
in reply to: josepht21

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report