Hello,
i got the name from my linked instance but for any reason, the name includes other stuff
import clr
import sys
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
rvt_links = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType()
names = []
for i in rvt_links:
names.append(i.Name)
OUT = rvt_links, names
How do i call it correctly?
KR
Andreas
You are looking at link instances not link types. What would you expect for the name if you had multiple instances of one of the links?
If you want the file name you can try working with the link types (via collector or by getting the instances link type), or pull each instance’s document and get that document’s title.
1 Like
@jacob.small ,
based on time-presure. i solved it this way…
KR
Andreas
Try the following:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
rvt_links = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType()
OUT = []
for i in rvt_links:
rvtFileName = i.Name.split(".rvt")[0]
OUT.append([i,rvtFileName])
OUT = zip(*OUT)
2 Likes
A non - string manipulation method:
for i in rvt_links:
lnkDoc = I. GetLinkDocument()
names.append(lnkDoc.Title)
1 Like
Beat me to it, i was just about to post a version including the GetLinkDocument() as i just remembered about that
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
#Gets a list of Revit Link elements
rvt_links = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType()
#Sets OUT to be a list
OUT = []
for i in rvt_links:
# Outputs the revit link and the title of the link document(eg file name without format)
# If you need more data from the link Document than just the title, then you should get
# the link document first as a variable then get what you need before putting into the list append.
# eg rvtDoc = i.GetLinkDocument()
# rvtTitle = rvtDoc.Title
# rvtPath = rvtDoc.PathName
OUT.append([i,i.GetLinkDocument().Title])
# Transposes the list and outputs it
OUT = zip(*OUT)
2 Likes
Personally when working with documents I always return the link, as it allows you to get not just the title (aka, name which is certainly useful in it’s own right), but also path which in my experience has been the instant follow up to the file name ion 80% of uses, and a whole bunch more.
2 Likes
Good point and I have added that as a comment on my code that i posted
1 Like
Hello this is Gulshan Negi
There are lots of ways to do this. To get a clean name from a linked file in Revit, you can also use the Document.GetElement()
method and the RevitLinkType.Name
property.
Thanks
1 Like