Just started coding in python, help with modules needed!

Hello,
I have just started taking an intrest in the Python API. However, there seems to be a problem with me, I can’t even get the most simplest thing to work in blender.

Example

import Blender
from blender import Lamp
[Now what, how do I use the various submodules?]
l = Lamp.New(‘Spot’) #I understand Lamp.New('Spot) but what is " l = " for? And why is it there? Is l a variable? If so then Lamp.New('spot) is the definition of the variable, correct?
So then: l.setMode(‘square’, ‘shadow’) is setting the properties for the Lamp, right?

Now what is all of this?
ob = Object.New(‘Lamp’)
ob.link(l)

Dudes my brain is fried like sunday dinner, I am completely confused, can someone give me some help. If you have ICQ gimme a ring tonight at 8:00PM Eastern US time. I would really appreciate it.
ICQ# 281-684-578

If you just want to post here that’s kool too.

Hi sprinkles, I gave you a poke on icq, just look the newcommer list.
then you’ll be able to ask me question when you need to.

Right now i can tell you:
Look in the doc. in each module you have classe, function, maybe variable.Each module has function to mainly to let you manage module data. The module data is most of the time classes. of if you prefer: object.
When you do I = Lamp.New(‘Spot’), you ask the lamp module to generate a lamp object and save it in the I variable. this variable is a pointer to data in blender: the lamp you just created. This data can be manipulated with the I variable you just wraped the data in, because this “wrap” give you tools too interact with blender data. I is a copy of the lamp class section of doc. So you can do l.setMode(‘square’, ‘shadow’) and the lamp you created will be modified.

Now the "Object.new(‘lamp’) trick is simple. You’ll notice that if you do the code as is, your lamp will not appear in the 3Dview. That because you have to understand that you are still bounded by the system you work with, here blender data manager system. Remeber the outliner, the OOPS view, the dropdown for material and object? There if you look closely, you’ll notice that first there is a lamp and this lamp is then linked to and object. Some for mesh: first you have a mesh, which is linked to an object. So the what you have to know about that is: an object is an universal container. The 3dview only show object you know :wink: . So if you want to put you lamp in a particular scene at a given position, you’ll have to work with the object. Because the lamp module only containe data concerning lamp and the object contain all the rest of the info: position, rotation, size, scene, layer, name, etc… This system give us the power to switch data and still keep the same object, with the dropdown menu you can choose an other mesh in the list and switch. Same for material look closely in the material button window. You have the ability to link the material data to the object or the mesh data. The main difference is if you link the material to the object and then switch the mesh object to something else, the object will still has is material. And if you link against the mesh itself, it will follow the mesh you just dropped, of course.

Just take a peek in the OOPS and enable all drawing option to know what you’r working on. Object or data.

Here what you talked. This little script will generate a lamp data and link it to a new object postitionned at (10,0,0). it will then place it in the current Scene. if you look at the OOPS you’ll see that these links are all needed to get a working lamp you can see in your screen:

import Blender
from Blender import Lamp, Object, Scene

I = Lamp.New("Spot")

ob = Object.New("Lamp")
ob.link(I)

sce = Scene.GetCurrent()
sce.link(ob)

ob.setLocation(10,0,0)

Ok I think I have the jist of it now, thanks man. If I have any other questions for python I will let you know on ICQ.

‘linking’ is integral to blender’s way to doing things. If you take a look at the ‘OOPS’ view you’ll see that the objects in blender are hierchical. When 2 objects require each other they are said to be linked. If data is not ‘linked’ then for all practical purposes its is not being used anywhere and blender will ignore it.

In C programming terms, many data types have a ‘linked list’ pointer which you can add/subtract items from the end which are associated with it.

You guys have to realize, i am a total noob when it comes to programming. But thanks to gab I am slowly learning, so if you guys have any help to give, just remember to keep it in simple terms so my little brain can comprehend it. :slight_smile: