Adding Sample ETO PushPick Button to Simple Recursion

Attempting to create a demonstration of ETO Button that will execute simple recursion. Currently, this locks up my Rhino instance. I’ve searched the forums and can’t find much. Thank you.

################################################################################
# SampleEtoPushPickButtonDialog.py
# Copyright (c) 2018 Robert McNeel & Associates.
# See License.md in the root of this repository for details.
################################################################################
# Imports
import rhinoscriptsyntax as rs
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms

class SampleEtoPushPickButtonDialog(forms.Dialog):
    
    def __init__(self):
        self.Title = "Point to Spheres"
        self.ClientSize = drawing.Size(200, 200)
        self.Padding = drawing.Padding(5)
        self.Resizable = False

        button = forms.Button()
        button.Text = "Pick Center Point"
        button.Click += self.OnPushPickButton
        
        self.Content = button

    # Define Function(s)
    def RecursiveSpheres(pt, r):
        if r == 0:                              # Tests value of r (counts down to 0)
            return 1                            # Exits Recursive Conditional
        else:
            rs.AddSphere(pt, r)                # Adds Sphere (from library)
        return RecursiveSpheres(pt, r-1)      # Calls Function (again)

    def OnPickPoint(self, sender, e):
        #Rhino.Input.RhinoGet.GetPoint("Pick a point", True)
        pt = rs.GetPoint("Pick Center Point")  # User Input (pick point on screen)
        RecursiveSpheres(pt, 10)              # Calls Funtion

    def OnPushPickButton(self, sender, e):
        Rhino.UI.EtoExtensions.PushPickButton(self, self.OnPickPoint)

################################################################################
# Creating a dialog instance and displaying the dialog.
################################################################################
def TestSampleEtoPushPickButtonDialog():
    dialog = SampleEtoPushPickButtonDialog()
    dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
    
################################################################################
# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.
################################################################################
if __name__ == "__main__":
    TestSampleEtoPushPickButtonDialog()

Challenge 02w - Point to Spheres.py (2.4 KB)

This is where I started, just attempting to do something simple, like create a sphere for every point selected.

################################################################################
# SampleEtoPushPickButtonDialog.py
# Copyright (c) 2018 Robert McNeel & Associates.
# See License.md in the root of this repository for details.
################################################################################
# Imports
import rhinoscriptsyntax as rs
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms

class SampleEtoPushPickButtonDialog(forms.Dialog):
    
    def __init__(self):
        self.Title = "Point to Sphere"
        self.ClientSize = drawing.Size(200, 200)
        self.Padding = drawing.Padding(5)
        self.Resizable = False

        button = forms.Button()
        button.Text = "Pick Center Point"
        button.Click += self.OnPushPickButton
        
        self.Content = button
        
    def OnPickPoint(self, sender, e):
        #Rhino.Input.RhinoGet.GetPoint("Pick a point", True)
        pt = rs.GetPoint("Pick Center Point")   #This works
        rs.AddSphere(pt, 10)

    def OnPushPickButton(self, sender, e):
        Rhino.UI.EtoExtensions.PushPickButton(self, self.OnPickPoint)

################################################################################
# Creating a dialog instance and displaying the dialog.
################################################################################
def TestSampleEtoPushPickButtonDialog():
    dialog = SampleEtoPushPickButtonDialog()
    dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
    
################################################################################
# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.
################################################################################
if __name__ == "__main__":
    TestSampleEtoPushPickButtonDialog()

Challenge 01w - Point to Sphere.py (1.9 KB)

Hi @stevefuchs,

Nice to see you out here!

Here is a fix, basically you need a few more self references.

Challenge 02w - Point to Spheres.py (2.4 KB)

– Dale

Very good to be back in Python with my design students. I’m going through some previous warm-up challenges with them, and I promised I’d introduce simple ETO to them, tonight. Is it also possible to use Rhino.Input, per your original example? Doesn’t seem to work, the way I have it below.

        pt = Rhino.Input.RhinoGet.GetPoint("Pick a point", True)
        #pt = rs.GetPoint("Pick Center Point")  # User Input (pick point on screen)

I sincerely appreciate the quick help. Please say hello to Mary from Nicole and me.

1 Like

Hi @stevefuchs,

I’ve tuned up the script, removing calls to rhinoscriptsynax.

Note, some RhinoCommon methods may return multiple objects as a tuple. The GetPoint is one such method.

.NET methods can only return one object as the result of a call; in order to return more than one object, by-ref parameters are needed. They are decorated with the parameter modifier (ref, out) in C#.

Point to Spheres.py (2.2 KB)

Does this work?

– Dale