Jump to content
Sign in to follow this  
logix1390

findattribval in for loop

Recommended Posts

hello,

I am currently studying findattribval vex function and I am trying to do the second example in the help docs here:

http://www.sidefx.com/docs/houdini/vex/functions/findattribval.html

 

I am trying to find point 10 with the id attribute and move it on the y axis by 2 and set the color of that point to red.

I am getting an error...

I will attach my scene for anyone that wants to take a look.

Thank you. 

findattribval.hipnc

Share this post


Link to post
Share on other sites

Hi,

Which version of Houdini are you running ? Seems from the doc that H17 allows findattribval to return an array, but from my doc in H16 or H16.5, the signature of that vex fiunction is only int.

So in my opinion, your Wrangle is getting an error because your for loop needs to iterate over an array, while you are feeding it with an integer...

In this case, I would recommend to work with findattribvalcount and then iterate with findattribval(0,"point","id",10, count). See their 3rd example :-)

 

 

Edited by StepbyStepVFX

Share this post


Link to post
Share on other sites

Hi Step, thank you for reply. I am currrently using h16 . I might be a little confused on how to get this working. Is there an example you can show me with find attribbval function?

Even with the third example I can't get it working properly. I am trying to make point 10 turn red and move it up on Y.

int count = findattribvalcount(0, "point", "id", 10);
int point_num;
for (int i = 0; i < count; i++) {
    point_num = findattribval(0, "point", "id", 10, i);
    @Cd=set(1,0,0);
    @P.y+=3;
}

This ends up doing it to all the points instead of point 10 only. 

Thank you.

 

Share this post


Link to post
Share on other sites

I tested 16.0 and 16.5....errors

H17 works fine.

For your last effort, try this:

int count = findattribvalcount(0, "point", "id", 10);
int point_num;
vector newpos;
for (int i = 0; i < count; i++) {
    point_num = findattribval(0, "point", "id", 10, i);
    setpointattrib(0, "Cd", point_num, {1,0,0}, "set");
    newpos = point(0, "P", point_num) + {0,3,0};
    setpointattrib(0, "P", point_num, newpos, "set");
    //@Cd=set(1,0,0);
    //@P.y+=3;
}

(note: even tho H17 works without errors...logically it is still wrong as it affects EVERYTHING......instead of just one point, hence it needs same logic as my solution above)

Share this post


Link to post
Share on other sites

Thank you Noobini , this works.

This is the first time I am using this function. Is it possible to get the second example in the help docs to work in 16.5 ?

Help docs example:

for (int point_num : findattribval(0, "point", "age", 10))
{
    // ...do something with the point...
}


I guess I am just trying to simplify this as much as possible for a better understanding. 

Thank you for the help

Share this post


Link to post
Share on other sites

No, the findattribval of 16 and 16.5 returns integers, and not arrays therefore the for loop cannot work properly (it does not know on what to iterate).

If you want to learn to learn VEX on Houdini version 16 and/or 16.5, refer to the docs of those versions, do not use the docs of H17 :-)

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
Sign in to follow this  

×