How to display temporary text follow to the cursor before adding?

I create a script that adds text using an eto form. When the button is clicked, then select the point to add text. I need to display temporary text according to the cursor. When clicked will add text at that position. How to do that?

import Rhino
import scriptcontext
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import rhinoscriptsyntax as rs
class SampleGridView(forms.Dialog[bool]):
    def __init__(self):
        self.AddText = forms.Button(Text='Add Text')
        self.AddText.Click += self.OnPushPickButton
        layout = forms.DynamicLayout()
        layout.Padding = drawing.Padding(10)
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(None)
        layout.AddRow(self.AddText)
        self.Content = layout
    def AddTextButton(self, sender, e):
        text = "RHINOCEROS"
        while True:  # Keep asking for a point until a valid one is selected or canceled
            point = rs.GetPoint("Select a point to add the text")
            if point is None:  # Check if point selection is canceled
                break
            else:
                self.AddTextToRhino(text, point)
    def AddTextToRhino(self, text, point):
        plane = Rhino.Geometry.Plane(point, Rhino.Geometry.Vector3d.ZAxis)
        rs.AddText(text, plane)
    def OnPushPickButton(self, sender, e):
        Rhino.UI.EtoExtensions.PushPickButton(self, self.AddTextButton)
dialog = SampleGridView()
rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)


Hi @In_Me,

In order to have something dynamically drawn when pick a point location, you’ll need to a class that inherits from GetPoint and that overrides the OnMouseMove and OnDynamicDraw virtual methods.

In the OnMouseMove override, you’ll do some kind of computation everytime the mouse moves. In the OnDynamicDraw override, you can draw your geometry using the computations used on OnMouseMove.

I’ve attached a farily elaborate sample that shows how to dynamically draw text.

test_place_text.py (2.5 KB)

Let me know if you have any questions.

– Dale

2 Likes

Thank @dale