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
Question about changing 'attribute' inside a for loop.
2055 4 0- govindk
- Member
- 13 posts
- Joined: Jan. 2019
- Offline
- PatW
- 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.
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.
- govindk
- Member
- 13 posts
- Joined: Jan. 2019
- Offline
- tamte
- Member
- 8784 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:
or potentially with all previous points removed with their prims (provided there were no isolated points)
or also using Enumerate SOP + Extract Centroid SOP (using index as piece attribute)
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
FX Supervisor
Method Studios, NY
- govindk
- Member
- 13 posts
- Joined: Jan. 2019
- Offline
-
- Quick Links