read elements of attributes in vex

   8433   6   0
User Avatar
Member
56 posts
Joined: June 2016
Offline
hello,

with the attribute create SOP it is possible to give an attribute (f.e. pointattribute as integer) a size. in the spreadsheet it appears now as
myattrib[0], myattrib[1],...
and so on. in hscript i am able to read this data with $MYATTRIB1 and $MYATTRIB2. but i cant find out how I could read the attribute in wrangle SOP (or in VOPs).

If I try
i@cloner = i@myattrib;
it reads the first element, but whatever I try, nothings seems to work to get the other elements, and i can't find anything in the docs (maybe i don't know what to search for). i know it works if the attribute is a vector or a matrix (v@myattrib.r). but in this case none of these work:
i@cloner = i@double.r; 
i@cloner = i@double.1;
i@cloner = i@double1;

why is that and where do i have to look in the docs?
thx!

e// added hipnc for better understanding
Edited by Xue_Yue - June 15, 2016 08:21:51

Attachments:
access_elements_attribute_in_vex.hipnc (61.5 KB)

User Avatar
Member
45 posts
Joined: Feb. 2008
Offline
You can create an array and get elements of array
i[]@boo = { 0, 2, 6, 4, 6};
@P.x = @boo[ 2];

Or you can use vector, and get components by .x, .y, .z, for example

v@new_vector = { 4, 5, 6};
@P.y = @new_vector.z;
Edited by envil - June 15, 2016 08:23:47
User Avatar
Member
56 posts
Joined: June 2016
Offline
hello and thanks for the reply.

i am aware that this works on vectors, matrices and arrays but i wondered how to access elements of the attributes if it is set up like this. the attributes are there, so i thought there might be a way to access them with vex, i just don't know how. it should be possible, right?


i added an example hipnc for better understanding in my first post.

User Avatar
Member
45 posts
Joined: Feb. 2008
Offline
v@cloner = set(u@double.x,0,0);

help:

http://archive.sidefx.com/docs/houdini15.5/vex/snippets [archive.sidefx.com]
Edited by envil - June 15, 2016 14:49:41
User Avatar
Member
56 posts
Joined: June 2016
Offline
Hey, thanks that helped me. Playing with that I also found out that this also works:
f@a = v@myattrib[0];
f@b = v@myattrib[1];
f@c = v@myattrib[2];

I didn't knew the “u@” datatype you used, but I with that I found that it also works with “p@”, which seems to be a vector with 4 floats.
f@a = p@myattrib[0];
f@b = p@myattrib[1];
f@c = p@myattrib[2];
f@c = p@myattrib[3];

But just for clarification, this just works because I'm interpreting the elements of “myattrib” as u(2 floats), v(3 floats), p(4floats). Right? If “myattrib” would have more elements (there is no limitation in the Attribute_Create SOP) I would not be able to import these. Or maybe with a differtent solution.

Consequently I am also not able to change all attribute elements
i@myattrib[3] = set(1); // error: ambiguous call to array index operator
f@myattrib[3] = set(1); // error: ambiguous call to array index operator
p@myattrib[0] = set(1); // works: sets first element to 1
p@myattrib[3] = set(1); // works: sets fourth element to 1
p@myattrib[4] = set(1); // also sets fourth element to 1, because p can only reach 4 floats (myattrib[3] in this case).


Thanks again for the help, I appreciate the effort.
User Avatar
Member
453 posts
Joined: Feb. 2013
Online
Hi, out of curiosity, has this ever been addressed?
I tested on 16.0.666 and it seems to not work as expected for something like:

i@myattrib[5] = set(1);

Basically it seems to still be like Xue_Yue described in the post above.
Edited by DASD - Oct. 30, 2017 02:33:41
User Avatar
Member
8539 posts
Joined: July 2007
Online
I'm not sure if it's possible to access such attributes through VEX, I'd advise using array attributes instead
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links