Last Chance To Claim LIFETIME ACCESS. [~30 Seats left]
Resources
Nov 2, 2023
Open/Reload Selected CAD Links in Revit
Are you tired of looking for your linked CAD files in Revit? Use this tool to save time by selecting DWG in Revit and then clicking on Open/Reload/Copy Path of selected DWG.
Where is Waldo? I mean CAD Link…
There are times when we work in Revit and we need to open linked DWG file. And Revit doesn't make that easy.
We can see all links in Manage Links menu, but then we have to scroll through until we find the DWG file name and we can't even copy its path… We need to look at it and follow the path in our folder structure.
And if you work on a large project there is a chance that you have a ton of links already. So it can quickly become a nightmare. I often found myself feeling like I play Where is Waldo game because it's unnecessary complicated to find your Linked DWG's filepath.
So I made a solution that can save you time and nerves to find your Linked DWG files.
How to use it?
This tool is part of EF-Tools, and it's very simple to use:
Select Linked DWG file in Revit
Click on the Button
Choose one of the 4 options
And the tool will do exactly what you selected it to do.
How does it work?
The code is written in python and executed with pyRevit. If you are interested in Revit API and want to understand how I made it work, let's break it down.
There are a few things we need to cover:
How to Select Linked DWG?
How to Open Linked DWG?
How to Open Linked DWG's Folder?
How to Reload DWG?
How to copy filepath to Clipboard?
How to Select Linked DWG?
First of all we need to select a Linked DWG Element in Revit.
I chose a simple way of doing it:
I just collect ElementIds of all selected elements with uidoc.Selection.GetElementIds, and I iterate until I find ImportInstance element.
And if it's not found, then I create an menu with pyrevit.forms.alert to notify user that ImportInstance wasn't in the selection, please try again.
How to Get DWG Filepath?
Once we have an ImportInstance we can find it's AbsolutePath, as long as it is a Linked DWG.
Let's create a function and break it down into steps:
Check if import_instance.IsLinked
Then we will get CADLinkType by using BuiltInParameter.ELEM_FAMILY_PARAM.
Then we can use GetExternalFileReference to get ExternalFileReference.
And Lastly, we can use it to GetAbsolutePath
How to Open Linked DWG's Folder/File?
To open a file or a folder we can use os package. There is a method called startfile, and it will work for both files and folders.
How to copy filepath to Clipboard?
Copying to clipboard is a little tricky. But we can do it with the shell command.
First of all we need to prepare the command, and then execute it with Popen, which will run it through cmd.
How to Reload DWG?
Lastly, reloading is very simple once you get your CADLinkType. It has a method Reload.
Also don't forget to use Transaction.