Python newb here, I am trying to get and set the head position for area tags, but Im having trouble getting any packages to work for area tags. I modified a python script for getting TagHeadPosition but having trouble using it to setting TagHeadPosition. I am familiar with setting parameters with python but how does it differ from setting attributes?
import sys
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
if isinstance(IN[0], list):
tags = UnwrapElement(IN[0])
else:
tags = [UnwrapElement(IN[0])]
pts = IN[1]
listout =[]
for x in tags:
y = x.TagHeadPosition
TransactionManager.Instance.EnsureInTransaction(doc)
setattr(x, y, pts)
TransactionManager.Instance.TransactionTaskDone()
Hello, I still need a solution for this . I have made progress and the code seems to work but is not reflecting on Revit itself. Is this a transaction manager issue?
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import AreaTag
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Get the current Revit document
doc = DocumentManager.Instance.CurrentDBDocument
# Convert Dynamo inputs to Revit elements
if isinstance(IN[0], list):
area_tags = [UnwrapElement(tag) for tag in IN[0]]
else:
area_tags = [UnwrapElement(IN[0])]
# Convert Dynamo points to Revit XYZ points
if isinstance(IN[1], list):
points = [pt.ToXyz() for pt in IN[1]]
else:
points = [IN[1].ToXyz()]
# Ensure that the number of points matches the number of area tags
if len(area_tags) != len(points):
raise ValueError("Number of area tags and points do not match.")
# Start a transaction
TransactionManager.Instance.EnsureInTransaction(doc)
# Set the TagHeadPosition for each area tag to its corresponding point
for tag, point in zip(area_tags, points):
if isinstance(tag, AreaTag):
tag.HasLeader = True
tag.LeaderEndCondition = LeaderEndCondition.Free
tag.TagHeadPosition = point
# Commit the transaction
TransactionManager.Instance.TransactionTaskDone()
# Output the modified area tags
OUT = area_tags
I tested this with Revit 2022, and it seems it is a bug.
If you add a subsequent process in python/dynamo that changes something else in the tag too, you will see it will apply the move. e.g., I changed the Angle property to 1 and back to 0 after running your node.