# how to change the value of various custom properties at the same time?

I have a bone with various custom properties and I want to change the value of all of them, from 0 to 1 at the same time (pressing a button).

Have a look at the operator simple template in the text editor. Replace main(context) with this

def main(context):
#active pose bone
pb = context.active_pose_bone
# all custom properties on bone
for key in pb.keys():
#ignore _RNA_UI
if key == '_RNA_UI':
continue
pb[key] = 1
# insert a keyframe
pb.keyframe_insert('["%s"]' % key)


and the poll method to

def poll(cls, context):
return context.active_pose_bone is not None


to make sure that there is an active pose bone selected.

and change the idname from object.simple_operator to something meaningful like posebone.set

Then have a look at the panel simple template and

row.operator("posebone.set")


will give you a UI button.

• how can I insert a keyframe to all of them, using this method? – nexxio Jun 7 '16 at 21:18
• @nexxio Added pb.keyframe_insert('["%s"]' % key) to code. Will add a keyframe for each custom property at the frame of button press. – batFINGER Jun 8 '16 at 5:17
• thanks a lot! @batFINGER ...and, I wanted this operator duplicated so I could have and operator for 3 more buttons that will make the same but each one will add a new value for one specific custom property. I tested and it works great, but if I copy and paste the script in the same operator simple template and change the idname of the pasted one it does not work. so my question is that: can you have more than one custom operator defined in the same script(I mean something like: custom operators.py)? – nexxio Jun 8 '16 at 15:52
• Each operator will also need a new class name eg SimpleOperator2 (think of a better one) and be registered bpy.utils.register_class(SimpleOperator2) in the register method. Could also pass operator arguments look at blender.stackexchange.com/questions/17751/… – batFINGER Jun 8 '16 at 16:37
• I did change the class name, and registered and unregistered, but only one works( I just make one copy of the code and pasted it under to see if it works). I thing that maybe is because they both are in main(context): (by the way i dont know what it is for) I tried changin one to: def execute(self, context): but it shows error. – nexxio Jun 8 '16 at 19:12