one object operator not working ?

the class obprintbutton1(bpy.types.Operator):
does not work here

can someone point out how to correct this error


 
mport bpy
from bpy.props import *
from mathutils import *
from math import *
#
 
#bpy.context.scene.scn['MyInt'] = 17
# Store properties in the active scene
#
def initSceneProperties(scn):
 bpy.types.Scene.MyInt = IntProperty(
  name="Integer", 
  description="Enter an integer")
 scn['MyInt'] = 17
 
 bpy.types.Scene.MyFloat = FloatProperty(
  name="Float", 
  description="Enter a float",
  default = 33.33,
  min = -100,
  max = 100)
 
 bpy.types.Scene.MyBool = BoolProperty(
  name="Boolean", 
  description="True or False?")
 scn['MyBool'] = True
 
 bpy.types.Scene.MyEnum = EnumProperty(
  items = [('Eine', 'Un', 'One'), 
   ('Zwei', 'Deux', 'Two'),
   ('Drei', 'Trois', 'Three')],
  name="Ziffer")
 scn['MyEnum'] = 2
 
 bpy.types.Scene.MyString = StringProperty(
  name="String")
 scn['MyString'] = "Lorem ipsum dolor sit amet"
 return
 
initSceneProperties(bpy.context.scene)
 
 
 
 
 # in UI  n Transform panel
"""
 bl_label = "Property panel"
 bl_space_type = "VIEW_3D"
 bl_region_type = "UI"
 bl_show_header=True
 
"""
 
 
#
# Menu in UI region       n Transform  panel 
#
class UIPanel(bpy.types.Panel):
 
 
# in tool pro panel
 
 bl_label = "Property panel"      # Header Panel's  name
 bl_space_type = "VIEW_3D"       # in 3D view
# bl_region_type = "TOOLS"       # in tool shelf
 bl_region_type = "TOOL_PROPS"  
 bl_show_header=True
 
 
 
 def draw(self, context):
  layout = self.layout
  scn = context.scene
  layout.prop(scn, 'MyInt', icon='BLENDER', toggle=True)
  layout.prop(scn, 'MyFloat')
  layout.prop(scn, 'MyBool')
  layout.prop(scn, 'MyEnum')
  layout.prop(scn, 'MyString')
  layout.operator("object.PrintPropsButton")
  print (' $$$$$$$$$$$     Doing  Draw Function  $$$$$$$$$$$  ')
#
# The button prints the values of the properites in the console.
#
 
class obprintbutton1(bpy.types.Operator):
 bl_idname = "ob.printpropsbutton"
 bl_label = "Print props"
 
 def execute(self, context):
  scn = context.scene
  printProp("Int:    ", 'MyInt', scn)
  printProp("Float:  ", 'MyFloat', scn)
  printProp("Bool:   ", 'MyBool', scn)
  printProp("Enum:   ", 'MyEnum', scn)
  printProp("String: ", 'MyString', scn)
  return{'FINISHED'}    
 
 
 
def printProp(label, key, scn):
 try:
  val = scn[key]
 except:
  val = 'Undefined'
 print("%s %s" % (key, val))
 
##########
 
 
 
bpy.utils.register_class(UIPanel)
bpy.utils.register_class(obprintbutton1)
 
 
 
 

also is there more then one way to register the class and how ?

thanks for any help


import bpy
from bpy.props import *
from mathutils import *
from math import *
#
 
#bpy.context.scene.scn['MyInt'] = 17
# Store properties in the active scene
#
def initSceneProperties(scn):
 bpy.types.Scene.MyInt = IntProperty(
  name="Integer", 
  description="Enter an integer")
 scn['MyInt'] = 17
 
 bpy.types.Scene.MyFloat = FloatProperty(
  name="Float", 
  description="Enter a float",
  default = 33.33,
  min = -100,
  max = 100)
 
 bpy.types.Scene.MyBool = BoolProperty(
  name="Boolean", 
  description="True or False?")
 scn['MyBool'] = True
 
 bpy.types.Scene.MyEnum = EnumProperty(
  items = [('Eine', 'Un', 'One'), 
   ('Zwei', 'Deux', 'Two'),
   ('Drei', 'Trois', 'Three')],
  name="Ziffer")
 scn['MyEnum'] = 2
 
 bpy.types.Scene.MyString = StringProperty(
  name="String")
 scn['MyString'] = "Lorem ipsum dolor sit amet"
 return
 
initSceneProperties(bpy.context.scene)
 
 
 
 
 # in UI  n Transform panel
"""
 bl_label = "Property panel"
 bl_space_type = "VIEW_3D"
 bl_region_type = "UI"
 bl_show_header=True
 
"""
 
 
#
# Menu in UI region       n Transform  panel 
#
class UIPanel(bpy.types.Panel):
 
 
  # in tool pro panel
  bl_label = "Property panel"      # Header Panel's  name
  bl_space_type = "VIEW_3D"       # in 3D view
  # bl_region_type = "TOOLS"       # in tool shelf
  bl_region_type = "TOOL_PROPS"  
  bl_show_header=True
  
  def draw(self, context):
    layout = self.layout
    scn = context.scene
    layout.prop(scn, 'MyInt', icon='BLENDER', toggle=True)
    layout.prop(scn, 'MyFloat')
    layout.prop(scn, 'MyBool')
    layout.prop(scn, 'MyEnum')
    layout.prop(scn, 'MyString')
    layout.operator("<b>object.printpropsbutton</b>")
    print (' $$$$$$$$$$$     Doing  Draw Function  $$$$$$$$$$$  ')
#
# The button prints the values of the properites in the console.
#
 
class obprintbutton1(bpy.types.Operator):
    bl_idname = "object.printpropsbutton"
    bl_label = "Print props"
 
    def execute(self, context):
        scn = context.scene
        printProp("Int:    ", 'MyInt', scn)
        printProp("Float:  ", 'MyFloat', scn)
        printProp("Bool:   ", 'MyBool', scn)
        printProp("Enum:   ", 'MyEnum', scn)
        printProp("String: ", 'MyString', scn)
        return{'FINISHED'}    
 
 
def printProp(label, key, scn):
    try:
        val = scn[key]
    except:
        val = 'Undefined'
        print("%s %s" % (key, val))
 
##########
 
def register():
    bpy.utils.register_class(UIPanel)
    bpy.utils.register_class(obprintbutton1)
    
def unregister():
    bpy.utils.unregister_class(UIPanel)
    bpy.utils.unregister_class(obprintbutton1)
    
if __name__ == "__main__":
    register()

you must pay better attention to your indentation and to your use of lower and upper-case letters.

i’ve seen people do


class_collection = UIPanel, obprintbutton1

def register():
    for name in class_collection:
         bpy.utils.register_class(name)

# same for unregister

but i’ve seen others do, but i expect this has to do with scripts that exceed one .py, ie using other scripts in the same directory to take functions/modules from. I’ve not used it…


def register():
    bpy.utils.register_module(__name__)

# and same for unregister()

i did check the id name ect and was not working
so i tough there had been other API changes!

at least this one is working again thanks!
i have to modify another 25 scripts lile that !LOL

for the registration

bpy.utils.register_class(name)

seems to work ok

but do you need to include the unregister also
and if you don’t what are the consequences ?

now don’t know i’v seen also this one but might not be working anymore!

def register():

bpy.types.register(myOperator)
bpy.types.register(myPanel)

before seeing if this can work or not in another script first i have to find the error for space info and correct that one

now is this way of registering out of date or can work in latest built ?

thanks

Ricky can you please take a little bit more time to format your posts. It’s such a pain to read them, especially if we are talking about programming in python. Slow down, read my previous post carefully!

for those interested
seems that you don’t need to declare all class

here is how

for script with a menu


 
 
def register():
 bpy.utils.register_module(__name__)
 
 bpy.types.INFO_MT_mesh_add.append(menu_func)
 
 
def unregister():
 bpy.utils.unregister_module(__name__)
 
 
 bpy.types.INFO_MT_mesh_add.remove(menu_func)
 
 
if __name__ == "__main__":
 register()
 
 

need to update another 20 scripts this weekend but going well!

thanks happy 2.5

Ricky you might want to reduce the gratuitous white space to improve your coding style.


def register():
    bpy.utils.register_module(__name__)
    bpy.types.INFO_MT_mesh_add.append(menu_func)

  
def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.INFO_MT_mesh_add.remove(menu_func)

 
if __name__ == "__main__":
 register()

Actually, the pep8 Python coding style (which Blender appears to recommend) asks for two blank lines before each outermost def and class. So some of RickyBlender’s double blank lines were adhering to that style. Though I agree that removing some of the other blank lines improves readability a bit here.

I totally get your point, but because register and unregister are a pair, it might not be so rogue to keep them closer. pep8 is open to some interpretation. pep8 dig into it ricky, good times!

i have some scripts which have only the register part and seems to work fine

i know it is not supposed to be like that
so was just wondering what this registering process does and what the unregistering is doing also

before we did not have this then we had it !
but never really undertstood what it does or not!

thanks