I want to write a macro to let a objects name be extracted as a text. To do this I have tried to write a command string who uses “object name” in text field option (Fx) but i have no success. Is this possible?
1 Like
There doesn’t seem to be a way to do this in RhinoCommon yet. I’ve added this to the to-do list.
https://mcneel.myjetbrains.com/youtrack/issue/RH-38682
– Dale
My apologies for the confusion - looks like you need to use TextFormula.
import Rhino
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt('Select text')
go.GeometryFilter = Rhino.DocObjects.ObjectType.Annotation
go.Get()
if go.CommandResult() == Rhino.Commands.Result.Success:
text = go.Object(0).TextEntity()
if text:
print text.TextFormula
– Dale
Thanks Dale!! I am embarrassed to admit that I do not really understand “text formula”. Is this a string I put into a script editor?
Let’s say you had a named object with an ID of dfe70ddc-3e57-4ca7-acc0-79bb29ecd629
. You could then create a text object with an ObjectName
formula like this:
from scriptcontext import doc
from Rhino.Geometry import *
text_entity = TextEntity()
text_entity.Plane = Plane.WorldXY
text_entity.TextFormula = "%<ObjectName(\"dfe70ddc-3e57-4ca7-acc0-79bb29ecd629\")>%"
text_entity.Justification = TextJustification.MiddleCenter
doc.Objects.AddText(text_entity)
doc.Views.Redraw()
– Dale
1 Like