Jump to content

attribtype() - Distinguish Float from Vector


Krion

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,

Link to comment
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
Link to comment
Share on other sites

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
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...