2
$\begingroup$

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

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
    bpy.ops.mesh.primitive_uv_sphere_add(location=l.location)
    # unlink from scene (could bpy.ops.delete or bpy.data.remove )
    scene.objects.unlink(l)

or pre select the lamps and use

lamps = context.selected_objects
$\endgroup$
0

You must log in to answer this question.

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