I would like to label some items in my drawing and I would like to add an annotation similar to the radial dimension. I really like how that one creates an arrow and I can find the best place to put it and the text alignment changes accordingly.
I would like the same behavior where I can just enter some text myself.
For example I am laying out some lighting rails and want to label the different connectors. I would really like to have the same arrow pointing at it and then be able to place it anywhere and type some text.
I created a macro that kind of does something like that by drawing a tiny circle, but of course it will just put “R1” as the text and I then have to edit it.
I think I am pretty close with a custom Python script to achieve this, but struggling with the last part where it edits the dimension:
import rhinoscriptsyntax as rs
import Rhino
def create_custom_annotation():
# Prompt for a point
pt = rs.GetPoint("Select point for the circle center")
if not pt: return
# Add a tiny circle
circle = rs.AddCircle(pt, 1)
if not circle: return
# Run the DimRadius command with the circle selected
rs.SelectObject(circle)
rs.Command("_DimRadius _Pause _Pause _Enter")
# Prompt for dimension text in the command line
text = rs.GetString("Enter dimension text")
if not text: return
# Get the last added dimension
rs.UnselectAllObjects()
dim = rs.LastCreatedObjects(select=False)
# Update the dimension text
if dim and len(dim) > 0:
rs.TextObjectText(dim[0], text)
# Delete the small circle
rs.DeleteObject(circle)
create_custom_annotation()
Is there a way to change the radial dimension’s text from the Python Script?
Thanks @jeremy5, that is what I was after, although it has quite a few more steps and you can’t do it without clicking after entering the text. Would be nice to be able to stick to the keyboard after entering the text, otherwise its: mouse, keyboard, mouse, which is normally quite slow.
If anyone knows how to edit the radial dimension’s text from a script, that would be really helpful and be exactly what I need.
Also I think the icon for the Leader is somewhat missleading (pun intended). I never thought it would have text at the end, because the icon doesn’t suggest that. The icon next to it (ordinate dimension) kind of suggest somethign like that, but strangely that doesn’t actually have any part going at an angle as the icon suggests, but it’s all right angles.
It starts life that way, but you can (laboriously) adjust it:
There are three grips at the points where the line kinks. After you finish drawing a series of ordinates you can reselect an ordinate and see the grips, then select and move them. A panel pops up to help you select the right one if they are stacked.
Okay, I adapted the script together with ChatGPT and got a working version now.
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
def quick_leader():
# Prompt for a point
pt = rs.GetPoint("Select point for the circle center")
if not pt:
return
# Add a tiny circle
circle = rs.AddCircle(pt, 0.1)
if not circle:
return
# Run the DimRadius command with the circle selected
rs.SelectObject(circle)
rs.Command("_DimRadius _Pause _Pause _Enter")
# Prompt for dimension text in a StringBox to allow multi-word input
text = rs.StringBox("Enter quick leader text", "Quick Leader", "Edit Text")
if not text:
return
# Get the last added dimension
rs.UnselectAllObjects()
dim_objs = rs.LastCreatedObjects(select=False)
# Update the dimension text using RhinoCommon
if dim_objs and len(dim_objs) > 0:
dim_id = dim_objs[0]
dim_obj = rs.coercerhinoobject(dim_id)
if dim_obj and isinstance(dim_obj, Rhino.DocObjects.AnnotationObjectBase):
dimstyle = sc.doc.DimStyles.Current
dim_obj.Geometry.Text = text
dim_obj.CommitChanges()
sc.doc.Views.Redraw()
# Ensure the circle gets deleted
if rs.IsObject(circle):
rs.DeleteObject(circle)
quick_leader()
Works like a charm.
Of course we still have this totally dumb limitation that you can’t enter text with spaces in the command line, except for some special commands that McNeel deemed worthy, without giving us the same possibilities with scripts, so it has to use the Script Box. I would have loved to have it solely in the command line like any other command.
-_Text has a special “Text string” input that allows spaces:
Have you tried \s in the command line in place of the space? It prevents the command completing prematurely but I don’t know whether it will be parsed back into a space in your text field.
Command: -Leader
First curve point
Next curve point ( Undo )
Next curve point. Press Enter when done ( Undo )
Next curve point. Press Enter when done ( Undo )
Text string: “This is leader text with spaces”
Text string: This is leader text with spaces
Yes, I am aware it works with quotes, but that is quite inelegant. If you just forget once you have to do the whole command again, because it will end the command after the first word.
I think the whole concept of using Space to mean the same as Enter is just a fundamental misunderstanding of the keyboard and mental models. If it does not mean Enter anywhere else, why should it mean that in Rhino? They are 2 different keys with different meanings for a reason. Enter isn’t really any harder to press than Space.
More importantly if TextObject can enter text with spaces without using quotes, why can we not do that ourselves in scripts? Couldn’t it have the same behavior when the input is a string?
Either way, the Script box is an acceptable workaround as it doesn’t require any more key presses or quotes.