I’m developing a system of Python nodes in Grasshopper for my own larger sketch that will:
- Read variables from comma-delimited files (format: var_name, value), example:
- ant,1
- bat,true
- cat,4.56799
- dog,This is a string
- elk,180
- …
- Store these values in a dictionary
- Output each variable to dedicated, named outputs
Key Requirements:
- Each file contains 20-100+ variables (mixture of ints, floats, strings, and booleans)
- Output names must match the variable names from the files for readability
- Core Python code will be common across all nodes, with a unique “key_id” input to distinguish the sc.sticky dictionary entries
Challenge:
Creating and maintaining the hundreds of Python outputs manually in Grasshopper is tedious and error-prone.
Proposed Solution:
I’m considering building an external .ghx generator in Java that would:
- Write the XML file structure of a file containing only the single element.
- Save it as a template (e.g., “body.ghx”)
- Create an empty Python node with all the correctly named inputs/outputs
- Allow me to insert the common Python code when pasted into my larger Grasshopper definition. Allow for rebuilding when the master variable file is updated.
Has anyone attempted something similar or have suggestions for a better approach? Any input on .ghx file generation or more efficient ways to handle multiple named outputs would be appreciated.