Get Tag host element

You do not have “taggedelementids” define in the script. “taggedelements = ” is defined.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

dataEnteringNode = IN
tags = UnwrapElement(IN[0])
taggedelements = []
taggedelementids = []
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)

for i in tags:
tagID = doc.GetElement(i.Id)
taggedRoom = tagID.Area
taggedElem = doc.GetElement(taggedRoom.Id)
taggedelements.append(taggedElem)
taggedelementids.append(taggedElem.Id)

TransactionManager.Instance.EnsureInTransaction(doc)

OUT = taggedelements,taggedelementids
1 Like

Hello Sean,

Thank you very much for your help!!!

1 Like

Hi, I got this error. Dynamo 1.3.4 Revit 2019

Your code didn’t paste with the proper format into the python node.

Make sure everything under “for I in tags:” is tabbed once until you get to Transaction Manager.

1 Like

Thanks Sean! Would you be kind enough to modify to Get model element IDs? Or would it need to be specific to wall elements and floor and so on

Feel like I’m close
image

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

dataEnteringNode = IN
tags = UnwrapElement(IN[0])
taggedelements = []
taggedelementids = []
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)

for i in tags:
	tagID = doc.GetElement(i.Id)
	taggedElem = doc.GetElement(tagID.TaggedLocalElementId)
	taggedelements.append(taggedElem)
	taggedelementids.append(taggedElem.Id)

TransactionManager.Instance.EnsureInTransaction(doc)

OUT = taggedelements,taggedelementids

I’ll take a look when I get back to a computer. May need to play with the tabbing of the last two lines be removing it.

1 Like

so close! but not doing the whole list

I am betting it had to do with how your making the lists for output. My guess is your only getting the last item because your over writing all the others. Make sure your using a list.Add(element) for the outputs and not just elemId=element.Id

I am also not sure, but looks like you have .append but it should be .Add I believe.

I will try figure out what your saying but this is where im at

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

tags = UnwrapElement(IN[0])
taggedelements = []
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)

for i in tags:
	tagID = doc.GetElement(i.Id)
	taggedElem = doc.GetElement(tagID.TaggedLocalElementId)
taggedelements.append(taggedElem)

TransactionManager.Instance.EnsureInTransaction(doc)

OUT = taggedelements

My bad, but indent the last line and try .Add vs .append. Right now your only adding the last item to the final output list. That’s should do it.

1 Like

Boom! your amazing. Thank you

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

tags = UnwrapElement(IN[0])
taggedelements = []
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)

for i in tags:
	tagID = doc.GetElement(i.Id)
	taggedElem = doc.GetElement(tagID.TaggedLocalElementId)
	taggedelements.Add(taggedElem)

TransactionManager.Instance.EnsureInTransaction(doc)

OUT = taggedelements
2 Likes

Years later needed this! Here is the py code condensed:

import clr                                                  ## Load the Python Standard and DesignScript Libraries

import Revit

from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument            ##Current DOC

tags = UnwrapElement(IN[0])                                 ##The inputs to this node will be stored as a list in the IN variables.

TaggedElements=[]                                           ##Initialize the output list


TransactionManager.Instance.EnsureInTransaction(doc)        ##Get transaction manager fo rundo

for i in tags:                                                  ##For each tag 
        tagID = doc.GetElement(i.Id)                            ##Get the ID
        taggedID = doc.GetElement(tagID.TaggedLocalElementId)   ##Get the id of the tagged element
        TaggedElements.append(taggedID)                         ##Add it to the OUT list : )    

TransactionManager.Instance.EnsureInTransaction(doc)        ##End transaction if crash    

OUT = TaggedElements                                        ##Return tagged elements
3 Likes

This may be years later, but I just found this thread and it was extremely helpful. I just wanted to thank you for sharing your python code. It works great!

Hi, I’ve tried everything, even copied the code from above, still to no avail. This is what I have:

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

dataEnteringNode = IN

tags = UnwrapElement(IN[0])

taggedelements =
doc = DocumentManager.Instance.CurrentDBDocument

TransactionManager.Instance.EnsureInTransaction(doc)

for i in tags:
tagID = doc.GetElement(i.Id)
taggedElem = doc.GetElement(tagID.TaggedLocalElementId)
taggedelements.append(taggedElem)

TransactionManager.Instance.EnsureInTransaction(doc)

OUT = taggedelements,taggedelementids

I get the following warning message:

IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 31, in
AttributeError: ‘FamilyInstance’ object has no attribute ‘TaggedLocalElementId’

1 Like

Just a guess- you may need to update your python (ala~ newer version of Revit)- and this code was written for Revit R22. If you are in 2019 that may be the issue.

Coming to an old post, but it seems an everlasting one!

I need this exact function, but script doesn’t work for me.
It could be newer dynamo/Revit?

I’m running Revit 2023, and Dynamo 2.16
This dynamo also prefers the newer CPython3

Can anyone help with this?