Script/Line Counter

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.

pyCount.gh (12.3 KB)

2 Likes

Awesome! I’m interested in these stats for my own scripts though 90% of mine are Python3.

I’ll try and see if I can poke around and get it working with Python 3

1 Like

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:

2 Likes

Hi @eirannejad,

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)

Thank you!

2 Likes

It is undocumented API as of now but you can get the Text property

3 Likes

Awesome, thank you!

1 Like