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

Eto realtime output?

$
0
0

I want to use the scroll wheel to iterate through a list of objects in Grasshopper. I’m currently doing this with a text dot in Rhino. Once it is selected, I can change the height input by clicking the text field and scrolling the mouse wheel. The textdot in the Rhino viewport updates instantly and is synchronized in Grasshopper after a short delay. The problem with this approach is that the smallest size is 3 units and I need index 0…

I also have a script to change the value of a textdot with an Eto dialog / popup.
It uses a numeric stepper and the value can be changed with the scroll wheel.

The problem with the script is that it only updates the textdot after clicking ok.

Is there a way to get the new value to a textdot in realtime without having to press ok?

image

################################################################################
# Source file: SampleEtoRebuildCurve.py
# MIT License - Copyright (c) 2017 Robert McNeel & Associates.
# See License.md in the root of this repository for details.
################################################################################

# Imports from
from Rhino.UI import *
from Eto.Forms import *
from Eto.Drawing import *

import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs

rs.Command("_-Gumball Hide Enter")

################################################################################
# Class to hold arguments
################################################################################
class TextDotArgs():
    
    # Initializer
    def __init__(self):
        self.Percentage = 10

    
    # Validator
    def IsValid(self):
        if self.Percentage < 0 or self.Percentage > 30: return False

        return True
    
################################################################################
# Change TextDot value dialog class
################################################################################
class TextDotDialog(Dialog[bool]):
    
    # Initializer
    def __init__(self, args):
        self.Args = args
        # Initialize dialog box
        self.Title = 'SetTextDot'
        self.Padding = Padding(5)
        # Create layout
        layout = TableLayout()
        layout.Padding = Padding(5)
        layout.Spacing = Size(5, 5)
        layout.Rows.Add(self.CreateSteppers())
        layout.Rows.Add(None) # spacer
        layout.Rows.Add(None) # spacer
        layout.Rows.Add(self.CreateButtons())
        # Set the dialog content
        self.Content = layout
    
    # Creates numeric stepper controls
    def CreateSteppers(self):
        # Create labels
        label0 = Label(Text = 'New Value:')

        label2 = Label(Text = '({})'.format(self.Args.Percentage))

        # Create numeric steppers
        self.Percentage = NumericStepper(
            Value = self.Args.Percentage,
            MinValue = 0,
            MaxValue = 30
            )

        # Create table layout
        layout = TableLayout()
        layout.Spacing = Size(5, 5)
        
        layout.Rows.Add(TableRow(label0, self.Percentage))

        return layout
    
    # OK button click handler
    def OnOkButtonClick(self, sender, e):
        # Harvest control values before closing
        self.Args.Percentage = self.Percentage.Value
        self.Close(True)
    
    # Cancel button click handler
    def OnCancelButtonClick(self, sender, e):
        self.Close(False)
    
    # Create button controls
    def CreateButtons(self):
        # Create the default button
        self.DefaultButton = Button(Text = 'OK')
        self.DefaultButton.Click += self.OnOkButtonClick
        # Create the abort button
        self.AbortButton = Button(Text = 'Cancel')
        self.AbortButton.Click += self.OnCancelButtonClick
        # Create button layout
        button_layout = TableLayout()
        button_layout.Spacing = Size(5, 5)
        button_layout.Rows.Add(TableRow(None, self.DefaultButton, self.AbortButton, None))
        return button_layout
    
################################################################################
# Function to change the TextDot value
################################################################################

def TestTextDot():
    
    res, objref = Rhino.Input.RhinoGet.GetMultipleObjects(
        "Select at least one TextDot", 
        True, 
        Rhino.DocObjects.ObjectType.TextDot
        )
    if res != Rhino.Commands.Result.Success: return
    
    args = TextDotArgs()

    dlg = TextDotDialog(args)
    
    rc = dlg.ShowModal(RhinoEtoApp.MainWindow)
    if rc and args.IsValid():

        objects = sc.doc.Objects.GetSelectedObjects(False, False)

        for obj in objects:
            if isinstance(obj, Rhino.DocObjects.TextDotObject):
                obj.Geometry.Text = str(int(args.Percentage))
                obj.CommitChanges()
    sc.doc.Views.Redraw()
    
################################################################################
# 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__":
    TestTextDot()

I added this but it doesn’t seem to do anything:

    def PercentageChanged(self, sender, e):
        self.Args.Percentage = self.Percentage.Value

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles