Jump to content

VEX: How to find an attribute by partial name


Recommended Posts

Hello,
For context, I'm processing some FBX files for a specific attribute name. The issue I'm running into is this attribute's name is not consistent across all the source geometry, but they do all have in common a certain string within the attribute's name. (e.g. "Base_Color")
What I'm hoping to do in VEX is find a way to parse all attributes for a specific string, and then return what the value of that attribute is. I was looking into the "hasprimattrib" function, but that returns an integer only as far as I can tell.

Link to comment
Share on other sites

Posted (edited)

Thank you for the response!
Hmm, I might not have explained my issue very well haha. I'll upload an  example HIP file to hopefully convey the question better!
In regards to your answer, I don't believe that function can work in this context, as the exact name of the attribute will vary from asset to asset, and I believe the match func requires and exact name in order to work?

 

 

attribute_partial_name_example.hip

Edited by Flakked
Link to comment
Share on other sites

Hi JD,

append a primitive wrangle right after your merge1-node, that

  • puts all primitive attributes into an array and checks if they match the name Color
  • if their string is longer than 0, assign it to a variable named path and break out of the loop.

 

string attribs[] = detailintrinsic(0,"primitiveattributes");

string path;
foreach(string a; attribs){
    if(match('*Color*', a)){
        string path_n = prim(0, a, i@primnum);
        if(len(path_n)>0){
            path = path_n;
            removeattrib(0, 'prim', a);
            break;
        }
    }
}

s@path = path;

attribute_partial_name_example_KM.hipnc

Edited by konstantin magnus
  • Like 2
Link to comment
Share on other sites

On 1/5/2024 at 6:12 PM, konstantin magnus said:

Hi JD,

append a primitive wrangle right after your merge1-node, that

  • puts all primitive attributes into an array and checks if they match the name Color
  • if their string is longer than 0, assign it to a variable named path and break out of the loop.

 

string attribs[] = detailintrinsic(0,"primitiveattributes");

string path;
foreach(string a; attribs){
    if(match('*Color*', a)){
        string path_n = prim(0, a, i@primnum);
        if(len(path_n)>0){
            path = path_n;
            removeattrib(0, 'prim', a);
            break;
        }
    }
}

s@path = path;

attribute_partial_name_example_KM.hipnc 70.08 kB · 4 downloads

Ahh, thank you! I ended up coming up with a solution that also involved using the detailintrinsic, but I think your code is much cleaner haha. This is what I cobbled together if interested heh:
 

string attrib_name_array[] = detailintrinsic(0,"primitiveattributes");

// printf("%s", attrib_name_array);

foreach(int i; string attrib_current_name; attrib_name_array){
    if (match("*Base_Color*", attrib_current_name) == 1 && prim(0, attrib_current_name, @ptnum) != ""){
        s@texture_name = prim(0, attrib_current_name, @ptnum);
    }
}

 

Link to comment
Share on other sites

  • 1 month later...

Notice the Intrisinc Detail Memory usage... Usefull!

 

Notice also that if you take a Box primitive, increase the subd in one axe and revert back just one second after to the minimum, the SOP node occupies a footprint RAM 5 times what it should ! 

Like if the RAM never totally get properlly refreshed... That's is not as nice

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...