How to get lamp object?

def test():
    Lights = bpy.data.lamps
    for light in Lights:
        light.use_nodes = True;

#how to get light.object? and set position?


Blender object basics.

The lamp objects in bpy.data.lamps is the data part of a lamp object o. A lamp object has o.type == "LAMP" and o.data is a lamp object from bpy.data.lamps.

To get all lamp objects in file

lamp_objects = [o for o in bpy.data.objects
                if o.type == 'LAMP']

all in file that use a lamp named "Lamp"

lamp = bpy.data.lamps.get("Lamp")
lamp_objects = [o for o in bpy.data.objects
                if o.type == 'LAMP' # need this since
                and o.data is lamp] # o.data is None for empties

for all in context scene

scene = bpy.context.scene
lamp_objects = [o for o in scene.objects
                if o.type == 'LAMP']

for all in context selected objects

lamp_objects = [o for o in bpy.context.selected_objects
                if o.type == 'LAMP']

To move all lamps to local position (0, 0, 0)

for o in lamp_objects:
    o.location = (0, 0, 0)

To move all lamps to global origin

for o in lamp_objects:
    o.matrix_world.translation = (0, 0, 0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.