Problem with get family and type from linked elements

Hi i try to write script for get elements ids and family&type. Script works with model elements but i get exception with linked elements. What i’m doing wrong? How to get inside the linked elements parameters?
image

import clr

import sys

import os

from rpw import revit

from Autodesk.Revit.UI.Selection import *

from pyrevit import forms

doc = revit.doc

uidoc = revit.uidoc

def Pargetstr(element, name):

    return (element.GetParameters(name))[0].AsValueString()

# Pick model elements

try:

    with forms.WarningBar(title="Pick elements in model"):

        collector = uidoc.Selection.PickObjects(ObjectType.Element)

except:

    print("")

   

# Pick linked elements

try:

    with forms.WarningBar(title="Pick elements in linked model"):

        collector_link = uidoc.Selection.PickObjects(ObjectType.LinkedElement)

except:

    print("")

# Print Ids

try:

    for i in collector:

            print("====")

            print("Model element "+str(i.ElementId))

            el=doc.GetElement(i.ElementId)

            print((Pargetstr(el, "Family and Type")))

except:    

    print("No linked elements")

try:

    for i in collector_link:

           

            print("====")

            print("Linked element "+str(i.ElementId))

            el=doc.GetElement(i.LinkedElementId)

            print((Pargetstr(el, "Family and Type")))

except Exception as e:

    print(e)

    print("No linked elements")

I think in your last try statement, you need to replace ‘doc’ with the linked document because right now you are trying to get an element in the native document, but the element you want is not in that document, it’s in the linked document.

2 Likes

yeah, i thought someone will show me the path or few code samples :stuck_out_tongue: but with your answer i figured this:

try:

    for i in collector_link:

            print("====")

            el=doc.GetElement(i.ElementId)

            linkdoc=el.GetLinkDocument()

            el=linkdoc.GetElement(i.LinkedElementId)

            print("Linked element "+str(i.ElementId))

            print((Pargetstr(el, "Family and Type")))