Skip to main content
added 155 characters in body
Source Link

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?

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")

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?

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?

added 2 characters in body
Source Link

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:

     if dcam.name == "PERSP.Camera":
         break
     else:
         bpy.data.cameras.new("PERSP.Camera")
for dcam in bpy.data.cameras:
     if dcam.name == "PERSP.Camera":
         break
     else:
         bpy.data.cameras.new("PERSP.Camera")

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?

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:

     if dcam.name == "PERSP.Camera":
         break
     else:
         bpy.data.cameras.new("PERSP.Camera")

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?

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")

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?

Source Link

Blender API - Use data-block name as if condition

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:

     if dcam.name == "PERSP.Camera":
         break
     else:
         bpy.data.cameras.new("PERSP.Camera")

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?