fetching the 2nd element of a vector attribute using point()

   821   3   1
User Avatar
Member
89 posts
Joined: 2月 2013
オフライン
in attribute wrangler i have this script :

@P.y = point(1, "P", @ptnum);

so I want to fetch the P attr from other object (connected to input 1). It works as expected but since the P is vector, by default i can only get the 'x' component.

I want to fetch the 2nd component of P (which is y). I tried both of these codes but they're not working :

@P.y =  point(1, "P", @ptnum).y;
or
@P.y =  point(1, "P", @ptnum)[1];

to make it works , i have to break the script into 2 lines:
vector pos = point(1, "P", @ptnum);
@P.y = pos.y;

What is the problem with those single line scripts ?
Edited by metaclay2 - 2025年5月9日 23:36:41
User Avatar
Member
692 posts
Joined: 8月 2019
オフライン
float y = vector(point(0, "P", @ptnum)).y;
printf("%g\n", y);
User Avatar
Member
393 posts
Joined: 8月 2018
オフライン
The reason it doesn't work in your first one-line examples is that "@P.y" is not an attribute. "@P" is.
If you cast to a vector, you can then get the 'y'.

f@myvariable = vector(point(1,P,@ptnum)).y;

See: https://www.sidefx.com/docs/houdini/vex/lang.html#variable-casting [www.sidefx.com]
Edited by Mike_A - 2025年5月10日 14:42:44
User Avatar
Member
58 posts
Joined: 8月 2014
オフライン
Just to add to the answers above - I believe it's because the "point" function doesn't have a single, predefined return type - it *might* return a vector, or it might return a float or a string, depending on what input you plug in... explicitly casting it as in the above posts means VEX can know in advance that referencing a .y component is valid.

You can still assign directly to @P.y this way:
@P.y = vector(point(1, "P", @ptnum)).y;
Edited by VortexVFX - 2025年5月10日 17:35:13
Dan Wood
Vortex VFX Ltd
  • Quick Links