Skip to content

Instantly share code, notes, and snippets.

@ricaun
Last active May 9, 2023 11:21
Show Gist options
  • Save ricaun/200a576c3baa45cba034ceedac1e708e to your computer and use it in GitHub Desktop.
Save ricaun/200a576c3baa45cba034ceedac1e708e to your computer and use it in GitHub Desktop.
Revit Command to test the Version and Defines
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.ComponentModel;
namespace RevitAddin
{
#if DEBUG
[DisplayName("Revit\rDebug")]
#else
[DisplayName("Revit\rVersion")]
#endif
[Description("Show a Window with the Revit VersionName.")]
[Designer("/UIFrameworkRes;component/ribbon/images/revit.ico")]
[Transaction(TransactionMode.Manual)]
public class CommandVersion : IExternalCommand, IExternalCommandAvailability
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
{
UIApplication uiapp = commandData.Application;
System.Windows.MessageBox.Show(uiapp.Application.VersionName, GetRevitVersion());
return Result.Succeeded;
}
public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
{
return true;
}
public static string GetRevitVersion()
{
#if Revit2017 || REVIT2017
return "2017";
#elif Revit2018 || REVIT2018
return "2018";
#elif Revit2019 || REVIT2019
return "2019";
#elif Revit2020 || REVIT2020
return "2020";
#elif Revit2021 || REVIT2021
return "2021";
#elif Revit2022 || REVIT2022
return "2022";
#elif Revit2023 || REVIT2023
return "2023";
#elif Revit2024 || REVIT2024
return "2024";
#elif Revit2025 || REVIT2025
return "2025";
#else
return "Undefined";
#endif
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment