I understand that running blender without a GUI does not provide bpy.context
for the 3d View. Can anyone help me with a work around. This results in a 'Context' object has no attribute 'object' error.
for scene in bpy.data.scenes:
for object in scene.objects:
if bpy.context.mode == 'OBJECT':
if object.name != 'Lamp':
if object.name != 'Camera':
print("deleting " + object.name)
bpy.ops.object.delete(use_global=False)
bpy.ops.mesh.primitive_cone_add({'scene': scene, 'active_object': object})
print(bpy.context.object)
getattr
andhasattr
or catch and handle the exceptions. $\endgroup$bpy.ops.object.delete
it could be deleting many objects at once, suggest you usescene.objects.remove(obj)
so you have better control, and make a copy of the objects list before looping over it. eg,for ob in scene.objects[:]: ....
$\endgroup$