LinkElementId Class to Tag Rooms in Linked Files

Share on email
Share on linkedin
Share on facebook
Share on whatsapp

When one would like to programmatically tag rooms in linked files it is can be confusing as the element ID’s that get generated in the container file. This is a short number. However, there is also a Unique Global Identifier for the element. This is a long number. Either can be used to identify the element.

It is quite possible that an element in one file has the same ID as a different element in another file. When linked file elements need to be tagged, their parent ID is not enough, and one must get the child ID (it is not the same Id as the parent file).

Autodesk, Revit, Dynamo, Micrographics, Linked File, Element, LinkElementId

It is simple to obtain this Id. One needs the Linked Document Id and the Room Id within the container as input.

linkElementId  = LinkElementId(linkDocId, ElementId)

In the script below the existing floor plans are inspected end linked room Id’s are extracted from them.

Whatever linked file elements you need to access, this would be the method to follow.

If you need assistance with your automation in Revit models using Dynamo, Micrographics can assist you with training or consultation. Consider that over some projects, potentially hundreds of man hours can be saved during production, which translated into hours your human capital can spend more productively. Teach your workforce new skills and let them enter the 4th industrial revolution. The rest of the world is doing exactly that, and this is what your company will be competing against, if you enter onto the international stage.


#[email protected],

import clr

import sys


from Autodesk.DesignScript.Geometry import *

import math

sys.path.append(r’C:\Program Files (x86)\IronPython 2.7\Lib’)


import Revit



clr.AddReference(“RevitServices”) # Import DocumentManager

import RevitServices

from RevitServices.Persistence import DocumentManager

from RevitServices.Transactions import TransactionManager

import traceback

clr.AddReference(‘RevitAPI’) #import clr

import Autodesk

from Autodesk.Revit.DB import *

from Autodesk.Revit.DB.Plumbing import *

from Autodesk.Revit.DB.Electrical import *

from Autodesk.Revit.DB.Mechanical import *

from Autodesk.Revit.DB.Lighting import *


import System

from System.Collections.Generic import *


from DSCore import *

doc = DocumentManager.Instance.CurrentDBDocument

linkDoc = UnwrapElement(IN[0])

category = IN[1]

linkinstance = UnwrapElement(IN[2])


linkDocId = linkinstance.Id

#elements =[]

elementCategoryFilter = ElementCategoryFilter(System.Enum.ToObject(BuiltInCategory, category.Id))

linkedRooms = FilteredElementCollector(linkDoc).WherePasses(elementCategoryFilter).WhereElementIsNotElementType().ToElements()

viewPlans = []

viewPlanIds = []

viewPlanLevels = []

out = []

possibleViewPlans = FilteredElementCollector(doc).OfClass(ViewPlan).OfCategory(BuiltInCategory.OST_Views).ToElements()#.WherePasses(filter) #THIS GETS THE PLACED FAMILY TYPE INSTANCES

for possibleViewPlan in possibleViewPlans:

if not possibleViewPlan.IsTemplate:

for linkedRoom in linkedRooms:

if linkedRoom.Location != None:

if linkedRoom.get_Parameter(BuiltInParameter.LEVEL_NAME).AsString() == possibleViewPlan.get_Parameter(BuiltInParameter.PLAN_VIEW_LEVEL).AsString():

linkedRoomReferenceId = LinkElementId(linkDocId, linkedRoom.Id)

doc.Create.NewRoomTag(linkedRoomReferenceId, UV(linkedRoom.Location.Point.X, linkedRoom.Location.Point.Y), possibleViewPlan.Id)

#LinkElementId(ElementId, ElementId)


OUT = linkedRoomReferenceId#,1,1,1#viewPlans, viewPlanIds, viewPlanLevels, linkedRooms#, linkedRoomLevels