I am making a python script that replace lights by spheres (to get the Blender light positions in Unity) for Dark Blender, but the script Cursor to Active command is specific to the 3d view so it does not compile from the text editor. What code should i write to make it work?


1 Answer 1


If a 3d view is not in local mode then bpy.ops.view3d.snap_cursor_to_active() is the equivalent of

context.scene.cursor_location = context.active_object.location

Could also just get the location from the lamps in the scene

import bpy

context = bpy.context
scene = context.scene

lamps = [o for o in scene.objects if o.type == 'LAMP']

for l in lamps:
    # add sphere
    # unlink from scene (could bpy.ops.delete or bpy.data.remove )

or pre select the lamps and use

lamps = context.selected_objects

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .