UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
ObjectType obt=ObjectType.LinkedElement;
Reference refElemLinked;
Element linkedelement = null;
refElemLinked = uidoc.Selection.PickObject(obt, "Please pick an element in the linked model");
RevitLinkInstance elem = doc.GetElement(refElemLinked.ElementId) as RevitLinkInstance;
Document docLinked = elem.GetLinkDocument();
linkedelement = docLinked.GetElement(refElemLinked.LinkedElementId);
import clr
import sys
import System
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
elements = UnwrapElement(IN[0]) if isinstance(IN[0],list) else [UnwrapElement(IN[0])]
dicDocLink = {link.GetLinkDocument().GetHashCode() : link for link in FilteredElementCollector(doc).OfClass(RevitLinkInstance) }
OUT = [dicDocLink.get(elem.Document.GetHashCode()) for elem in elements]