1
$\begingroup$

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).

$\endgroup$
1
$\begingroup$

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.

$\endgroup$
7
  • $\begingroup$ how can I insert a keyframe to all of them, using this method? $\endgroup$ – nexxio Jun 7 '16 at 21:18
  • $\begingroup$ @nexxio Added pb.keyframe_insert('["%s"]' % key) to code. Will add a keyframe for each custom property at the frame of button press. $\endgroup$ – batFINGER Jun 8 '16 at 5:17
  • $\begingroup$ 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)? $\endgroup$ – nexxio Jun 8 '16 at 15:52
  • $\begingroup$ 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/… $\endgroup$ – batFINGER Jun 8 '16 at 16:37
  • $\begingroup$ 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. $\endgroup$ – nexxio Jun 8 '16 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.