Skip to main content
added 136 characters in body
Source Link
Gorgious
  • 31.8k
  • 2
  • 50
  • 106

I think you're overcomplicating things with your loop. Try something like :

import bpy

cam_name = "PERSP.Camera"
cam = bpy.data.cameras.get(cam_name)
if cam is None:
    cam = bpy.data.cameras.new(cam_name)

bpy.data.cameras acts like a dictionary. You can use get to test if an element is inside it. If not, it will return None.

You can also use the slightly more pythonic but weirder

cam = bpy.data.cameras.get(cam_name) or bpy.data.cameras.new(cam_name)

I think you're overcomplicating things with your loop. Try something like :

import bpy

cam_name = "PERSP.Camera"
cam = bpy.data.cameras.get(cam_name)
if cam is None:
    cam = bpy.data.cameras.new(cam_name)

bpy.data.cameras acts like a dictionary. You can use get to test if an element is inside it. If not, it will return None.

I think you're overcomplicating things with your loop. Try something like :

import bpy

cam_name = "PERSP.Camera"
cam = bpy.data.cameras.get(cam_name)
if cam is None:
    cam = bpy.data.cameras.new(cam_name)

bpy.data.cameras acts like a dictionary. You can use get to test if an element is inside it. If not, it will return None.

You can also use the slightly more pythonic but weirder

cam = bpy.data.cameras.get(cam_name) or bpy.data.cameras.new(cam_name)

Source Link
Gorgious
  • 31.8k
  • 2
  • 50
  • 106

I think you're overcomplicating things with your loop. Try something like :

import bpy

cam_name = "PERSP.Camera"
cam = bpy.data.cameras.get(cam_name)
if cam is None:
    cam = bpy.data.cameras.new(cam_name)

bpy.data.cameras acts like a dictionary. You can use get to test if an element is inside it. If not, it will return None.