Set Textnote Vertical and Horizontal alignment

Hello,

I’m attempting to change the vertical/horizontal properties of a bunch of text notes all at once using the python I found here: Textnote vertical and horizontal alignment - #4 by Deniz_Maral @Deniz_Maral

Can someone tell me why the data I’m feeding in isn’t working as expected?

Dynamo: text alignment.dyn (17.6 KB)
Revit: text alignment.rvt (432 KB)

Try to enter “Bottom” and “Center” as String or
edit the code like that:

el.HorizontalAlignment = hor
	el.VerticalAlignment = ver

Thanks for the help! I tried single strings, lists of strings, etc. and looks like I’m getting different errors now…


text alignment2.dyn (29.5 KB)

# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitAPI","RevitServices")
from Autodesk.Revit.DB import *
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
elements = UnwrapElement(IN[0])

vertical = IN[1]
horizontal = IN[2]

if not hasattr(elements,"__iter__"):
	elements = [elements]
	
TransactionManager.Instance.EnsureInTransaction(doc)
for el,ver,hor in zip(elements,vertical,horizontal):
	el.HorizontalAlignment = hor
	el.VerticalAlignment = ver
	
TransactionManager.Instance.TransactionTaskDone()
OUT = elements

If you try with strings don’t edit code.

I did also try the strings with unmodified python…

el.HorizontalAlignment = HorizontalTextAlignment.Center
el.VerticalAlignment = VerticalTextAlignment.Bottom

It has to work then you don’t need other inputs.

I want to be able to feed it inputs instead of having it hard coded. Is that possible with the loop you wrote?

It worked on my side when I wrote it but now I can’t test it because I am running on Mac. I can tell you that tomorrow.
Which version of Dynamo do you use?

you can then do it like that and

TransactionManager.Instance.EnsureInTransaction(doc)
for el,ver,hor in zip(elements,vertical,horizontal):
	el.HorizontalAlignment = hor
	el.VerticalAlignment = ver
	
TransactionManager.Instance.TransactionTaskDone()
OUT = elements

It will work. You should use those lists that you flattened.

1 Like

Well, I must be doing something wrong still. I really appreciate all your help. This is not a rush so feel free to get back to your revit machine.

I tested it in Dynamo 2.0.3.8811 & also in Dynamo 2.3.0.8352

text alignment3.dyn (17.6 KB)

# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitAPI","RevitServices")
from Autodesk.Revit.DB import *
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

elements = UnwrapElement(IN[0])
vertical = UnwrapElement(IN[1])
horizontal = UnwrapElement(IN[2])

if not hasattr(elements,"__iter__"):
	elements = [elements]
	
TransactionManager.Instance.EnsureInTransaction(doc)
for el,ver,hor in zip(elements,vertical,horizontal):
	el.HorizontalAlignment = hor
	el.VerticalAlignment = ver
	
TransactionManager.Instance.TransactionTaskDone()
OUT = elements
1 Like

There is something wrong with those Nodes then. They give you String as output. They have to be member of Horizontal or VerticalAlignment Class.
I will take a look tomorrow.

1 Like

It works for me:

# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitAPI","RevitServices")
from Autodesk.Revit.DB import *
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

elements = UnwrapElement(IN[0])
vertical = IN[1]
horizontal = IN[2]

if not hasattr(elements,"__iter__"):
	elements = [elements]
	
TransactionManager.Instance.EnsureInTransaction(doc)
for el,ver,hor in zip(elements,vertical,horizontal):
	el.HorizontalAlignment = eval(hor)
	el.VerticalAlignment = eval(ver)
	
TransactionManager.Instance.TransactionTaskDone()
OUT = elements

Works like a charm now!

I polished it up into something convenient to run in the dynamo player. Enjoy everyone! :slight_smile:

set text note alignment.dyn (17.8 KB)

snip_20210930085537

2 Likes