So you’re just trying to count how many lines are in a given function? Since Dynamo 2.0 files are just JSON, you can parse it like any other JSON file. The script contained within a python node is a single string, complete with all newline (\n) and tab (\t) characters. If you identify the start and end of your function (start would be at ‘def’ and the end would be at the next line which is not indented, which is indicated by the lack of a tab character (or four spaces) after a newline character) then you will only have to count the number of newline characters to indicate how many lines are contained within the function. I don’t have access to a computer right now, but once I do I will update this with some clearer examples of what I mean.
Within the DYN file, all nodes are stored in a single “Nodes” key and the script is stored in the “Code” key of a single node. For example, here are three lines of code as they appear in the DYN file:
"Code": "import clr\r\nclr.AddReference('RevitAPI')\r\nfrom Autodesk.Revit.DB import *"
Here is how they would appear in the editor:
from Autodesk.Revit.DB import *
You can see that each line is separated by a carriage return (\r) and a line feed (\n). So, each line is followed by
\r\n if there is no indentation and
\r\n\t if there is one level of indentation (adding a tab character for each additional level of indentation if necessary).