Search - User list
Full Version: Renaming objects in alembic files
Root » Technical Discussion » Renaming objects in alembic files
larkis
Hello, I'm not well versed in this aspect of houdini yet need to manipulate some data coming in from alembic which was written out of maya. The (many) objects in the file follow this pattern "/Boy_B_rig_v001:body_SUBD/Boy_B_rig_v001:body_SUBDShape" What I want to do is take the first part "Boy_B" and write that as a new name, so the alembic rop at the end writes out a "washed" abc that only has the names without the rest of the garbage. I would also be fine with just maintaining the first namespace which is "Boy_B_rig_v001" and write that for every object in the incoming abc.

What would be the workflow for this? Any help would be greatly appreciated.
Italimpex Productions
Hello. I recommend splitting the attribute by a colon so it becomes Boy_B_rig_v001. It will get complicated if we try to shorten further than that. I assume other objects are going to follow the same naming convention, and it's always useful to keep the version. Drop down a Primitive Wrangle node and paste the code below. It will split the path attribute by the colon sign, take the first item of the created array, delete remaining slashes, and store it into the path string. (If your geometry uses the name attribute instead of path, just swap s@path for s@name in the code).

s@path = strip(split(s@path, ":")[0], "/");

I hope this helps!
larkis
Italimpex Productions
Hello. I recommend splitting the attribute by a colon so it becomes Boy_B_rig_v001. It will get complicated if we try to shorten further than that. I assume other objects are going to follow the same naming convention, and it's always useful to keep the version. Drop down a Primitive Wrangle node and paste the code below. It will split the path attribute by the colon sign, take the first item of the created array, delete remaining slashes, and store it into the path string. (If your geometry uses the name attribute instead of path, just swap s@path for s@name in the code).

s@path = strip(split(s@path, ":")[0], "/");

I hope this helps!

Thank you. I ended up doing something similar because I needed to have the name repeated twice in order for maya to pick up the names

string raw = s@path;
string first = split(raw, "/");
string ns = split(first, ":");
s@path = "/" + ns + "/" + ns;

This gives me Boy_B_rig_v001/Boy_B_rig_v001 which works. Just curious, why did you use the strip function instead of just splitting the string directly?
Liesbeth_Levick
Edit: I started writing this before your reply and only saw it after I posted it.

It's not entirely clear to me from your post what you are trying to do. Do you want your final attribute to be "Boy_B_rig_v001"? Because then the reply above will work. However, it seems more likely to me that you would want to extract the useful name from each object such as "body". If that is the case here are some things you can do.

If your path is
/blah/blah../blah/Boy_B_rig_v001:body_SUBD/Boy_B_rig_v001:body_SUBDShape
and you want a name attribute
Boy_B_rig_v001:body_SUBD
then you can use a Muscle ID SOP with the Attribute Name set to `name` , Initialize from Input Attribute Toggled on, and Element Pos fom End set to 1. This will extract the second to last entry in the path attribute and store it as a name attribute.


If you wanted to clean the namespace from the name then you can use an Attribute String Edit SOP. Specify `name` in the Primitives field, and then it the Editor tab, in the From field put "Boy_B_rig_v001:*", and in To put "*". If you also wanted to remove the "_SUBD" you can instead put "Boy_B_rig_v001:*_SUBD" in the From field.


If you want your name to overwrite your path attribute, then you can use an Attribute Rename SOP, go to the Primitive tab, specify your From/To attributes, and toggle on Overwrite Existing Attributes.


Hope that answers your question!
Italimpex Productions
In my code the order of execution is
1. split(s@path, ":") which splits s@path into 3 strings ( /Boy_B_rig_v001, body_SUBD/Boy_B_rig_v001, body_SUBDShape )
2. extracts the first item /Boy_B_rig_v001

3. and last comes strip() which only removed forward slash. It's an optional step. Leaving it out wouldn't make a practical difference. Path would just remain /Boy_B_rig_v001 instead of Boy_B_rig_v001. ROP Alembic will add a leading slash anyway.

Either way, in ROP Alembic, you must check "Build Hierarchy from Attribute" toggle with Path Attribute set to "path" to actually write to disk with that modified path attribute. Otherwise Houdini will generate default internal path like "/geo1/attribwrangle1".

In your code you could completely drop that second line and write it like this:
string raw = s@path;
string ns = split(raw, ":")[0]; // returns "/Boy_B_rig_v001"
s@path = ns + ns; // previous line carries a slash (/Boy_B_rig_v001) so we don't write "/" + ns + "/" + ns

I hope this helps!
larkis
Awesome, thank you for the help guys.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.