2.5 Create and Return New Lamp?

HI All,

I am trying to create a new lamp and return it to a variable. Ideally, I want to avoid what the Console Reports.

bpy.ops.object.lamp_add(type=‘SPOT’, view_align=False, location=(0, 0, 0), rotation=(0, 0, 0), layer=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))

While this does create a lamp in the scene, I don’t like the fact that I do not get the result stored in a variable, I can not name it on creation and it destroys the current selection.

In 2.49 I did this.


l = Lamp.New('Spot',passedName) 

What is the 2.5 equivalent of the 2.49 create lamp code?

Thanks!

add a lamp and you see the command in the report window
or goto scripting
type there
bpy.ops.object.la (ctrl space) :wink:

Kind of a PITA but…


lampdata = bpy.data.lamps.new('lamp')
lamp = bpy.data.objects.new('lamp', lampdata)
bpy.context.scene.objects.link(lamp)

Thanks for the syntax!

@PKHG: Thanks for the CTRL-SPACE tip for the console. I have been typing print(dir(myVar)) quite a bit to figure out what I could use after the next DOT. CTRL-SPACE is so much quicker!

In by the way, in the console dir(bpy) (or the like) suffices, no print( ) needed. That is what I do in (foreign) scripts …