While I was learning Revit API through SDK samples, I see there is a huge Samples folder with about 180 project files.
I thought it would be a good idea to quickly update the references of each project to the correct Revit install folder.
There is an executable included in the SDK samples folder that does this, but it did not work for me. I created a simple Python script which creates a .user file having project references directed to the Revit path.
# This simple app creates .user file corresponding to every .csproj | .vbproj
## With following text
# <?xml version="1.0" encoding="utf-8"?>
# <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
# <PropertyGroup>
# <ReferencePath>D:\Program Files\Autodesk\Revit 2018\</ReferencePath>
# </PropertyGroup>
# </Project>
# Created by moogalm(@galakar), ADN, Autodesk.
import os, shutil
import xml.etree.ElementTree as ET
revitSampleDir = input("Revit SDK Samples Folder, for E.g \"D:\\Revit2018\\Samples\" :")
userFile = revitSampleDir + "\\user.txt"
revitInstallDir = input("Revit Install Folder :")
project = ET.Element("Project", ToolsVersion="14.0", xmlns="http://schemas.microsoft.com/developer/msbuild/2003")
propertyGroup = ET.SubElement(project, "PropertyGroup")
referencePath = ET.SubElement(propertyGroup, "ReferencePath").text = revitInstallDir
tree = ET.ElementTree(project)
tree.write(userFile, encoding='utf-8', xml_declaration=True, method='xml')
for root, dirs, files in os.walk(revitSampleDir):
for filename in files:
if filename.endswith(('.csproj', '.vbproj')):
shutil.copy(userFile, os.path.join(root, filename + ".user"))
print(os.path.join(root, filename + ".user"))
This script creates a .user file for each project file it finds and writes the Revit install path into the file so Visual Studio will pick up the correct reference path.

Leave a Reply