usd_setattrib Doesn't Accept Generic Data Types

   393   0   0
User Avatar
Member
15 posts
Joined: Sept. 2023
Offline
I'm trying to copy some USD attributes using a LOP Attribute Wrangle. I can use usd_addattrib and usd_attribtypename just fine. However, If I want to set the copied attributes, I HAVE to write a bunch of conditionals to check the typename before setting them.

This is the USD file content:
#usda 1.0
(
defaultPrim = "attribs"
)
def "attribs"{
custom string someString = "test"
custom float someFloat = 1
}

This is how I have to copy the attributes, which is not so ideal:
string attributes[] = usd_attribnames(0, @primpath);

for(int i = 0; i < len(attributes); i++)
{
    string attribName = attributes[i];
    string attribType = usd_attribtypename(0, @primpath, attribName);
    string copiedAttribName = attribName + "Copy";
    usd_addattrib(0,  @primpath, copiedAttribName, attribType);
    if(attribType == "float")
    {
        float attribVal = usd_attrib(0,  @primpath, attribName);
        usd_setattrib(0,  @primpath, copiedAttribName, attribVal);
    }
    else if (attribType == "string")
    {
        string attribVal = usd_attrib(0,  @primpath, attribName);
        usd_setattrib(0,  @primpath, copiedAttribName, attribVal);
    }
    
    // THIS RESULTS IN AN ERROR
    //usd_setattrib(0,  @primpath, copiedAttribName, usd_attrib(0,  @primpath, attribName));
}

Is there some way I can just copy all the attributes without having to specify their type first?

Attachments:
before-after.png (58.0 KB)
network.png (99.5 KB)
sample.usda (134 bytes)

  • Quick Links