How to add text alignment to Python Script

import rhinoscriptsyntax as rs

# Get all text objects in the DWG file
all_objects = rs.AllObjects()
text_objects = [obj for obj in all_objects if rs.ObjectType(obj) == rs.filter.annotation]

# Loop thru all text objects and change the font, size, and alignment
for text_object in text_objects:
    rs.TextObjectFont(text_object, "SIMPLEX")
    rs.TextObjectHeight(text_object, 2.000)

Ive been trying to add the following text justification to include:
TopCenter
BottomCenter

Any help on how to proceed would be greatly appreciated .

Hi @wm_c,

it seems RhinoScriptSyntax does not provide a method to change the justification for existing annotation text objects. You might create a new annation text object with the existing properties using rs.AddText eg:

import scriptcontext
import rhinoscriptsyntax as rs
import System

def DoSomething():
    
    font = "Arial"
    height = 2.5
    justification = 1 + 262144
    
    for text_id in rs.ObjectsByType(rs.filter.annotation):
        if not rs.IsText(text_id): continue

        text = rs.TextObjectText(text_id)
        plane = rs.TextObjectPlane(text_id)
        
        rs.AddText(text, plane, height, font, 0, justification)
        rs.DeleteObject(text_id)

    scriptcontext.doc.Views.Redraw()
    
DoSomething()

Above re-creates the text using TopLeft, refer to the docs for different justification values. This is just a simplified script, you’ll need to transfer object properties (layer, color etc) on your own.

_
c.

1 Like

Wow, thank you Clement. That is super clever. Huge time saver for me as I spend a ton of time converting old drawings over to this format.

-wmc