Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Placing text onto pageview (layout) from Python

$
0
0

I am having a hard time navigating the nuances between viewports and pageviews. It seems that I cannot genereate text onto a layout unless it is the active view port. Is that the case ? I have been chipping away at the problem but fall just short of generating text onto a layout without it being the active view port.

Here I have placed four points on a layout. Three are to establish a plane and the fourth is the planes new origin. Once the plane is created and its origin is updated I go along to make a TextEntity object and create an object attributes object and populate it whit what I think is important. This works fine, but again it only works when I have the first layout open on my screen as the active viewport or set it as the active view port. Is there a way to have it populate text while not switching to the page view / layout view.

Thanks !

import rhinoscriptsyntax as rs
import scriptcontext as sc
import math

import System
import System.Collections.Generic
import Rhino as R


doc = sc.doc

objs = sc.doc.Objects

views = sc.doc.Views.GetPageViews()

for vi in views:
    if vi.PageName == 'Page 1':
        sc.doc.Views.ActiveView = vi



for ob in objs:
    if type(ob) == R.DocObjects.PointObject:
        if ob.Name == "t_len_a":
            text_origin_pt = rs.coerce3dpoint(ob.Id)
            v_id = ob.Attributes.ViewportId

        if ob.Name == "pp_o":
            base_p_o = rs.coerce3dpoint(ob.Id)
        if ob.Name == "pp_x":
            base_p_x = rs.coerce3dpoint(ob.Id)
        if ob.Name == "pp_y":
            base_p_y = rs.coerce3dpoint(ob.Id)


ds = sc.doc.DimStyles.Current

plane = R.Geometry.Plane(base_p_o,base_p_x,base_p_y)

plane.Origin = text_origin_pt

te = R.Geometry.TextEntity.Create("Hello", plane, ds, False, 0, 0)
te.TextHeight = 0.25

targh = R.DocObjects.ObjectAttributes()
targh.ViewportId = v_id
targh.SetObjectFrame = plane

t_id = objs.AddText(te,targh)

sc.doc.Views.Redraw()

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles