1

I have some Revit add-ins that are written for Revit 2019 or the versions below. Now I'm trying to upgrade the tools for Revit 2020, but it seems like there are some significant changes in API methods. Fortunately, some of them are backward compatible so I can just update the code with new API methods and use it for Revit 2020 and 2019. However, some of them only works for Revit 2020. (ex) ImageInstance.Create(Document, View, ElementId, ImagePlacementOptions)

In this case, what would be the best way to keep the same code base compatible with different Revit versions? I can easily imagine using If Statement to determine a proper API method for each Revit version, but it doesn't seem ideal for the maintenance of the tool.

Any advice would be appreciated!

Yongjoon Kim
  • 107
  • 1
  • 8

1 Answers1

1

Ive been writing and managing Addins since Revit version 2015 and use if statements to make sure things are backwards compatible. They havent gotten too out of control yet...

Its worth writing a small function to return the Revit version as a string for your if statement:

def revitVersion(): # returns '2020'
     return app.VersionName[-4:]

You can also put lists together to help check for functionality:

revitsWithoutBIM360 = ['2015', '2016', '2017', '2018']

if revitVersion() in revitsWithoutBIM360:
     print 'This version or Revit can't access BIM360 projects'
else:
     # your code here

Might not be the most elegant way to handle it, but works for me.

Callum
  • 578
  • 3
  • 8
  • Thanks so much! Yes, though I expressed a little bit of concern, your method definitely seems to be the most straightforward way to do it. I'll try it as an option! – Yongjoon Kim Apr 15 '20 at 04:48