Add geometry to list

Hi All,

For a project, I want to add grasshopper rectangles after each click on the button in my user interface (Blue circle). Now, with a loop I can add multiple rectangles to a list in a while loop, until the user puts it to stop by typing “N” (in green).

However, this program only shows all rectangles after the loop has stopped. Is there also a way to create a rectangle at each click on the button, and after the python component add this new rectangle to a list of already created ones?

Hope to hear from you, thanks for your help!

JS

Code:

sc.doc = ghdoc

corridors = []
stop = False
while stop == False:
    
    plane = rs.WorldXYPlane()
    Rhino.RhinoApp.ReleaseMouseCapture()
    x1 = rs.GetPoint("Select first point of corridor")
    print(x1) # Tip: print(...)
    x2 = rs.GetPoint("Select second point of corridor")
    print(x2)
    Rhino.RhinoApp.ReleaseMouseCapture()
    rs.Redraw()
    corridors.append(rs.AddRectangle(plane,x1,x2))
    
    more_corridors = rs.GetString("more corridors? (if yes type 'Y', if no type 'N')") 
    if more_corridors == 'Y' or more_corridors == 'y':
        continue
    else:
        stop = True

Thanks for posting this here after out chat via PMs. In addition to the rest of the comments written in the PM, I feel some urge to repeat that this is not something very recommendable, because Grasshopper users do expect the Grasshopper solution to be stopped when a user script pauses for command line input.

That being said, if you create the form, that problem could be circumnavigated.
Developing all this in a GhPython component seems like a big endeavor!

This all being said, and to address this more specific question that you ask here – Grasshopper uses its own display conduit/pipeline in order to draw its geometry. You can create your own conduit and display what you prefer while your script executes. There is an example here:

Thanks,

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Thank you very much!

Some more examples with conduits are here:

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Display_DisplayConduit_PreDrawObjects.htm