vex usd_childpath()

   2337   4   1
User Avatar
Member
23 posts
Joined: Sept. 2021
Offline
Hi,

I noticed there's a usd_parentpath() function but no usd_childpath()/usd_childrenpaths() function. I'm guessing this has to do with the wrangle being multithreading safe, but how would I go about the following problem otherwise:

All children prims hold an attribute (like polygon count) and I want to sum those up and write the sum as an attribute on the parent primitive.
User Avatar
Staff
1448 posts
Joined: July 2005
Offline
I've added an RFE for the `usd_childrennames()` VEX function.

If you know the children names, you can form the child path by appending "/" and a child name to the parent's path.

Otherwise, as a workaround for this task, you can try the Python LOP.

EDIT: RFE number is 116741
Edited by rafal - Oct. 19, 2021 18:11:24
User Avatar
Member
23 posts
Joined: Sept. 2021
Offline
Cool!
Yeah we worked around with python - In general I prefer vex though, thanks for the RFE
User Avatar
Staff
4159 posts
Joined: Sept. 2007
Offline
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!
I'm o.d.d.
User Avatar
Member
8525 posts
Joined: July 2007
Online
Would also be cool if ust_setattrib() supported modes like "add", "append", ... Like setattrib() functions do
Then the second wrangle could be avoided in cases like this
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links