I'm trying to make a python script that searches for an existing camera data-block in the scene and creates it if not found.
I've gone with a rather simple code:
for dcam in bpy.data.cameras:
if dcam.name == "PERSP.Camera":
break
else:
bpy.data.cameras.new("PERSP.Camera")
However, what I've written will keep creating increments of "PERSP.Camera" despite the condition checking if there isn't already a camera with this name.
I'm relatively new to python. Am I missing something about data-blocks where their names cannot be accessed if they're within a loop/not linked to an object in the scene?
bpy.data.cameras
iterator, the code works. All other possible scenarios will make it not work as intended. $\endgroup$