Still trying to wrap a property into my Addon where I can dynamically control the values of the resulting variable. Take the default operator_mesh_add example and alter the definition of the width FloatProperty to be:
def get_func(self):
print('get_')
return self.actual_width
def set_func(self, value):
print('set_')
self.actual_width = value
class AddBox(bpy.types.Operator):
"""Add a simple box mesh"""
bl_idname = "mesh.primitive_box_add"
bl_label = "Add Box"
bl_options = {'REGISTER', 'UNDO'}
actual_width: 1.0
width: FloatProperty(
name="Width",
description="Box Width",
min=0.01, max=100.0,
default=1.0,
set=set_func,
get=get_func,
)
this gives:
AttributeError: 'MESH_OT_primitive_box_add' object has no attribute 'actual_width'
if the get/set functions access the self.width member, there is an infinite recursion. We really need a tangible example of how to use get/set within an operator setting.
Following How to use set/get property callbacks correctly? and making set/get:
def get_func(self):
print('get_')
return self['width']
def set_func(self, value):
print('set_')
self['width'] = value
results in:
KeyError: 'bpy_struct[key]: key "width" not found'
What is the right way?
self.actual_widthdoesn't work because you don't have an instance attribute, you've declared a class attribute. Therefore you would need to use eitherAddBox.actual_widthortype(self).actual_width. – Robert Gützkow Oct 15 '19 at 22:06.get()for when the key doesn't yet exist. – Robert Gützkow Oct 15 '19 at 22:13