@andheum, thanks for the updated component! Thatās super handy! For this exploration, Iām not sure that getās me what Iām shooting for. For example, a python component returns as a ZuiPythonComponent, as oppossed to the āNameā? A fair bit of our custom components are python basedā¦(maybe this is an indicator that we should move beyond python?!)
One of the goals of this little side-project of mine, is to ultimately try to operate from outside of a rhino/GH environment. (of course, that logic immediately breaks down because my current efforts are dependent on using a gh component that @DavidRutten wrote to convert GH files to GHX). I also acknowledge that this side project is a little outside of the bounds of this forum.
I am hoping that, if we can assemble a reasonably accurate data set of what components people in our office are using the most, we can get a better understanding of common tasks/workflows that our designers are using. Then we can adapt our training focus and workflows based on what people are trying to do. I also have an image in my mind of some type of dataviz of this dataset. At any rate, I spent a little time on it this evening and came up with a version that outputs to a csv. Not entirely sure itās the best structure yet, but ultimately, we can dump it into a Database and the let the DB server handle the heavy lifting of responding to queries.
"""Testing method to read GHX files outside of a rhino/GH environment
Successfully tested with Python Ver 3.6.3, (NOT IRON PYTHON).
GOALS: 1 - Iterate project folders on network server to find grasshopper files and write to a data set of used components
2 - Visualize/chart data
REQUIRES: conversion of GH file to GHX (ideally we should write our own version of this....)
http://www.grasshopper3d.com/forum/topics/batch-convert-gh-ghx-files
ASSUMPTIONS: Parsing raw xml files is faster than methods dependent on Rhino/GH environment.
We can use existing data visualization frameworks, (highcharts), to visualize/drill down into data
"""
import csv
import os
from fnmatch import fnmatch
import xml.etree.ElementTree as ET
import collections
root = "D:/Documents/02_MyITProjects/_Grasshopper/GHSTuff_Hanley/GHCONVERTED"
pattern = "*.ghx"
comps = []
try:
with open("D:/Documents/02_MyITProjects/_Grasshopper/GHSTuff_Hanley/GHCONVERTED/output.csv", "w", newline='' ) as output:
writer = csv.writer(output)
writer.writerow(['Name', 'Count', 'Filename'])
for path, subdirs, files in os.walk(root):
for name in files:
if fnmatch(name, pattern):
f = os.path.join(path, name)
root = ET.parse(f)
for i in root.iterfind('chunks/chunk/chunks/chunk/chunks/chunk/chunks/chunk/items'):
for line in i:
thing = line.attrib.get('name')
thing2 = line.text
if thing == "Name":
comps.append(thing2)
counter = collections.Counter(comps)
for key, val in counter.items():
writer.writerow([key, val, f])
print ("Processing: ", counter)
del comps[:]
except ValueError:
print("something went wrong....sorry about that")
Lastly, I am posting this more of a record of efforts using this particular method. At this point, I am not expecting any assistance from the folks at mcneel. Although, I do think some type of builtin method to generate this data would be interestingā¦
Attached is the csv output I am getting at this pointā¦apparently we canāt upload csv files? hereās a screen shot.
component name | count per file | file name