Setting the entries in a value list?

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
        Name: {item,str}
        Keys: {list,str}
        Values: {list,str}
        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
                for k,v in zip(Keys,Values):
                    vli = gh.Kernel.Special.GH_ValueListItem(str(k),str('"' + v + '"'))
                if selected in Keys:

PVL_2024Jan4a (9.1 KB)

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