Text Width change does not update Height

I’m changing the width on text and then trying to get the new height. However, the height doesn’t change until after all the Dyanmo nodes have run. See two lists from code below. both oldHeight and newHeight area the same. I’m guessing Dyanmo’s transaction manager isn’t “really” committing the changes on TransactionTaskDone?

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

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

#from System.Collections.Generic import *

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

from Revit.Elements import *

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

myElements = UnwrapElement(IN[0])
width = IN[1]
newElems = []
myOut = []
oldHeight = []
newHeight = []

TransactionManager.Instance.EnsureInTransaction(doc)

#from Autodesk.Revit.DB import Transaction
#t = Transaction(doc, 'Name')
#t.Start()

for i in myElements:
oldHeight.append(i.Height)
i.Width = width
i.HorizontalAlignment = Autodesk.Revit.DB.HorizontalTextAlignment.Left
newElems.append(i)

uidoc.RefreshActiveView()
TransactionManager.Instance.TransactionTaskDone()

#t.Commit
TransactionManager.Instance.EnsureInTransaction(doc)

for i in newElems:
myOut.append([i.ToDSType(True), i.Height, i.Coord.ToPoint(), i.Coord.X, i.Coord.Y, i.Coord.Z])
newHeight.append(i.Height)

uidoc.RefreshActiveView()
TransactionManager.Instance.TransactionTaskDone()

OUT = myOut, oldHeight, newHeight

Solved.
Needed A ForceCloseTransaction to make sure the height was updated.

1 Like