i try to preview a Text3d object in rhino from grasshopper via python so i thought this should work.
import Rhino as rh
import System
T = rh.Display.Text3d('Test')
C = System.Drawing.Color.Black
P = rh.Geometry.Plane.WorldXY
a = rh.Display.DisplayPipeline.Draw3dText(T,C,P)
The help in the grasshopper python editor is mention Draw3dText(self: DisplayPipeline, text: Text3d, color: Color, textPlane: Plane) wahtever this self: DisplayPipeline means.
How can i create self: DisplayPipeline to get a text preview ?.
but the examples do not help and i guess the main reason are my scripting skills.
This forum post Creating text objects and outputting them as normal Rhino geometry is exactly what i have tried and the python and c# example works exactly the way i want but these scripts are to complicated to me.
It would be cool to understand this created class to preview non grasshopper objects and also preview grasshopper objects without an output maybe in the future.
But my second try succeed with creating a TextEntity object and previewing as surfaces.
Unfortunatly baking text entity take the dimesion style changes not into account.
import Rhino as rh
import scriptcontext as sc
# get dimstyle and change settings
ds = rh.DocObjects.DimensionStyle()
# change text properties ( a lot of options )
ds.Font = rh.DocObjects.Font(F)
ds.TextHeight = H
#ds.TextVerticalAlignment = rh.DocObjects.TextVerticalAlignment.Bottom
# create textentity which is not visible for grasshopper
te = rh.Geometry.TextEntity.Create(T,P,ds,False,0,0)
# create textentitysurface which is visible
# for preview what you get if you bake the text entity
a = rh.Geometry.TextEntity.CreateSurfaces(te,ds,0,0)
# bake text with same settings like textentity to get rhinotext object
if Bake:
sc.doc = rh.RhinoDoc.ActiveDoc
rh.RhinoDoc.ActiveDoc.Objects.AddText(T,P,H,F,False,False)
sc.doc = ghdoc
I like to use the simpler CustomDisplay class for rendering geometry and text from GHPython, using these functions to circumvent some of the issues with using this method: