Another alternative approach could use two wrangles. The first would run on each mesh prim, and put the count value in a unique attribute on an ancestor primitive. Then the second wrangle would iterate over those ancestor prims, and sum the values together.
First wrangle (here we're counting the meshes on the "grandparent" prim):
// Get Point Count
vector pts[] = usd_attrib(0, @primpath, "points");
// Get mesh prim's name, as well as parent prim's name, to
// place a unique attribute on the "grand-parent" prim.
string parent = usd_parentpath(0, @primpath);
string grandparent = usd_parentpath(0, parent);
// Add and set counter attribute on the grandparent prim
string attrib = "counter_"+usd_name(0,parent)+"_"+usd_name(0, @primpath);
usd_addattrib(0, grandparent, attrib, "int");
usd_setattrib(0, grandparent, attrib, len(pts));
Second wrangle:
string attribs[] = usd_attribnames(0, @primpath);
string prefix = "counter_";
int total = 0;
foreach(string attr; attribs)
{
if (startswith(attr, prefix)==1)
{
total += usd_attrib(0, @primpath, attr);
}
}
i@totalMeshCount= total;
Might be useful until getting child prims is possible!