Question about changing 'attribute' inside a for loop.

   2058   4   0
User Avatar
Member
13 posts
Joined: Jan. 2019
Offline
Hello all,

I'll get straight to it, so I have a primitive cube from which I am extracting the points, looping though and creating new point at the prim's center - all good thus far. However, when I change the @Cd the original 8 points on the cube changed but not the points that got created inside the for loop. I did solve the issue (image attached), however I feel my solution is inelegant and I am missing something obvious and still not sure why the @Cd wasn't affecting the newly created points inside the for loop.

Thank you for looking into it and appreciate any advice on the right track.
Regards,
-G
Edited by govindk - Sept. 25, 2021 08:21:33

Attachments:
houdini_question.png (122.7 KB)
primPoints_colour.hip (140.5 KB)
solved.png (109.4 KB)

User Avatar
Member
18 posts
Joined: Nov. 2013
Offline
When you use attribute wrangle node to run over points, the @attribute_name syntax is bound to attribute of current point being processed. That's why setting v@Cd affect the original point. To set attribute of a new point, you have to use setpointattrib() instead.

int pt = addpoint(0, pos);
setpointattrib(0, "Cd", pt, {1,0,0});

Which is close to the second image. In fact, i@group_name is also bound to current point, not the new point.
"if(i@group_cpt = 1)" will always be "true" as you are assigning i@group_cpt to 1 here.
User Avatar
Member
13 posts
Joined: Jan. 2019
Offline
I see the gap in my understanding.
So in this case the creating the group was unnecessary it seems like, because I can simply use setpointattrib()

Thank you for the explanation PatW, appreciate it.
User Avatar
Member
8786 posts
Joined: July 2007
Offline
your code will create duplicated overlapping points per prim
regardless of the v@Cd problem which has been explained, you can create points at prim centroids in prim wrangle either as additional points:
int pt = addpoint(0, @P);
removeprim(0, @primnum, 0);

or potentially with all previous points removed with their prims (provided there were no isolated points)
int pt = addpoint(0, @P);
removeprim(0, @primnum, 1);

or also using Enumerate SOP + Extract Centroid SOP (using index as piece attribute)
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
13 posts
Joined: Jan. 2019
Offline
Thank you for the additional information Tomas. I was using a fuse node after the wrangle, these options you mentioned really helps.
  • Quick Links