i’m part of a team which uses regularly grasshopper, Ironpython, and Rhinocommon in our workflow. We want to analyse our codebase, which is saved as python files but also as python within the Grasshopper script files. Is there a possibility to acces a *.gh file from outside of Rhino with Python or C# and find Nodes within a *.gh file, which consist of python code and extract this code as plain text file.
If you save your GH files as ‘.ghx’ (XML) instead of ‘gh’ (binary), you can open the files with a text editor and find the Python bits.
<item name="CodeInput" type_name="gh_string" type_code="10">"""
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)</item>
<item name="Description" type_name="gh_string" type_code="10">Populate Value List</item>