## Recommended Posts

I have a grid, and I scatter points on it using the scatter sop.

I want to access the number of scattered points per each prim of the grid.

What's the most efficient way to achieve this?

My current workaround contains a foreach loop, that creates "bounds" using the bounds sop per each prim, and groups scattered points using the "Bounding Object" bounding type. Then I write the count of points as a primitive attribute using a wrangle. This is very slow - would love to know how else to achieve this..

##### Share on other sites

on the scatter, under Output atributes, turn on Prim Num Attribute

then use a primitivewrangle, plug the grid into the first and scatter into second input:

`i@scattered = findattribvalcount(1, "point", "sourceprim", @primnum);`

• 1

##### Share on other sites

Wow, this is amazing. What if I want to access the average @P of all points on the prim?

##### Share on other sites

same wrangle, add following lines of code

```vector avg = {0,0,0};
for(int i = 0; i!=@scattered; ++i)
{
int pt = findattribval(1, "point", "sourceprim", @primnum, i);
vector p = point(1, "P", pt);
avg += p;
}
avg /= float(@scattered);
v@avgP = avg;```

• 1

##### Share on other sites

seems to show {0,0,0} for each avgP

##### Share on other sites

With a little modification and correction, seems to work perfectly.

Thank you sir!

```int scattered = findattribvalcount(1, "point", "sourceprim", @primnum);

vector avg = {0,0,0};
for(int i = 0; i<scattered; i++)
{
int pt = findattribval(1, "point", "sourceprim", @primnum, i);
vector p = point(1, "P", pt);
avg += p;
}
avg /= float(scattered);
v@avgP = avg;```

• 1

## Create an account

Register a new account