Modify Text Object Justification (Python)


Does anyone know how to modify Annotation Text justification without recreating the text using Python. AddText has a parameter to modify justification when creating text, but it does not appear that TextObjectJustification was created for Python.

This is my assumption because this exists:

But it is not in this list:

If I am simply misunderstanding something, please let me know.

Thank You

Hi Dbodey,

There seems to be no rhinoscriptmethod to adjust justification of a text.

Below is quickly made setup to show how to do it with RhinoCommom in python:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
import System

def set_justifiction(text_id, justification):
    1 = Left
    2 = Center (horizontal)
    4 = Right
    65536 = Bottom
    131072 = Middle (vertical)
    262144 = Top
    #set new justification like with rs.AddText
    new_justification  = System.Enum.ToObject(Rhino.Geometry.TextJustification, justification)
    #grab geometry of the text object
    text_geometry = rs.coercegeometry(text_id)
    text_geometry.Justification = new_justification
    #replace geometry of the rhino object with new justification geometry
text_id = rs.GetObject('select text for new align')

set_justifiction(text_id, 1)
set_justifiction(text_id, 2)
set_justifiction(text_id, 4)
set_justifiction(text_id, 65536)
set_justifiction(text_id, 131072)
set_justifiction(text_id, 262144)

Does this make sense?


Makes a lot of sense. Thank you!

1 Like
 #replace geometry of the rhino object with new justification geometry

Could I get a little more info on this line of code and what parameter types it takes? I’m thinking text_id has to be a TextObject rather than a GUID. Is that so?

I was getting this error with my own implementation using that Replace function when I passed in (GUID, modified_TextObject).

Actually, I figured out my misunderstanding. I was treating a TextObject as a TextEntity. It works great now, thanks again.

See, I wasn’t using coerce functions because I had been using:
which returns a list of Rhino.DocObjects.TextObject

So, what is the difference between TextObject and TextEntity and particularly when do I use one over the other @Willem?

Looks like TextObject.Geometry == TextEntity