So what I have is 2 sets of objects distributed roughly into 2 grids, 1 in front of the other. I want to select each of the objects in the back (cubes) and merge them with the object roughly in front of them (spheres).
The objects in these arrays all have different geometries (The spheres and cubes are just an example) and their origins are not aligned but the one consistent thing is that their origins are always contained in a 15x15x15 area. e.g the bottom, middle sphere is always between (-7.5, -7.5, -7.5) and (7.5, 7.5, 7.5). I already got a scrip to detect if an object is contained between those coordinates from another unrelated question:
import bpy
from mathutils import Vector
def IsInBoundingVectors(vector_check, vector1, vector2):
# if vector_check is either bigger or smaller than both other, it does not lie between them
# in that case it won't be inside the bounding box; hence return false
for i in range(0, 3):
if (vector_check[i] < vector1[i] and vector_check[i] < vector2[i]
or vector_check[i] > vector1[i] and vector_check[i] > vector2[i]):
return False
return True
So what I need it to do is some kind of cycle where it selects the first object (bottom, left) in the back and merges it with the object in front (which has the same rough coordinates except the Y is +15 in both cases), and then moves to the next one. When it's done with one row it jumps to the start of the next one.
I assume this is possible if I manually declare 4 variables for the starting set of coordinates and the width and height of the grid, i.e '(-22.5, -22.5, -7.5)', '(-7.5, -7.5, 7.5)', '3' and '3' in this case. But I'm pretty new to python/programing so I have no any idea how to declare the variables and add to them or use them to make the cycle.
Any pointers on how to do this?
I would also want to restrict the script to only the objects on the grids since there will be others in the file. I can put them all in a specifically names collection if it's needed for that or start with them selected