No properties inside Panel - only allowed in Operator ?

Hi everyone,

can you please explain to me why I can declare and use Properties inside of an bpy.types.Operator, but not when I’m using a bpy.types.Panel (using Blender 2.59) ?

For example, this does not display the property, printing an error:


import bpy
from bpy.props import *

class test (bpy.types.Panel):
    bl_idname = "tes.t"
    bl_label = "TestTest"
    bl_region_type = "TOOLS"
    bl_space_type = "VIEW_3D"
    
    #properties
    gamma = IntProperty(name="", min=1, max=100, default=10, description="Property Test Value")
    
    
    def draw (self, context):
        layout = self.layout
        layout.label("Now follows the property")
        
        row = layout.row(align=True)
        row.prop(self, 'gamma')
        

def register():
    bpy.utils.register_class(test)
    
def unregister():
    bpy.utils.unregister_class(test)
    
if __name__ == "__main__":
    register()

But in contrast, this works:


import bpy
from bpy.props import *

class test (bpy.types.Operator):
    bl_idname = "tes.t"
    bl_label = "TestTest"
    bl_description = "Operator Description"
    bl_options = {'REGISTER', 'UNDO'}
    
    #properties
    gamma = IntProperty(name="", min=1, max=100, default=10, description="Property Test Value")
    
    
    def draw (self, context):
        layout = self.layout
        layout.label("Now follows the property")
        
        row = layout.row(align=True)
        row.prop(self, 'gamma')
        
    def execute(self, context):
        print ("executing ...")
        return {'FINISHED'}
        

def register():
    bpy.utils.register_class(test)
    
def unregister():
    bpy.utils.unregister_class(test)
    
if __name__ == "__main__":
    register()

i think that proprs are use only for the tool pro sub panel!
and in operators class like when adding using add mesh script
at top header

see pipe script for example

so if you need to get properties inside a panel you need to define a scene properties in main and you assign it a prop!

that way it will work fine !

happy 2.5

Changing the bl_region_type to “TOOL_PROPS” did not change the situation, so I need to be able to pass the properties to the panel.

So you say I have to define a scene property like this, but what do you mean by “define it in main” - after the if name == “main”: block ?



    bpy.types.Scene.myProperty = IntProperty(name="", min=1, max=100, default=10, description="Property Test Value")
    bpy.types.Scene.myProperty = "Something"

But how do I access it - row.prop(self, “myProperty”) does not find it.

Got it, so I need to use
row.prop(context.scene, “myProperty”)
Thanks !