Jump to content
Krion

attribtype() - Distinguish Float from Vector

Recommended Posts

Hi,

I am copying attributes by looping over the attributes.

Unfortunetely this doesn't work: 

string detailattribs[] = detailintrinsic(1,"detailattributes");

foreach(string detailattrib; detailattribs){  
    setdetailattrib(0, detailattrib, detail(1, detailattrib, 0), "set");
}

So I have to specify the type like this:
 

string detailattribs[] = detailintrinsic(1,"detailattributes");

foreach(string detailattrib; detailattribs){
    int type = detailattribtype(1, detailattrib); 
  
    if(type==1){
        float val = detail(1, detailattrib, 0);
        setdetailattrib(0, detailattrib, val, "set");
    }
        if(type==0){
        int val = detail(1, detailattrib, 0);
        setdetailattrib(0, detailattrib, val, "set");
    }
}

The weird thing about the attribtype() function is that it uses one value for "Float or vector". 
I do only have floats and ints right now, but I'm still wondering: what if you want to do this for a vector?

Another sidequestion would be, is there a better way to do this?

Thanks, kind regards,

Share this post


Link to post
Share on other sites

Hi,

To filter it further you have to use attribsize():

https://www.sidefx.com/docs/houdini/vex/functions/attribsize.html

Returns

The size of an attribute’s type.

  • For a vector type, this is the number of components.

  • For an integer, float, or string, this returns 1.

  • For an array attribute, this returns the size of the tuples in the array. The tuple size is controlled by the Size parameter on the Attribute Create node.

 

The best way to copy attributes is by using the Attribute Copy SOP, it's much faster also.

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

Thanks Yunus,

I somehow didn't expect the Attribute Copy SOP to be able to handle wildcards... but it does handle them. I wonder how my brain works sometimes.
Anyway good to know about the attribsize() function. Thanks!

Edited by Krion

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×