I have a silly little Python trinket to share and a question. I used to enjoy seeing thousands of organized components on my canvas, but the more comfortable I become with Python, the less I use. I’m missing that extra dopamine from checking Document Info.
This keeps track of the number of scripts, names and amount of code you’ve created. Also helpful for finding scripts you forgot the name of, or forgot to name.
The question: it’s working with the python 2 components, but can’t access the code of python 3 the same way. I thought maybe someone could add that functionality. It might also be nice to add c# as well, maybe vb too for the weirdos in the back.
That’s cool. And it’s funny to see the different ways to extract the relevant information. I wrote some code once that’s does something similar, but getting to the script code and checking component types quite differently, might be interesting to you:
Also, a more recent script that e.g. demonstrates how check for obsolete components:
How would one retrieve the script contents of the newer Python 3 component?
Relevant code:
# Check for RhinoCodePluginGH.Components.Python3Component
elif component_type == "RhinoCodePluginGH.Components.Python3Component":
# Try various possible attributes to get the script
script_source = getattr(obj, 'Code', None)
if script_source is None:
script_source = getattr(obj, 'ScriptSource', None)