With the recent release of Revit 2021, you might be looking for a better way to upgrade all of your current Revit files to make them compatible with the new year. Using Revit alone, you would have open each individual Revit file in the year of Revit that you wish to upgrade it to, save it after Revit finishes upgrading it, and repeat the process until all files have been processed. Fortunately, there is no need to do this manually since Dynamo can be used to automate this process.
Start by opening any Revit file in the year of Revit that you wish to upgrade the content to. This is just so you can launch Dynamo, which is located in the Manage tab. Once Dynamo is open, you'll want to create a new file. Then make sure your mode is set to Manual rather than Automatic. You'll also need to ensure that you have the Rhythm and Clockwork packages installed to utilize all of the referenced nodes in the script below.
Start by using the Directory Path node to specify the folder location that contains the Revit files that you want to upgrade.
Then use the Directory.Contents+ node from the Clockwork package to retrieve all relevant files from the previously specified folder. Unlike the built-in node which will only find files at the folder level specified, Clockwork's node will search the directory recursively and return all relevant files contained in subfolders as well. For this example, we will be building a script to upgrade Revit family files so a Code Block can be added to ensure that it will only find files ending in ".rfa". If you are trying to upgrade other types of Revit files such as project templates or project files then this Code Block would need to be modified accordingly.
Now that it has identified and collected all of the Revit family files contained in the specified folder path, we need to tell it to open each file, save it, and then close it. The Application.OpenDocumentFile node from the Rhythm package can be utilized to accomplish the first part, opening the file. Then the Application.CloseDocument node, also from the Rhythm package, can be placed which will handle closing the file, but we are still missing a critical step in between, saving the file. We will set it to save by using the Boolean node.
Once all the nodes are placed and attached appropriately, the last thing to do is run the Dynamo script and watch the families update! This script can be saved and used in the future whenever you need to upgrade Revit families. This script also gives you the flexibility to upgrade other types of Revit files as well. If for instance you wanted to upgrade your project templates, you would replace "*.rfa" in the Code Block with "*.rte" instead.
Keep in mind that the upgraded files will be saved in the same folder path as the original family file, leaving you with the upgraded family file and also a backup family file as well. If you wanted to clean up the folder and remove the backup files saved by Revit, you could accomplish that with a separate Dynamo script. This script would start out very similar to the previous one. A combination of the Directory Path node, Directory.Contents+ node, and a Code Block will be utilized to find all of the Revit family files in the specified folder path.
We would then need to analyze the file names that are collected to determine which files are the backups. In this step we are looking at the file names, minus the file extension, to see if any include a period followed by four digits ranging in value from zero to nine.
In this last step we are filtering down our list of files to just the backup files that we found in the previous step and deleting them.
With all of those nodes linked together as shown below, you now a script that will delete any Revit family backup files in the specified folder path. Keep in mind that this script can be updated to delete backups of other Revit file types as well. To do so, you would simply replace "*.rfa" in the Code Block with the appropriate file extension.
As a final note, if you are only interested in using Dynamo to upgrade Revit family files and you don't need the flexibility to upgrade other Revit file types then this third script is for you! With only two nodes, it combines the functionality of the two previously discussed scripts. The script below will upgrade all families in the specified folder path and also delete any backup family files in that path as well. The only downside to this script is that it will only process Revit family files. Note, the Batch.UpgradeFamilies node is part of the Rhythm package as well.