Get python code from grasshopper node as plain text


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.

Like in this screenshot someone of our team coded something in a node with python. Can we extract this python code as textfile?

In Python Editor->File->Export As->Save as type: All Files and add .txt at the end of your file name


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
        Name: {item,str}
        Keys: {list,str}
        Values: {list,str}
        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
                for k,v in zip(Keys,Values):
                    vli = gh.Kernel.Special.GH_ValueListItem(str(k),str('"' + v + '"'))
                if selected in Keys:
                    <item name="Description" type_name="gh_string" type_code="10">Populate Value List</item>

Have a look at the code I posted here, it demonstrates how to get the code of GHPython components and export this to .py files/make user objects: