I wrote this simple python script for Blender 2.69, which creates a new operator. The operator is supposed to change the energy for four lamps in the scene (essentially switching them off and on again). However, while the script runs fine and creates the operator itself, when I select the operator, it has no effect on the lamps' energy.
Entire script:
import bpy
def main(context):
for ob in context.scene.objects:
print(ob)
class LightsOperator(bpy.types.Operator):
bl_idname = "object.lights_operator"
bl_label = "Headlight Operator"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
if bpy.data.objects['headlight1'].energy==0.0:
bpy.data.objects['headlight1'].energy = 0.8
else:
bpy.data.objects['headlight1'].energy = 0.0
if bpy.data.objects['headlight2'].energy==0.0:
bpy.data.objects['headlight2'].energy = 0.8
else:
bpy.data.objects['headlight2'].energy = 0.0
if bpy.data.objects['headlight3'].energy==0.0:
bpy.data.objects['headlight3'].energy = 0.8
else:
bpy.data.objects['headlight3'].energy = 0.0
if bpy.data.objects['headlight4'].energy==0.0:
bpy.data.objects['headlight4'].energy = 0.8
else:
bpy.data.objects['headlight4'].energy = 0.0
def register():
bpy.utils.register_class(LightsOperator)
def unregister():
bpy.utils.unregister_class(LightsOperator)
if __name__ == "__main__":
register()
# test call
bpy.ops.object.lights_operator()
poll
andexecute
methods are not inside the class? Make sure that you indent them correctly $\endgroup$