Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- def draw(self, context):
- self.layout.operator("object.add_target_spot", icon="LIGHTPROBE_CUBEMAP")
- class OBJECT_OT_add_target_spot(bpy.types.Operator):
- """Tooltip"""
- bl_idname = "object.add_target_spot"
- bl_label = "Target Spot"
- def execute(self, context):
- #bpy.ops.object.light_add(type="SPOT", radius=1)
- root_obj = bpy.data.objects.new("spot_root", None) # create the empty
- root_obj.empty_display_size = 2.0
- root_obj.empty_display_type = 'SPHERE'
- light = bpy.data.objects.new("spot", bpy.data.lights.new("spot", "SPOT"))
- light.lock_location = (True, True, True)
- light.parent = root_obj
- target_obj = bpy.data.objects.new("spot_target", None) # create the empty
- target_obj.location = (0, 0, -27)
- target_obj.parent = root_obj
- target_obj.empty_display_size = 1.0
- target_obj.empty_display_type = 'CUBE'
- constraint = light.constraints.new("DAMPED_TRACK")
- constraint.track_axis = 'TRACK_NEGATIVE_Z'
- constraint.target = target_obj
- bpy.context.layer_collection.collection.objects.link(root_obj)
- bpy.context.layer_collection.collection.objects.link(target_obj)
- bpy.context.layer_collection.collection.objects.link(light)
- for o in bpy.data.objects:
- o.select_set(False)
- root_obj.select_set(True)
- root_obj.location = context.scene.cursor.location
- bpy.context.view_layer.objects.active = root_obj
- return {'FINISHED'}
- def register():
- bpy.utils.register_class(OBJECT_OT_add_target_spot)
- bpy.types.VIEW3D_MT_light_add.append(draw)
- def unregister():
- bpy.utils.unregister_class(OBJECT_OT_add_target_spot)
- bpy.types.VIEW3D_MT_light_add.remove(draw)
- if __name__ == "__main__":
- register()
Advertisement
Add Comment
Please, Sign In to add comment