I'm writing a simple script to rename an array of cameras to match a sequence on a grid so that I can plot GPS co-ordinate to them. See the screenshot below where I show what I want to happen.
I'm looking to rename the array of cameras so that they follow this pattern
1 2 3
4 5 6
But, when I run the script, invariably it outputs this:
1 2 3
6 3 4
Here's the .blend file example
https://drive.google.com/drive/folders/1emGQRb6LgLambTk0Y_7vIjouZ62gNbHq?usp=sharing.
When you hit "run" script, you'll it happen.
It doesn't matter how extensive the array is, the second, third fourth (and so on) rows start with the number which should end the row sequence, e.g. This is the output I get with an example larger array.
1 2 3 4 5
10 6 7 8 9
15 11 12 13 14
Here is the script that I am working on:
import bpy
cameras = bpy.context.selected_objects
TOL = 0.0001
if cameras:
cameras = sorted(cameras, key = lambda o: (-o.location.y, o.location.x))
y = cameras[0].location.y
for i, camera in enumerate(cameras):
if abs(camera.location.y - y) > TOL:
z = camera.location.y
camera.name = "%d" % (i+1)
i
infor
loop starts with 0 so you are lying in your question. The script should give you names 0, 1, 2, 3 ... It seems to work fine as well. Maybe there is some problem with the camera objects. Maybe the cameras have delta transforms or something else like constraints effecting their location?.. $\endgroup$