Check if a variable belongs to an array of integers

Hi,

I am trying to use the palletizing script for a project. I have 12 positions on a layer that I need to place and I need to pick in one of two orientations from the pick point. I would like to use the item counter variable created by the palletizing template to determine which orientation I need to pick with.

So ideally my Array1 will be [3,5,6,9,11,12] and Array2 will be [1,2,4,7,8,10], I need to check which array the item counter belongs to with an if/statements so I can pick in one of two different orientations.

My question is how do I write the script to initialize my arrays and how do I check which array my item counter variable belongs to?

If you’re planning on these arrays expanding, then I would agree with your more scalable approach. If it’s just those very limited, discrete comparisons, I would probably just write a small function in a URScript file and call that, just for a cleaner look in Polyscope. But all I would do is just say

if(itemCount == 3 or itemCount == 5 or itemCount == 6 or itemCount == 9 or itemCount == 11 or itemCount == 12):
  return 1
  else return 2
end

If you need to be more explicit in your second array, then just look for those specific numbers. What you’re describing would involve passing the item count into a function, iterating over each element of the first array, checking if that element is equal to the itemCount. If you reach the end of the first array, then you iterate through the second. This approach makes sense for a large dataset, or for a dynamic dataset, but is unncessarily complex if you are, in essence, checking if a number is 1 of 6 choices.