AddText() disabling "orient text towards reader when viewed from behind" in code

Good evening,

I have a problem when creating a text with Python. In the default text style the option for “orient text toward the reader when viewed from behind” is checked. Of course I could change that option in the template, but what if I wanted to control this in my code?

If not, is there an option to set the textstyle via code? This woudl be really comfortable.

This is the code I am using. All variables not specified here are set in the code above via rhinoscriptsyntax.

Option 1

text_entity = Rhino.Geometry.TextEntity()
text_entity.Plane = pln
text_entity.TextHeight = size
text_entity.Text = text
text_entity.Justification = justification
text_entity.FontIndex = sc.doc.Fonts.FindOrCreate(font, False, False)
item = sc.doc.Objects.AddText(text_entity)
rs.ExplodeText(item, delete=False)

Option 2

item = sc.doc.Objects.AddText(text, pln, size, font, False, False, justification)
rs.ExplodeText(item, delete=False)

Hi Tobias,

Annotation style can be defined as:

styleName = "Millimeter Large"
dimStyle = Rhino.RhinoDoc.ActiveDoc.DimStyles.FindName(styleName)
if dimStyle:
    text_entity.DimensionStyleId = dimStyle.Id
    print "Annotation style '{}' does not exist in the current .3dm file.".format(styleName)
1 Like

@djordje, thanks. I will check.
There is something I cannot explain to myself though.
When I start working on a model the script is working fine even with the option checked.
That means it does not respect the option and creates the text on the plane exactly how I want it to be.

Then suddenly - after some testing (and I have no idea how that is happening) it respects the option checked and flips all the texts if my view is viewed from behind. Maybe that has something to do that I unconsciously change the view or so on…

So I will test your approach and get the dimension styles and deactivate the orient option.

Hi Tobias,
Not sure what can be the problem. My suggestion was that you create a new Annotation style where the option “orient text toward the reader when viewed from behind” is unchecked.
Then when you add the “text_entity” to the Rhino document, you set its annotation style to this newly created one (which has “orient text toward the reader when viewed from behind” option unchecked).

Yes I agree, @djordje .
As the default style is unused in my template I will just set that option to False everytime I create a text like that.
I will check and let you know.

Hi @tobias.stoltmann and @djordje,

an alternative would be to override the DrawForward property per object, eg. something like:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    obj_id = rs.GetObject("Annotation", rs.filter.annotation, True, False)
    if not obj_id: return
    obj = rs.coercerhinoobject(obj_id, True, True)
    if not isinstance(obj, Rhino.DocObjects.AnnotationObjectBase): return

    new_style = Rhino.DocObjects.DimensionStyle()
    new_style.DrawForward = False


1 Like

Very nice Clement. Thank you for providing the solution.

1 Like