Text Height node and python not working when ran with text note creation

I altered a python get text height node and then found a text height node and was testing with both of those on already made text. It works however if I try to add it to a script that creates text notes and place it after the node that sets the text width it only returns 0.

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument
textInput = IN[0]

if not isinstance(textInput, list):
	textInput = [textInput]

textHeight = []

TransactionManager.Instance.EnsureInTransaction(doc)

for textH in textInput:
	textH = UnwrapElement(textH)
	textHeight.append(round(textH.Height,3))

TransactionManager.Instance.TransactionTaskDone()

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument 

def CloseAllTransactionAndRegenerateDocument():
    TransactionManager.Instance.TransactionTaskDone()
    TransactionManager.Instance.ForceCloseTransaction()
    doc.Regenerate()

if isinstance(IN[0], list):
    textInput = UnwrapElement(textInput)
else:
    textInput = [UnwrapElement(textInput)]

textHeight = list()

#Force close any ongoing transaction and regenerate document
CloseAllTransactionAndRegenerateDocument()

for textH in textInput:
    textHeight.append(round(textH.Height,3))

OUT = textHeight

try the code above.

1 Like

I had to replace textInput with “IN[0]” here:

if isinstance(IN[0], list):
    textInput = UnwrapElement(IN[0])
else:
    textInput = [UnwrapElement(IN[0])]

My next warning I got was this:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 29, in
File “”, line 19, in CloseAllTransactionAndRegenerateDocument
Exception: Modification of the document is forbidden. Typically, this is because there is no open transaction; consult documentation for Document.IsModified for other possible causes.

EDIT:
I think perhaps the issue isn’t with the get height python node I created because the built-in TextNote.Height is returning 0 as well.

The Revit.Elements.TextNote element I’m getting is straight from a node that sets the widths so the notes should have differing values. Even if it didn’t work it should at least return the height for one line of text rather than 0.

I was able to get both the python node and the builtin node working by using a simple Transaction.End node after my SetWidth node.

Thanks stillgotme for the help. That close all transaction code looks like it could be useful elsewhere if I new what was going wrong with it.

Figures, sometimes the transaction aint committed, thats why you arent able to query the new data generated, no matter what kind of methodology you used. thats why i suggested the force close any on-going transaction before query any new elements generated.

but still, glad that you are able to solve it

EDIT: Sorry for the code error typo there, everything was typed on the fly without checking :smiley:

1 Like

No worries, do you know why the your close all transactions definition didn’t work?

To be honest, i have no idea. It might be due to the last method called (which i dont think is the cause).

In their node, they called the exact same method as i do, except for the last line where dynamo uses UIDocument.RefreshActiveView(Revit API) rather than Document.Regenerate(Revit API)

Maybe you can try it out in the python script and let us know? :smiley:

EDIT: Incase you know which line to replace, just replace doc.Regenerate() with DocumentManager.Instance.CurrentUIDocument.RefreshActiveView() in the CloseAllTransactionAndRegenerateDocument() method in the python script