Does This Counter Solution Look Unstable?

I’m trying to make an interactive next/previous item selector in Grasshopper, but the use of data recorders bothers me. Will them amassing larger volumes of data not start to slow the whole script down? Would the Null checks and stream filters impact performance if this snippet were to be used in a larger, already heavy script?

nextpreviouslist.gh (17.1 KB)

I think the buttons are unreliable as they might count when you click and let go. I’ve triedd all sorts of things years ago and ended up using a script.

Look here: Keyboard hotkey to replace button - #2 by Mahdiyar

and here: How to detect an update/change of a number? - #11 by AndersDeleuran

Wow. A keyboard shortcut sounds very nice! Thank you.

A coding solution is better than a script cobbled together out of components from various random plug-ins, but out of a desparation of not knowing how to code, here is a solution I came up with:


Increment Decrement Counter VR 1.gh (25.3 KB)

Summary

I’ve employed a number of tricks. The buttons are set to +1/-1 increment/decrement values in the pressed state and are devoid of a value in the unpressed state. The If Value Changed component from Parakeet will read the merged outputs of the buttons and send out a pulse when it registers a change. This occurs on both the press and release of the buttons, so a double pulse for a click. In order to ignore the release pulse, the pulses are ANDed with the list length of the merged button outputs, which reads 1 on downpress and 0 on uplift. For every press of a button, you now have a single pulse coming the the Gate And component.

The Data Recorder component is limited to single output. This creates a hold state of the last change of increment value from the buttons. A Panel acts as memory for the counter. When a pulse passes through the Stream Filter, the sum of the increment/decrement hold state with the counter is pushed through the gate and used by the Set Object Value component from Metahopper to overwrite the memory. The entire point of the pulse is to be able to overwrite memory, and then interrupt the read/write feedback loop set up by the wiring.

I really like opening solution that uses purely native Grasshopper components. I wonder if there isn’t a way of using an annotation dot that you write to via Content Cache as memory. Obviously, a very simple piece of code is the best solution.

For some things I’ve used an eto script to scroll an annotation dot up and down.

:sweat_smile:


Increment Decrement Counter VR 2.gh (19.8 KB)

It’s great, but unfortunately I can’t use external components in my workflow.

However, you gave me an idea for something like this:

It operates exclusively on whole numbers, but it can be changed by changing the conversion from int to float, should there be a need. And it also doesn’t repeat while the button is pressed, like your solution does.

Code
import Grasshopper

from Grasshopper.Kernel.Special import GH_Panel



if x:


    for obj in Grasshopper.Instances.ActiveDocument.Objects:

        if isinstance(obj, GH_Panel):

            if obj.NickName == "Bomb":

                obj.SetUserText(str(int(obj.UserText)+x))


if y:


    for obj in Grasshopper.Instances.ActiveDocument.Objects:

        if isinstance(obj, GH_Panel):

            if obj.NickName == "Bomb":

                obj.SetUserText(str(int(obj.UserText)+y))
Additional detail

Or like this for probably marginally better performance :skull_and_crossbones:

I am guessing bomb is a term of art here?

It only repeats after a specific delay (that you can set) of holding down the button. No control over the speed though. :thinking:

Yeah, that’s the first word that came into my mind :distorted_face:

Lol, so, no.


A reset button would be useful. But then you would have to save the original values of the panels. Glad I could provide some inspiration!

Sorry, I didn’t notice your edit. Would this suffice?

set-save-reset panel.gh (6.4 KB)

Code
import Grasshopper

from Grasshopper.Kernel.Special import GH_Panel

pan = 0

if "saved_value" not in globals():

    saved_value = 0

for obj in Grasshopper.Instances.ActiveDocument.Objects:

    if isinstance(obj, GH_Panel):

        if obj.NickName == "Bob":

        pan = obj

if x:

    pan.SetUserText(str(int(pan.UserText)+x))

if y:

    pan.SetUserText(str(int(pan.UserText)+y))

if save:

    saved_value = pan.UserText

if reset:

    pan.SetUserText(default)

saved = saved_value