# Function Update on Boolean Property

Is there a way to use the update function when group properties are used? Am I not registering it correctly? I need to keep unique properties attached to each newly added object however. It seems that if I use the standard update on the pointer for the group functions, it doesn't maintain unique settings for each object.

import bpy
from bpy.props import *

# ---
# Group Properties that include Float, Integer, and String
# ---

class MyPropertyGroup(bpy.types.PropertyGroup):
custom_String = bpy.props.StringProperty(name ="My String")
# Update Function for Boolean
custom_Boolean = bpy.props.BoolProperty(update = UpdatedFunction)

# ---
# Layout
# ---

class LayoutPanel(bpy.types.Panel):
bl_label = "Test Text"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_context = "mesh_edit"

def draw(self, context):
scn = bpy.context.object
layout = self.layout

row = layout.row(align=True)
col = row.column()
col.prop(scn.my_prop_grp, 'custom_String', text="")
col.prop(scn.my_prop_grp, 'custom_Boolean', text="")

def UpdatedFunction(self, context):
pass
return

# ---
# Registers
# ---

def register():
bpy.utils.register_class(MyPropertyGroup)
bpy.utils.register_class(LayoutPanel)
bpy.types.Object.my_prop_grp = bpy.props.PointerProperty(type=MyPropertyGroup)

def unregister():

bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
register()


Your update function is not defined before you try to use it. You need to put it before the property group class.

Here is a simple add-on that is very similar to your original:

bl_info = {
"version": (1, 0),
"blender": (2, 75, 0),
"location": "View3D > Tools > Test Text",
"description": "Description",
"warning": "",
"wiki_url": "",
"category": "Temp",
}

import bpy
from bpy.props import StringProperty, BoolProperty
from bpy.types import PropertyGroup, Panel, Scene
from bpy.utils import register_class, unregister_class

def UpdatedFunction(self, context):
print("In update func...")
return

class MyPropertyGroup(PropertyGroup):
custom_String = StringProperty(name ="My String")
custom_Boolean = BoolProperty(update = UpdatedFunction)

class LayoutPanel(Panel):
bl_label = "Test Text"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_category = "Tools"  # puts it in the tools tab of 3D view tools
#bl_context = "mesh_edit"

def draw(self, context):
scene = bpy.context.scene
layout = self.layout

row = layout.row(align=True)
col = row.column()
col.prop(scene.my_prop_grp, 'custom_String', text="")
col.prop(scene.my_prop_grp, 'custom_Boolean', text="")

classes = (MyPropertyGroup, LayoutPanel)

def register():
for i in classes:
register_class(i)

# storing property in scene for this example
Scene.my_prop_grp = bpy.props.PointerProperty(type=MyPropertyGroup)

def unregister():
for i in classes:
unregister_class(i)

if __name__ == "__main__":
register()


I think you should be able to find your way from there, but let me know if you need further clarification.

Edit:

bl_info = {
"version": (1, 0),
"blender": (2, 75, 0),
"location": "View3D > Tools > Test Text",
"description": "Description",
"warning": "",
"wiki_url": "",
"category": "Temp",
}

import bpy
from bpy.props import StringProperty, BoolProperty, PointerProperty
from bpy.types import PropertyGroup, Panel, Scene
from bpy.utils import register_class, unregister_class

def UpdatedFunction(self, context):
print("In update func...")
print(self.custom_String)

class MyPropertyGroup(PropertyGroup):
custom_String = StringProperty(name ="String Property")
custom_Boolean = BoolProperty(name="Bool Property", update=UpdatedFunction)

class LayoutPanel(Panel):
bl_label = "Test Text"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_category = "Tools"  # puts it in the tools tab of 3D view tools
#bl_context = "mesh_edit"

def draw(self, context):
scene = bpy.context.scene
layout = self.layout

row = layout.row(align=True)
col = row.column()
col.prop(scene.my_prop, 'custom_String', text="")
col.prop(scene.my_prop, 'custom_Boolean', text="")

col.prop(scene.my_other_prop, 'custom_String', text="")
col.prop(scene.my_other_prop, 'custom_Boolean', text="")

classes = (MyPropertyGroup, LayoutPanel)

def register():
for i in classes:
register_class(i)

# storing property in scene for this example
Scene.my_prop = PointerProperty(type=MyPropertyGroup)
Scene.my_other_prop = PointerProperty(type=MyPropertyGroup)

def unregister():
for i in classes:
unregister_class(i)

if __name__ == "__main__":
register()

• Thanks pycoder! However, I think I needed to clarify the question- sorry about that. I needed to keep each newly added item with maintaining unique settings. When I update through the described method, since it's registered, it can't assign each object with new properties - at least that is my understanding. – ACopeLan Mar 1 '17 at 15:37
• @Monolith So you need multiple property groups such that the update function's effects are not shared across all instances? I'm quite positive that's how it works by default, but it isn't too difficult to check. I don't really understand what you mean by "since it's registered, it can't assign each object with new properties"? Can you explain? – JakeD Mar 1 '17 at 16:16
• Exactly. Or if there is a way to do that from the one property group. – ACopeLan Mar 1 '17 at 16:17
• @Monolith please see my edited comment and answer... – JakeD Mar 1 '17 at 16:27
• OK thanks pycoder, that put me on the right track. The posted code is what I was thinking. If you create an object and switch it to edit mode, change the variables, get out of edit mode, create a new object(s)- each object will maintain it's own variables. – ACopeLan Mar 1 '17 at 17:06