adding a lamp to the scene with a function

hello, I need help before I go nuts…

I want to add a lamp to my scene. I use the following code:

import Blender, math
from Blender import Scene, Object, Lamp

conv = 2*math.pi/360

cur = Scene.GetCurrent()
##### Definition of the lamp
l = Lamp.New('Lamp','Lamp')
lam = Object.New('Lamp')
lam.link(l)
lam.setEuler(47.534*conv,0,0)
lam.setLocation(0, -10, 7)
cur.link(lam)

Blender.Redraw()

Now, I want to put this code into a function, to easily add a Lamp through a GUI, later. So I built the following code:

import Blender, math
from Blender import Scene, Object, Lamp

conv = 2*math.pi/360

cur = Scene.GetCurrent()
##### Definition of the lamp
def MakeLamp():
	l = Lamp.New('Lamp','Lamp')
	lam = Object.New('Lamp')
	lam.link(l)
	lam.setEuler(47.534*conv,0,0)
	lam.setLocation(0, -10, 7)
	cur.link(lam)

MakeLamp

Blender.Redraw()

I get no error from the console, and nothing is updated on the screen (nor in the outliner, BTW) when python does the MakeLamp function.

Could someone explain me why and how to make my code sample works? I’m a python beginner so explanations should be at a low level or understanding :wink:

Thanks!

Just a guess, but if MakeLamp is a function, when you call it (one line up from bottom), shouldn’t it be:

MakeLamp()

hmmm… I tried this, I’m sure of it! Perhaps had I many errors at the same time, and debugged too many errors at the same time (the script is little more complex than the sample in the first post).

But you are perfectly right, thanks! It saved my day :wink:

Cheers,

No worries, I’ve made plenty of worse errors when I begun coding. :smiley:

There is an example of code at this address :
http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_b223new.htm#duplicopy232

( You should ask this kind of question on the french forum :
http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender)

This code does work perfectly for me

What do you mean, what does work perfectly for you: MakeLamp without the brackets? or MakeLamp() with the brackets…

What’s strange is that the console returns no error or warning when brackets are missing, but do nothing if they are missing… I really wonder why :slight_smile:

My attention is already too much scattered between many websites, communities, projects… I’d like to (and I tried to, many times in the past) but I noticed that I was far less efficient, because reviewing too much threads in too much places, and not working myself :frowning:

Now I’m trying to learn a bit of python by myself, and your website is a real good place to discover things, BTW :wink: