Find CAD link referencing View

GET VIEW NAME FOR SPECIFIC CAD LINK.dyn (8.3 KB)

Find Referencing Views for Linked CAD files.

Hi I am trying to find the view that a CAD Link has been linked into. I have many views and it is not possible to search through each one to find the link.

I have had a go at it in dynamo and have used a few custom packages but not sure which ones.

At the moment I have been able to get all the links and then select the link I want from the list using a match string custom node. The python script at the end will copy an element from one view to another if you give it the view names and the element id. I am only missing the view name for the existing CAD link.

Thanks

This should get you started so you’ll need to think about how to iterate through your list of views and query if the collector returns an ImportInstance. Note that the way the DWG has been linked will affect the result of your query. Unless it’s been linked to the current view when it was first imported, you’re going to get lots of views reporting a DWG link when only one object exists in your model, meaning what you are asking for might be flawed from the outset anyway if you are expecting to find one DWG associated to one view:

import clr

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument

view = UnwrapElement(IN[0])

collector = FilteredElementCollector(doc, view.Id).OfClass(ImportInstance)
collector.ToElements()

OUT = collector

GET VIEW NAME FOR SPECIFIC CAD LINK.dyn (19.6 KB)

Hi Thanks for the help. I have used a LoopWhile Node to iterate through your python script. First time to get it to work very exciting, thanks. My next problem is how to adjust the python script to select to import instance I want to search for, but for now this does what I needed, thanks again.

Hi,

I am still trying to find a solution for this. I have learnt a little bit of python since last time. But it doesn’t seem to be working for me. Hope someone can help with the python. I need to find the location of a specific link based on the name of the CAD link.

dynamo file at bottom

doc = DocumentManager.Instance.CurrentDBDocument

ownerViewId = “Owner View : N/A”
namsearch = UnwrapElement(IN[0])
views = UnwrapElement(IN[1])

for view in views:
cadLinkCollector = FilteredElementCollector(doc, view.Id).OfClass(ImportInstance)
cadLinks = cadLinkCollector.ToElements()

code that modifies revit database goes here

for cad in cadLinks:
viewSpecific = cad.ViewSpecific
if viewSpecific and cad.Name == namsearch:
ownerViewId = doc.GetElement( cad.OwnerViewId )
else:
ownerViewId = “Not working properly”

OUT = ownerViewId

FINDING LOST CAD BY NAME.dyn (5.1 KB)

Try BimorphNodes CAD.ReportInstances node

1 Like

Thanks for the tip but was mainly using it has a problem to practice python.

Now got one that works the way I wanted.

FINDING LOST CAD FINAL MARCH2018.dyn (8.3 KB)

This has been a great help to me. Unfortunately, this no longer works in 2018 (at least for me). Something with the Python code isn’t producing the same output as before.

I’ve updated the parameter names as required but I keep getting a null from the Python Script.

Find Lost CAD Inserts v0.1.dyn (44.9 KB)

Here’s the code: (I apologize that’s it’s formatted as indented text).

import clr

Import RevitAPI Classes

clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
#the above can be changed to import just specific classes separated by a comma

clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

clr.AddReference(‘RevitNodes’)
import Revit

Adds ToDSType (bool) extension method to wrapped elements

clr.ImportExtensions(Revit.Elements)
#adds ToProtoType, ToRevitType geometry conversion extension methods to objects
clr.ImportExtensions(Revit.GeometryConversion)

#import documentmanager and transaction manager
clr.AddReference(‘RevitServices’)
from RevitServices.Transactions import TransactionManager
from RevitServices.Persistence import DocumentManager

create varible for revit document

doc = DocumentManager.Instance.CurrentDBDocument
elements = UnwrapElement(IN[0])
nams =

start transaction

TransactionManager.Instance.EnsureInTransaction(doc)

code that modifies revit database goes here

for ele in elements:

#end transaction
TransactionManager.Instance.TransactionTaskDone()

OUT = nams

Thanks again!

1 Like

is it doable to change OwnerViewId i.e. “rehost” imported DWG to another view, seems manually cut/paste trick doesn’t work

SHARE

Select the correct index for your CAD link.

cad link location.dyn (8.8 KB)

1 Like