Load Revit plugin on Legacy Revit versions

Load Revit plugin on Legacy Revit versions

mizrachi_amir2
Advocate Advocate
1,218 Views
5 Replies
Message 1 of 6

Load Revit plugin on Legacy Revit versions

mizrachi_amir2
Advocate
Advocate

Hello All,

 

I have a Revit plugin with 2 commands that are intended to run on Revit 2019 onward.

I am now working on the 3rd command, which is using the OST_Signage BuiltInCategory. This category is only available from Revit 2022 API.

How can I still load this whole plugin (with 3 commands) also to Revit 2019 so that the 3rd command will not be functional?

 

Thank you!

 

 

0 Likes
Accepted solutions (1)
1,219 Views
5 Replies
Replies (5)
Message 2 of 6

mizrachi_amir2
Advocate
Advocate

So - whoever tackles the same, I managed to overcome this using the preprocessor directives:

#if --> #else --> #endif

 

Also added this to my .csproj:

<DefineConstants>$(DefineConstants);RV$(RevitVersion)</DefineConstants>

 

This is what guided me:

https://levelup.gitconnected.com/multi-year-revit-addin-a-better-way-54ef441b5b4b

0 Likes
Message 3 of 6

nice3point
Advocate
Advocate

The approach in the article above suggests creating one project, per Revit version. This is bad advice, and I don't recommend it. With Define Constants, you can support all versions of the Revit API in a single project

 

Recommendations:

Revit Multiversion support wiki -  https://github.com/Nice3point/RevitTemplates/wiki/Multiple-Revit-Versions

Auto Define constants generation - https://github.com/Nice3point/Revit.Build.Tasks

Message 4 of 6

mizrachi_amir2
Advocate
Advocate

Thank you, @nice3point.

Actually, I used your templates so I have a single project for all versions 🙂

Message 5 of 6

nice3point
Advocate
Advocate
Accepted solution

perfect) then I have good news for you, you don't need to add DefineConstants yourself. They are already contained in the templates

nice3point_0-1713128243117.png

In your case, the only thing left to do is to wrap the code in a #if block:

#if REVIT2022_OR_GREATER
    var category = BuiltInCategory.OST_Signage;
#endif
Message 6 of 6

mizrachi_amir2
Advocate
Advocate
That is just great. Thank you very much!