scripting questions blender and Pyton

hey guys, in an attempt to learn scripting in blender and I have a few questions. I am looking at the script

import bpy

class OBJECT_PT_hello(bpy.types.Panel):
    bl_label = "Hello World Panel"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        obj = context.object

        row = layout.row()
        row.label(text="Hello world!", icon='WORLD_DATA')

        row = layout.row()
        row.label(text="Active object is: " +
        row = layout.row()
        row.prop(obj, "name")

1st question is: does a function not have to be called? for example I see the draw function being defined but never called. Is it considered a constructor in this case and just called automatically when we run he script since it is the 1st (and only) function in the class?

2nd question:

def draw(self, context):

what exactly is context referring to?

3rd question: And if this is a constructor type situation, why do we place anything in the parenthesis for the function definition, since we are not actually calling the function and thus not passing any parameters?

Sorry for my ignorance but I could not seem to find a direct answer to that last question in python documentation.


Blender calls the draw() method when it wants to draw the panel.

‘context’ holds all sorts of interesting stuff about blender’s internal state that you can do fun things with – pretty much the reason scripts are created in the first place is to interact with context.

And finally, I believe that the classes get ‘constructed’ automagically when blender parses the file using either the base class init() method or quite possibly the default python method. Not too sure how blender does that.

Yo Visnik! You should check out #blendercoders and #blenderpython on irc freenode.

checking that out now, thanks

Loop, it seems I was kicked from #blenderpython as it is an invite only channel. Is this correct?