Anyone know why my i value isn't iterating by 1 each time? I made arrays of primitives by their group. I want to set a “primlevel” attribute for each primitive in an array / group that corresponds with its index value in the array, but it assigns each index in the array a value of 1 instead of incrementing.
//Arrays by Group
int leftstraights=array(@group_leftstraights);;
int rearcurves=array(@group_rearcurves);
int rightstraights=array(@group_rightstraights);
int frontcurves=array(@group_frontcurves);
foreach(int i; leftstraights){
int addattrib= setprimattrib(0, “primlevel”, @primnum, i, “set”);
}
Vex Foreach Loop issue
6380 3 1- GaryHanna
- Member
- 32 posts
- Joined: 1月 2017
- Offline
- goldleaf
- スタッフ
- 4200 posts
- Joined: 9月 2007
- Offline
It won't work because
Also, to get an integer array variable, the syntax is this (brackets after the variable):
Or maybe I've misunderstood what you're trying to achieve?
i@group_leftstraights
will always be an integer. The wrangle snippet is being run on each primitive, so that group/attr represents whether the current element is part of that group or not. You can see this if you save that array to an attribute (see the image attachment).Also, to get an integer array variable, the syntax is this (brackets after the variable):
int foobar[] = array(1,3,5,2,8,9,2,5);
Or maybe I've misunderstood what you're trying to achieve?
I'm o.d.d.
- GaryHanna
- Member
- 32 posts
- Joined: 1月 2017
- Offline
goldleaf
It won't work becausei@group_leftstraights
will always be an integer. The wrangle snippet is being run on each primitive, so that group/attr represents whether the current element is part of that group or not. You can see this if you save that array to an attribute (see the image attachment).
Also, to get an integer array variable, the syntax is this (brackets after the variable):int foobar[] = array(1,3,5,2,8,9,2,5);
Or maybe I've misunderstood what you're trying to achieve?
thanks, but the original code does have the brackets (I think the forum edited them out and the group settings work. It's just the int i in the foreach loop that's not incrementing in value setting the attribute to 1 across the board in the array vs. 1, 2, 3, etc.
- el_diablo
- Member
- 133 posts
- Joined: 7月 2005
- Offline
You are iterating across all primitives and then in a foreach loop over all primitives in a group each time. So for each primitive you are setting it to 1 exactly N times of the length of the group array. I would think thats not what you are trying to do . Rethink logic, or do everything in a detail wrangle to run only once.
-
- Quick Links