Hello. That code doesn't work because it finds the number of vertices for each primitive, and not for each piece. It will delete entire tree once it crosses threshold primvertexcount(0, @primnum) <= 3. However, there aren't any polygons in your mesh with 20 vertices. Condition will get evaluated as false and nothing will be deleted.
To fix this, code needs to be aware of the pieces and not just individual prims. I'd drop Connectivity with "Primitive" type to get i@class which we will then use in primitive wrangle. Then we count the number of prims that share the same class value. Leaves have the least number of polygons so they're the ones that get detected first.
int prim_count = findattribvalcount(0, "primitive", "class", i@class);
if(prim_count <= chi("thresh")){
removeprim(0, @primnum, 1);
}
This method also works with SpeedTree's trees. You can optionally drop Fuse before Connectivity. Some trees from SpeedTree have these separated caps on small branches that kept getting flagged by this vex condition. Based on the image I don't think you will have that issue.
I hope it helps!