Input Dynamically

from Rhino import *
from Rhino.Geometry import *
from Rhino.Commands import *
from Rhino.Input.Custom import *
from scriptcontext import doc
from System.Drawing import *
import rhinoscriptsyntax as rs

def RunCommand():
    gp = GetPoint()
    gp.SetCommandPrompt("Center point")
    if gp.CommandResult() != Result.Success:
        return gp.CommandResult()
    center_point = gp.Point()
    if center_point == Point3d.Unset:
        return Result.Failure
    radius = rs.RealBox("msg", 0, "tit") #
    gcp = GetCircleRadiusPoint(center_point, radius) #
    #gcp = GetCircleRadiusPoint(center_point)
    gcp.SetBasePoint(center_point, True)
    gcp.DrawLineFromPoint(center_point, True)
    if gcp.CommandResult() != Result.Success:
        return gcp.CommandResult()
    #radius = center_point.DistanceTo(gcp.Point())
    cplane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane()
    doc.Objects.AddCircle(Circle(cplane, center_point, radius))
    return Result.Success
class GetCircleRadiusPoint(GetPoint):
    #def __init__(self, centerPoint):
    def __init__(self, centerPoint, radius):
        self.m_center_point = centerPoint
        self.m_radius = radius #
    def OnDynamicDraw(self, e):
        cplane = e.RhinoDoc.Views.ActiveView.ActiveViewport.ConstructionPlane()
        radius = rs.RealBox("msg", 0, "tit") #
        #radius = self.m_center_point.DistanceTo(e.CurrentPoint)
        circle = Circle(cplane, self.m_center_point, radius)
        e.Display.DrawCircle(circle, Color.Red)
if __name__ == "__main__":

the above code, I modified it from below link:

the intent is to be able to vary the size of the circle, not by clicking with the mouse to obtain the distance from the center, but by repeatedly typing the numerical value via an input until you find the desired size

I don’t know if it’s possible,
but looking through guides and various examples, I haven’t found anything about it.

Hi @0904,

there are probably multiple ways to do this, below is one using a CustomDisplay (3.6 KB)



@clement Thanks for the reply :+1:
so you have to use another method

I’m trying to rework the code and ended up in this situation:


in the tests I had omitted the clear,
now even using it the created circles don’t disappear even creating a new file :confused: :confused:

Yes, you’ll need to restart Rhino then to get rid of it. To prevent that you run into this situation you can do two things:

  1. Store the custom_display in scriptcontext.sticky so on your next start of the script, you can get it and then clear / reuse it if it exists.

  2. Put all your code into a try except finally block which ensures that in finally you clear, disable and dispose the custom_display. This makes it easier to work on the script and whenever you create an error, the display is cleared.


1 Like

Hi, @clement

I found in the guide: sticky-values
but it’s not clear to me how this kind of dictionary works
what is the difference with the classic Python dictionary?

ps are the values stored within Rhino?

Hi @0904,

scriptcontext.sticky works like a regular python dictionary but it is preserved while Rhino remains open. You can store something in this dictionary with one script and another script can access the same dictionary if it is started from the same Rhino instance. Only if you close Rhino or reset the scriptengine, the dictionary is cleared.


so sort of:



in Rhino. . .

Hi @0904, _SetUserText and _SetDocumentUserText both store only string values. To store an instance of a CustomDisplay you cannot use them. But you can store almost anything in a python dictionary (which scriptcontext.sticky is).


1 Like

Hi @clement,

I did several tests, but I don’t understand your solution?

ps Should I use both recommended strategies or choose one?

with the try I handled error.
but using sticky, after half a day nothing

Hi @0904,

as long as you do not need to have the CustomDisplay to stay after you have finished the script, there is no need to store it in the sticky.

Below is an example using try except finally, note the comments below finally (4.1 KB)


ok thanks @clement, I will study it in order to understand all the steps well :+1:

Finally I was able to use this method that you recommended :+1:

ps cute as what, I think it will definitely come in handy for me in the future :pray: