1
$\begingroup$

I run a background script that:

  • deletes everything:

override = {'selected_bases': list(bpy.context.scene.object_bases)} bpy.ops.object.delete(override)

  • appends a camera, a mesh and a light as object to the scene from a blend file:

    with bpy.data.libraries.load(filepath) as (data_from, data_to): data_to.objects = data_from.objects print ("Objects added for map "+selectedmap+": " +str(data_to.objects))

  • sets the appended camera for the scene:

bpy.context.scene.camera = bpy.data.objects['Camera']

  • adds a bunch of cylinders

  • does a render of the objects in the blend file

  • saves the file:

bpy.ops.wm.save_mainfile(filepath=basepath + 'FPSPath.blend', check_existing=False)

  • then repeats again from, delete all

  • append another camera, mesh and light from a different blend file

  • render all again, but at this point the new camera does not seem to be selected as active, I do a bpy.context.scene.camera = bpy.data.objects['Camera'] after appending but, the render keeps coming back empty.

My print debug shows that the camera is changing name, (as camera.001 and so on) could that be the reason I am not getting anything on the render, is there a way to get any camera and then make it the active one?

Also the last blend file saved does not contain the camera, light or mesh objects I appended, should I add something else to the appending method? does it need anything else, the mesh object is never on the render, and only the first camera works.

Thanks.

$\endgroup$
5
  • $\begingroup$ Please provide more context, or it may be impossible to answer this question. $\endgroup$ Commented Jun 27, 2016 at 21:41
  • $\begingroup$ Sounds like you forgot saving the file after removing all objects as Sazerac mentioned, related: blender.stackexchange.com/a/27235/3710 $\endgroup$
    – p2or
    Commented Jun 28, 2016 at 8:40
  • $\begingroup$ I am using this to save: bpy.ops.wm.save_mainfile(filepath=basepath + 'map.blend', check_existing=False) $\endgroup$
    – Oirad
    Commented Jun 28, 2016 at 13:04
  • $\begingroup$ Another way would be to rename each of data_to.objects before "delete all again", If you don't want to save on each iteration. $\endgroup$
    – batFINGER
    Commented Jun 28, 2016 at 13:35
  • $\begingroup$ the camera works now, I switched the method I was using to looping through all objects to find a camera and then set it as the camera for the scene: for obj in bpy.data.objects: if ( obj.type =='CAMERA'): bpy.data.scenes["Scene"].camera = obj $\endgroup$
    – Oirad
    Commented Jun 28, 2016 at 13:52

1 Answer 1

1
$\begingroup$

If the new camera is getting named Camera.001 then it is likely that the old camera is not being deleted, as blender appends .XXX (where XXX is some number) when the requested name is already in use. I'm not to familiar with all the python delete functions, but this could be because that data isn't actually deleted until the scene is saved and re-opened, due to how blender manages garbage collection/scene data.

You probably need to update your script to get the name of the new camera from ti after creation or assign a unique name to it when you create it, and the use that to set the active camera

$\endgroup$
1
  • $\begingroup$ to make the camera work I used: for obj in bpy.data.objects: if ( obj.type =='CAMERA'): bpy.data.scenes["Scene"].camera = obj $\endgroup$
    – Oirad
    Commented Jun 30, 2016 at 12:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .