Search Python code components in whole document

I heavily use Python components in Grasshopper but this becomes a maintainability problem if I want to find particular bits of code. Within a single Python component it is possible to make text searches (the “find and replace” dialog) and within the Grasshopper canvas I can also search for particular components by name, but neither are that helpful with the dozens or even hundreds of Python components I am using, often reusing fragments of code or even using the “sticky” module with makes it less clear which code depends on what.
Is there a way to search all the existing Python components of the Grasshopper document at once for matching text?
If this is not a feature (which I am doubtful it exists), are there any alternatives? Even just being able to get all the code as text in one place could help (Where are these scripts stored? Are they accessible?)

Hi YCoCg, welcome to forum. You have tagged Rhino 7, so I assume you are referring to GHPython components. In which case, one can use the ReplaceGHPythonString code posted here (last code block):

2 Likes

I write most of my grasshopper python outside of the grasshopper environment.
This lets me use the tooling of my ide while editing and plays nice with version control (git), but means the package is no longer contained to a single .gh file

The pattern I use involves adding the codepath to sys.path and calling functions.

# grasshopper python component
sys.path.append("./codeFolder")
from externalCode import func
output1, output2, output3 = func(input1, input2, input3)
# ./codeFolder/externalCode.py

def func(input1, input2, input3):
    # do processing
    return output1, output2, output3
1 Like