remove points from group based on attribute?

   2460   3   0
User Avatar
Member
10 posts
Joined: Sept. 2017
Offline
What I'm trying to do is remove certain points from a group based on an attribute they have.
Each point has an attribute called “placementType”, and it\f it's 0 I want to remove it from the group “stall cells”

I've got this in a pointWrangle

int success;

int startpoints = chi(“../attribcreate1/npts”); // get the number of points

for (int i=0; i < @startpoints; i++){
int att = pointattrib(0, “placementType”, i, success);
if(att == 0)
{
setpointgroup(0, “stall cells”, i, 0);
}
else
{
setpointgroup(0, “stall cells”, i, 0); //see if it even works
}
}

but this doesn't seem to even do anything. I've never done vex before, so this could be completely wrong. Any help?
User Avatar
Member
7803 posts
Joined: Sept. 2011
Offline
Unless you are trying to use a wrangle as exercise to learn how setpointgroup and pointattrib() are used, there are better easier ways to modify groups based on attribute value.

There are a number of things wrong with this code example:

Point wrangles are run over points, meaning that there is no cause to loop over the points to get/set values. Bound attributes are used for this purpose.

The main issue I see that prevents this code from working is ‘startpoints’ is declared, but ‘@startpoints’ is referenced, which instead of returning the value set for ‘startpoints’ would return the value of a bound float attribute named ‘startpoints’. Which would be 0.0 unless this previously existed.

A side issue that may just be a bad copy/paste is that the group name, ‘stall cells’ contains a space.

The basic way to do what you are after is to simply set the value of the group to its current value minus the value of your attribute.

for example in a point wrangle:

@group_stall_cells &= !i@placementType;

For a more intuitive method that does not require code, the group combine sop can be used to do such boolean operations.

For the equivalent operation with group combine:

Group (stall_cells) Equals (stall_cells) Subtraction With (@placementType)
User Avatar
Member
10 posts
Joined: Sept. 2017
Offline
Thank you that answered my question. What I'm planning to do is based on the placementType attribute, remove points surrounding the point from the group as well. Basically using those points to place items with different sizes without them overlapping, so each point is like a cell. So if the placementType is 2, it would remove 1 point next to it from the group, if it's 3 it would remove both points next to it, and based on the placementType it would place different sized objects. Would there be a way to access the previous/next point to check their attributes or remove them from the group?
User Avatar
Member
10 posts
Joined: Sept. 2017
Offline
Alright I got it to work with

setpointgroup(0, "stall_cells", (int)@ptnum + 1, 0, "set");
  • Quick Links