Blender Addon Help

Hello, there. I am looking to write a blender addon. I’ve only done game engine scripting but I thought I would get into this as well. I have no experience in the bpy module, nor with anything other than game logic. If someone were to be so kind as to either write this addon under my supervision, or mentor me in the ways of bpy, it would be appreciated.

Here is my current code, taken from a template (terrible).


import bpy



class ObjectTypePanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Object Types"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'LOGIC_EDITOR'
    bl_region_type = 'UI'
    bl_context = "Tools"

This can be rewritten. Here is the structure of the completed addon that I want:


Each boolean (Tool, Item, Etc) would add certain logic to the selected object, including properties and python scripts. The Name field would influence the properties of some of the logic bricks, and Create Property Handler (which should be named Create Logic) would create an object (unless it exists already) that has certain logic with certain properties, that would be further edited by further use of the addon, and the button would also add necessary logic to the object itself.

If someone would guide me though this or write it completely, I would be very happy.

It’s still a little too vague. I’ve never done any real work with blender’s game engine, but from what i understand so far:

  1. the “tool, item, other” are bools… and every object in the scene can be one of the 3 options
  2. every object has a name field (separate from the normal object name field)
  3. all this data would be used by a game engine script to affect behaviour
    (please correct me where i’m wrong)

i still don’t understand the create handler button. is “handler” a game engine term?

Spot on, khalibloo! A ‘hander’ is just an object that stores properties. It’s normally on a hidden layer, an overlay scene, or always off screen. In this case, it would add the handler just behind the camera… that’s possible, right?

Yes, it’s very possible. So a handler is like a game controller? (saw that in the unity “project stealth” series a while back)

Anyways, what you need for the most part is RNA properties. and then ID properties for the handler.
The best way to learn is to get your hands dirty, so I’ll just guide you through it. here’s a starting place http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Properties

Qvestion. How would I make a button that calls a function in the script?

Never mind, I got that done. Now I need to know how I can get the name of the currently selected object.

Never mind again, I got that, sort of. It spits out this error when I press the create logic button shown below:




Here is the code for the button:


class CreateAllLogic(bpy.types.Operator):
    bl_idname='wm.ok_createlogic'
    bl_label = 'Create Logic'
    
    def execute(self, context):
        obj = bpy.context.object
        sensors = obj.game.sensors
        controllers = obj.game.controllers
        actuators = obj.game.controllers
        bpy.ops.logic.actuator_add(type='MESSAGE', object=obj.name)

Any solutions?

Sorry again. I got it fixed. I ought to shut up until I mess around with it some more…

hmmm… :slight_smile:
currently selected object (active object) = bpy.context.active_object

Thanks! I’ve progressed a little farther, and know I have this line:


bpy.ops.logic.actuator_add(type='MESSAGE', object=obj.name)

I need to change the name and subject of this logic brick through the script. Anyone?

bpy.ops.logic.actuator_add(type=‘MOTION’, name="", object="")
you can specify the name in the name field

EDIT:
bpy.data.objects[“Cube”].game.actuators[0].name can be used if you need to edit the name at a later time

I’m not sure what you mean by subject, but you can use the python console’s auto complete to see what properties of the actuator can be accessed.

Type “bpy.data.objects[“Cube”].game.actuators[0].” and hit Ctrl + Space

All right! I am on to victory! Stay tuned, though, because being the idiot that I am, I’ll probably mess it up.

:smiley: in my experience, idiots don’t even try. You’ve come a long way already. that’s saying something!

All right new problem. And yes, I googled it before I asked here. I need to add a game property to the active camera, using python tooltips I have this code:


#adds property to camera
cam = bpy.context.scene.camera
bpy.ops.object.game_property_new(type="STRING", name ="TEST")

This adds the TEST property to the active object. How can I make it so that it adds it to whatever object the ‘cam’ variable references?

bpy.ops.object.game_property_new({‘active_object’: cam}, type=“STRING”, name =“TEST”)

You already have your feet in the water, just keep swimming, I have not yet even touched a toe in the blender code :smiley:

Booyah! Thanks CoDEman!

All right, latest problem:
I have two booleans, I need them to be linked somehow so that when one is selected, the other is unselected. Any ideas?

boolean object?

could you elaborate, please?
Selected in the 3d viewport?
selected from the script?
activated in the modifier stack?

@blueprint, you could tag along as well
just think of a task you’d like to automate, and go for it

Yes, the boolean is checked in the logic editor’s UI.