Setting the entries in a value list?

Why not use two item selectors? I actually find that if I plug in all 1384 names my GH freezes for like 30 seconds and it would be a way too long list to scroll.

I would use 2 selectors and remove the “All” category first, since that would mean in the names list you have everything twice, since All contains all the others anyways.

polyheadra_names.gh (5.6 KB)

1 Like

:man_facepalming: of course, thank you!

1 Like

I’ve just created a GH model that displays ALL the polyhedra by branch in a grid. Very cool to see them. I think my favorite is the “Rhombic Icosahedron ” which has 20 equal size diamond shaped faces. It is [index = 15] in category “Other Solids” [index = 17].

Boo Hoo. :cry: I just tried your old reliable PVL (PopulateValueList) Python component using R7 and it fails with the following error:

Runtime error (MissingMemberException): 'NoneType' object has no attribute 'Name'

Traceback:
  line 25, in script

What happened? This was really useful, and simple. Any help please :question:

"""
Populate Value List
    Inputs:
        Name: {item,str}
        Keys: {list,str}
        Values: {list,str}
    Outputs:
    Remarks:
        Author: Anders Holden Deleuran (BIG IDEAS)
        Rhino: 6.30.20266.14531
        Version: 210108
"""

ghenv.Component.Name = "PopulateValueList"
ghenv.Component.NickName = "PVL"

import Grasshopper as gh

if not Values:
    Values = Keys
if Keys and Values:
    for obj in ghenv.Component.OnPingDocument().Objects:
        if type(obj) is gh.Kernel.Special.GH_ValueList:
            if obj.NickName == Name:
                selected = obj.FirstSelectedItem.Name
                obj.ListItems.Clear()
                for k,v in zip(Keys,Values):
                    vli = gh.Kernel.Special.GH_ValueListItem(str(k),str('"' + v + '"'))
                    obj.ListItems.Add(vli)
                if selected in Keys:
                    obj.SelectItem(Keys.index(selected))
                obj.ExpireSolution(True)

PVL_2024Jan1a
PVL_2024Jan1a.gh (13.9 KB)

1 Like

Will this ever work again? Broken now in R7. :cry:

The latest file posted above appears to work on my system with Rhino 7 (7.36.23346.16351, 2023-12-12):

Which file would that be? I know how it’s supposed to work as I’ve been using it for years, so the video is no help. As I reported three days ago, it doesn’t work anymore.

  1. Solution exception:‘NoneType’ object has no attribute ‘Name’
  1. Solution exception:unsupported operand type(s) for +: ‘str’ and ‘float’

The file name is in the top left corner of the Grasshopper window in the recording. It’s the second one here.

I’m not sure what to tell you, I just ran my latest file (i.e. 210108_PopulateValueList_02.gh) with the latest Rhino 7 update (i.e. in the video I just posted) and it seemed to work :man_shrugging:

Edit: I just saw your post above, and it looks like you’re using two PVL components hooked up to the same inputs, one of which has no Values input. These conditions combined will likely cause all sorts of time-sequence issues.

OK, so the critical error message is this one:

Runtime error (TypeErrorException): unsupported operand type(s) for +: ‘str’ and ‘float’

Traceback:
line 29, in script

Because integers are not allowed as values. This is line 29:

vli = gh.Kernel.Special.GH_ValueListItem(str(k),str('"' + v + '"'))

:man_facepalming: :roll_eyes: :cry:

P.S. This can easily be fixed by setting a Type hint of ‘str’ for the ‘Values’ input, or perhaps both.

The other error I reported when the Value List is empty is a bug that should be fixed:

Runtime error (MissingMemberException): ‘NoneType’ object has no attribute ‘Name’

Traceback:

  • line 25, in script*

This is line 25:

selected = obj.FirstSelectedItem.Name

This version of @AndersDeleuran’s PVL (PopulateValueList) Python component has changes to fix a few anomalies I encountered:

  1. Added code to accept only Keys. If no Values are are connected they will default to the Keys.
if not Values:
    Values = Keys
  1. Added Type hint = ‘str’ (String) to all three inputs, making it possible to use integers without error.

  2. Handle empty Value Lists by changing this:
    selected = obj.FirstSelectedItem.Name
    to this:
    selected = obj.FirstSelectedItem

"""
Populate Value List
    Inputs:
        Name: {item,str}
        Keys: {list,str}
        Values: {list,str}
    Outputs:
    Remarks:
        Author: Anders Holden Deleuran (BIG IDEAS)
        Rhino: 6.30.20266.14531
        Version: 210108
        misc. debugs by Joseph Oster, Jan 4, 2024
"""

ghenv.Component.Name = "PopulateValueList"
ghenv.Component.NickName = "PVL"

import Grasshopper as gh

if not Values:
    Values = Keys
if Keys and Values:
    for obj in ghenv.Component.OnPingDocument().Objects:
        if type(obj) is gh.Kernel.Special.GH_ValueList:
            if obj.NickName == Name:
                selected = obj.FirstSelectedItem
                obj.ListItems.Clear()
                for k,v in zip(Keys,Values):
                    vli = gh.Kernel.Special.GH_ValueListItem(str(k),str('"' + v + '"'))
                    obj.ListItems.Add(vli)
                if selected in Keys:
                    obj.SelectItem(Keys.index(selected))
                obj.ExpireSolution(True)

PVL_2024Jan4a
PVL_2024Jan4a.gh (9.1 KB)

Please contact me if there are further Python refinements to be made.

I’m just gonna quite myself from three years ago here:

:wink: … but specifically to your points:

I’d argue this is “anomalous” behavior, unless documented of course. If one wants the keys to be also be the values, one can wire the input data to both inputs.

The component docstring explicitly states that the Keys and Values are both lists of strings. But I’d agree that is limiting. I think we might have covered this above or elsewhere if I recall. Anywho, one can change line 29 to format the value like so (i.e. check if the value is an integer or a number):


240104_PopulateValueList_00.gh (6.0 KB)

This way one can pass strings, floats or integers. And that’s actually what they will become inside the value list (i.e. numbers aren’t just strings with quotation marks). Note that integers might (i.e. depending on their origin) have to be explicitly cast using an integer component or by applying typehints.

I’m afraid I haven’t been able to reproduce this issue.

1 Like

In all cases, the changes I made were because I hit obstacles in the course of normal use, including empty Value Lists. You can create one by editing its contents and deleting all, but that’s not how it happened. Other errors (integers instead of strings) caused them to become empty, but it doesn’t matter how they became empty, the code didn’t handle the condition and recover, as it does now.

I fixed conditions that broke the code so badly that extraordinary steps were required to recover. In my experience, those are nasty bugs that can be avoided by prudent programming.

Meaning, whatever your normal use is. It’s futile to blame people for something not living up to specs and requirements that only exist in your head.

Again, I’d love to understand what is happening here. But you’d need to demonstrate it better (e.g. post a video capture).

The hero we deserve…

It sounds to me like you are writing from a theoretical, academic point of view rather than a practical one. My career as a programmer was always for real people trying to get something done. “Blocker bugs” were always unacceptable and they still are. I posted code three days ago that demonstrated these bugs, which IMHO is far better than any video, but you apparently ignored that.

I’m not sure why everything always has to be so confrontational with you, but it’s really tiring. Please stop @-ing me.

Wow! No point in using @AndersDeleuran when you ignore it anyway. How very bizarre :exclamation:

I didn’t post here or ping you for fun. I was trying to do something else when the cool code you shared years ago blew up and wouldn’t work.

Hey Guys!
I hope this help. I arrived at this thread looking into solving a related issue and thanks to @AndersDeleuran and @Joseph_Oster back and forth, solved my own.
I was looking for a component that, when triggered, would automatically produce a “valueList” “Checklist” with a number of items given an int input.


CheckList Generator.gh (11.4 KB)

5 Likes

Hi Guys,

Anyone know why this code doesn´t work in Rhino 8 script editor? It never fulfill this condition:
“if type(obj) is gh.Kernel.Special.GH_ValueList:”

Thank you in advance.

1 Like

Hi Josehp,

It doesn’t work neither. It never through for step 2 and doesn´t update the list.

Thank for your help.