I am working on a test addon that displays property UI controls.
I am getting an error that says… “‘Scene’ object has no attribute ‘my_tool’”
It seems to be a registration issue, but don’t know how to fix this error
I have searched and tried many code examples, but they they don’t work with ver 2.81
Here is my code…
bl_info = {
"name": "PS Test",
"description": "PS Test",
"author": "Pixelink Software",
"version": (0, 0, 1),
"blender": (2, 80, 0),
"location": "View3D",
"wiki_url": "",
"tracker_url": "",
"category": "3D View"
}
import bpy
from bpy.props import (StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
EnumProperty,
PointerProperty,
)
from bpy.types import (Panel,
Operator,
PropertyGroup,
)
class MySettings(PropertyGroup):
my_bool = BoolProperty(
name="Enable or Disable",
description="A bool property",
default = False
)
my_int = IntProperty(
name = "Int Value",
description="A integer property",
default = 23,
min = 10,
max = 100
)
my_float = FloatProperty(
name = "Float Value",
description = "A float property",
default = 23.7,
min = 0.01,
max = 30.0
)
my_string = StringProperty(
name="User Input",
description=":",
default="",
maxlen=1024,
)
my_enum = EnumProperty(
name="Dropdown:",
description="Apply Data to attribute.",
items=[ ('OP1', "Option 1", ""),
('OP2', "Option 2", ""),
('OP3', "Option 3", ""),
]
)
class WM_OT_HelloWorld(bpy.types.Operator):
bl_label = "Print Values Operator"
bl_idname = "wm.hello_world"
def execute(self, context):
scene = context.scene
mytool = scene.my_tool
# print the values to the console
print("Hello World")
print("bool state:", mytool.my_bool)
print("int value:", mytool.my_int)
print("float value:", mytool.my_float)
print("string value:", mytool.my_string)
print("enum state:", mytool.my_enum)
return {'FINISHED'}
class OBJECT_PT_CustomPanel(Panel):
bl_label = "PS Tests"
bl_idname = "OBJECT_PT_custom_panel"
bl_category = "PS Test"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
# @classmethod
# def poll(self,context):
# return context.object is not None
def draw(self, context):
layout = self.layout
myscene = context.scene
mytool = myscene.my_tool
layout.prop(mytool, "my_bool", text="Bool Property")
layout.prop(mytool, "my_enum", text="Enum Property")
layout.prop(mytool, "my_int", text="integer Property")
layout.prop(mytool, "my_float", text="Float Property")
layout.prop(mytool, "my_string", text="String Property"")
layout.operator("wm.hello_world", text="Hellow World")
layout.separator()
def register():
bpy.utils.register_class(OBJECT_PT_CustomPanel)
#bpy.types.Scene.my_tool = PointerProperty(type=MySettings)
bpy.types.Scene.my_tool = BoolProperty(name="my_bool")
def unregister():
bpy.utils.unregister_class(OBJECT_PT_CustomPanel)
del bpy.types.Scene.my_tool
if __name__ == "__main__":
register()