我在教自己在Blender中使用Python,並試圖使用腳本創建一個簡單的操作符。劇本在下面 - 它的目的是在場景中選擇四個(點)燈並改變它們的能量(基本上,打開和關閉燈光)。但是,當我嘗試運行該腳本時,出現「Python腳本失敗」錯誤消息。任何人都可以看到代碼有什麼問題嗎?攪拌機:Python腳本失敗(創建簡單的操作符)
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):
light1 = bpy.data.objects['headlight1']
light2 = bpy.data.objects['headlight2']
light3 = bpy.data.objects['headlight3']
light4 = bpy.data.objects['headlight4']
if light1.energy==0.0:
light1.energy = 0.8
else:
light1.energy = 0.0
if light2.energy==0.0:
light2.energy = 0.8
else:
light2.energy = 0.0
if light3.energy==0.0:
light3.energy = 0.8
else:
light3.energy = 0.0
if light4.energy==0.0:
light4.energy = 0.8
else:
light4.energy = 0.0
return {'FINISHED'}
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()
這是實際的縮進嗎? – jonrsharpe
我也推薦你在[這個專用的StackExchange站點](http://blender.stackexchange.com/)上發佈有關攪拌器的問題 –
我會推薦學習python以外的攪拌器專門的python ... blender python很可能會使用一些被認爲是不合理的或者違反直覺的東西。 –