Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- # 1. Create a single shared Spotlight data-block
- light_data = bpy.data.lights.new(name="Shared_Ceiling_Spot", type='SPOT')
- light_data.energy = 500.0 # Initial power in Watts
- # 2. Store current selection
- selected_objs = bpy.context.selected_objects.copy()
- # 3. Deselect old objects so only the new lights are selected at the end
- bpy.ops.object.select_all(action='DESELECT')
- # 4. Spawn a linked light at each selected object's transform
- for obj in selected_objs:
- light_obj = bpy.data.objects.new(name=f"Spot_{obj.name}", object_data=light_data)
- # Link to the same collection as the target object (or active collection)
- if obj.users_collection:
- obj.users_collection[0].objects.link(light_obj)
- else:
- bpy.context.collection.objects.link(light_obj)
- # Match exact position and rotation
- light_obj.matrix_world = obj.matrix_world.copy()
- light_obj.select_set(True)
- # Set the last created light as the active object
- if bpy.context.selected_objects:
- bpy.context.view_layer.objects.active = bpy.context.selected_objects[0]
Advertisement