Question on ExpireSolution in GhPython

Here’s what I came up with, using the scriptcontext.sticky dictionary which retains data between solutions. Note that you can directly access the instance properties instead of using the GetValue and SetValue methods of the GH_NumberSlider type.

from scriptcontext import sticky

thisDoc = ghenv.Component.OnPingDocument()
slider = ghenv.Component.Params.Input[0].Sources[0]

if click_me:
    # reset values to starting position
    sticky['running'] = True
    slider.TickValue = 30 

desired_area = 12
if sticky['running']:
    if area > desired_area or slider.TickValue >= slider.TickCount:
        sticky['running'] = False # break the loop
    else:
        def sln_delegate(doc):
            slider.TickValue +=1 
        thisDoc.ScheduleSolution(1, sln_delegate) # call the delegate function and schedule a solution in 1 millisecond

Alhough if you’re comfortable enough with Python and RhinoCommon scripting, you could get a 100x speedup by embedding the entire loop logic inside the Python script:

from Rhino.Geometry import *

num_steps = 10000
min_radius, max_radius = 0.030, 10.00

for i in range(num_steps):
    radius = min_radius + i * (max_radius - min_radius) / num_steps
    circle = Circle(Plane.WorldXY, radius).ToNurbsCurve()
    area = AreaMassProperties.Compute(circle).Area
    if area > 12:
        break


question.gh (9.3 KB)