Button config: How to target version-based dll's based on Revit version?

Hi everyone

I’m attempting to configure a button to target a different dll based on the Revit version and my attempt so far appears to have done nothing:

  1. Create a script (named script.py) which targets the required version (this is a mockup). This is stored in the folder which defines the button:
import os
import sys

def get_revit_version():
    # This function should return the Revit version, e.g., 2022 or 2025
    # You can use the `revit` module from pyRevit to get the version
    import revit
    return revit.version

def set_assembly_path():
    revit_version = get_revit_version()
    if revit_version == 2022:
        assembly_path = r"C:\SomeLocation\SomeApp2022.dll"
    elif revit_version == 2023:
        assembly_path = r"C:\SomeLocation\SomeApp2023.dll"
    elif revit_version == 2024:
        assembly_path = r"C:\SomeLocation\SomeApp2024.dll"
    elif revit_version == 2025:
        assembly_path = r"C:\SomeLocation\SomeApp2025.dll"
    else:
        raise Exception(f"Unsupported Revit version: {revit_version}")

    # Write the assembly path to a temporary file or environment variable
    os.environ["ASSEMBLY_PATH"] = assembly_path

if __name__ == "__main__":
    set_assembly_path()
  1. The yaml:
author: ""
highlight:
assembly: ${ASSEMBLY_PATH}
command_class: LaunchCommand
  1. Import the script in startup.py:

The error when clicking the button in Revit states “The target assembly is not set correctly and cannot be loaded”

The dlls exist in the locations specified in the script. How can the problem be resolved?

2 Likes