Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 4159

Input Dynamically

$
0
0
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")
    gp.Get()
    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.SetCommandPrompt("Radius")
    gcp.ConstrainToConstructionPlane(False)
    gcp.SetBasePoint(center_point, True)
    gcp.DrawLineFromPoint(center_point, True)
    gcp.Get()
    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))
    doc.Views.Redraw()
    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__":
    RunCommand()

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.

8 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 4159