Hello,
i see all with the Lookup table, but where is the path of my .dwg ?
dwg = UnwrapElement(IN[0])
nam = [i.Path() for i in dwg]
OUT = nam
KR
Andreas
Hello,
i see all with the Lookup table, but where is the path of my .dwg ?
dwg = UnwrapElement(IN[0])
nam = [i.Path() for i in dwg]
OUT = nam
KR
Andreas
Use the .GetExternalFileReference()
method
Might want to add a conditional check against it’s property .IsLinked
also as I’m pretty sure imports wont have a reference. But maybe they do? Try it out without first.
i found this but i stuck in the syntex
#Template
#DraxlA
#19.07.2023
import clr
import sys
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
collector = FilteredElementCollector(doc).OfClass(typeof(CADLinkType))
file_paths = []
for el in collector:
try:
CADLinkType link = doc.GetElement(el.Id) as CADLinkType
isLinkedFile = link.IsExternalFileReference()
if isLinkedFile == true:
ExternalFileReference exFiRef = link.GetExternalFileReference()
ModelPath path = exFiRef.GetPath()
#pathString
if path.ServerPath == true:
pathString = path.CentralServerPath
file_paths.append(pathString)
else:
pathString = path.ToString()
file_paths.append(pathString)
except:
file_paths.append("Does not work")
OUT = file_paths
i got this @haganjake2
the dwgs are linked!
… set from C# to python Solved: Re: Get filepath of linked CAD file (non-rvt file) - Autodesk Community
That’s because the method is for ImportInstances (which is what you showed in your first screenshot).
But now you are using cadlinktype’s.
Try the same method on the import instance, maybe just try it with 1 first also?
You need to put line 38 inside the if condition checking if it is a link or not.
The error you are getting is because it is trying to get the reference from an import not link (I think)
Let do simple than, I saw your code so many issue syntax basic, I hope it don’t relate to chat GPT
# Load the Python Standard and DesignScript Libraries
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
paths = []
def GetExtFileRefPath(item):
try :
dirRefs = item.GetExternalResourceReferences()
for i,v in enumerate(dirRefs):
paths.append(v.Value.InSessionPath)
return paths
except Exception as e: return e.ToString()
doc = DocumentManager.Instance.CurrentDBDocument
items = FilteredElementCollector(doc).OfClass(CADLinkType).ToElements()
OUT = [GetExtFileRefPath(x) for x in items]