I found the excellent tutorial from Patrick Boelens on cgcookie here:
I completed this tutorial with no problems, but what I really want to do is use an NxN matrix of non-primitive objects. Here is my working python from the tutorial that uses primitive_cube_add:
I’d like to remove this line:
bpy.ops.mesh.primitive_cube_add(location = (x, y, 0))
And replace it with some code that accomplishes the same thing but instead uses a custom mesh thats already in the scene. I’m not sure which api functions I’m after. I tried:
bpy.context.active_object.location = [x, y, 0]
While having my custom mesh selected. This does create duplicates of the object, but each copy of the object seems to have its location changed on the z axis only and each object copy is scaled on its x and y so they are all of different sizes which was unexpected. I’m not sure why its happening, but this is the first time I’ve touched the python api so I’m likely just missing something basic.
I also tried:
bpy.ops.object.add(type=‘MESH’, location=(x, y, 0))
This works correctly in terms of creating new objects (although they are empty “Mesh” objects) in the correct locations. I just want it to use my custom mesh instead of a placeholder mesh.
Can anybody give me a clue on how to replace the primitive_cube_add function with something that allows me to duplicate an existing scene object and change its location? I can provide some screenshots too if that would help.
EDIT: Figured it out, was a bit more convoluted than expected. Lots of trial and error until I got it working.