How to get Link Document and Link Instance from a Revit Model Element

Hi there,

I am trying to use the node “Select Model Element” to select a Revit link Instance, and from it I want to take the Link Document and the Link Instance.

I am wondering if it is possible with python, because I tried to find a node that do this task, but I didnt.

There are several packages that include nodes with this functionality. I usually use the one from archi-lab; GetDocuments I think it’s called.

Hi @MartinSpence, thanks for your reply.
Actually I need a node that retrieves the link document and the link instance just from the model element that I select, not all link files.
The node GetDocuments that I know retrieves information about all link files of my project.

Aha! Sorry, I misunderstood what you are after then. I don’t know of a node that will return the doc/instance it originates from.

Personally, I’ve never researched if elements in links have this information stored in them, but perhaps it’s out there :slightly_smiling_face:. But in that case you’re probably looking at some python scripting.

1 Like

This is what you mean, isn’t it?

Python script:

import clr

#Import the Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

eleDoc = UnwrapElement(IN[0]).Document

#To get the doc:
OUT = eleDoc

Edit: I just read the title again and realized this whasn’t it :-D.

2 Likes

seems it will get host document instead of linked one, any easy way to get linked document from linked instance? well, I prefer user actually selecting the link instance for flexibility

Hi @Ning_Zhou,

The method show above will yield the document of which the element, in this case a wall, resides. Here’s a link to the property in the API.

If you have your user select the link manually, you can retrieve the document by using the GetLinkDocument() method. See here for more info.

Good luck.

Edit:

3 Likes

got it, thanks Martin!

I tried but I got this error:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 7, in
AttributeError: ‘List[object]’ object has no attribute ‘GetLinkDocument’

If you’re feeding a list, you need to loop through the list, and call the method.

Can elaborate later if needed.

Problem has resolved in here : Getting Link Document - Revit - Dynamo (dynamobim.com)

it does not work for a revit link input list though, although I can get all links and documents with a library:

IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 7, in
AttributeError: ‘List[object]’ object has no attribute ‘GetLinkDocument’

Here’s an example:

# Enable Python support and load DesignScript library
import clr

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

links = UnwrapElement(IN[0])

output = []

for i in links:
	output.append(i.GetLinkDocument())

# Assign your output to the OUT variable.
OUT = output

@MartinSpence I am getting this error. Can you please help me out ?

link instance type error

Hi @shashank.baganeACM,

The code you are using is expecting a list. If you place a list.create between your two nodes, it should work.

Otherwise you can use this snippet instead:

import clr

#Import the Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

eleDoc = UnwrapElement(IN[0]).Document

#To get the doc:
OUT = eleDoc
3 Likes

please could you tell me the difference between link document and link instance?

Hi @joumana95 ,

The information you are able to extract from the two elements classes are very different.

You can explore the two API classes via the links below:

Link to the Document Class.

Link to the LinkInstance Class.

1 Like

many thanks