I want to create custom property for a bone in "pose mode" and then make it drive a shape key on mesh. As there are lots of shape keys and I need to apply this to every rig I want to script it.


1st Method

  1. Assign a custom property to an existing type

    "type" are blender data types please note that "Bone" is different from "PoseBone" type "custom_float2" is just random name it can be anything you like

    bpy.types.PoseBone.custom_float2 = bpy.props.FloatProperty(name="Test Prob", default=0.3, min=0.0, max=1)

    For more description on Creation of Custom property

  2. Then Assign it to the bone you wish to use it with

    bpy.data.objects["Armature"].pose.bones["Bone"].custom_float2 = 2.0

    • Select the bone in pose mode and you will see the custom property

    • Note: bones["Bone"].custom_float2 is unique from bones["Bone 2"].custom_float2 and bones["Bone 3"].custom_float2 just you have to repeat step 2 to assing custom property to other bones

2nd Method

Create the property. Assigning some value is very important.

pbone = bpy.data.objects["Armature"].pose.bones["Bone"]
pbone['myControl'] = 0

Now as Jerryno pointed To change min, max, softmin or softmax you need to adjust the _RNA_UI_ dictionary with those parameters. There are few things have to be kept in mind.

_RNA_UI is a single dictionary for all ID-Properties for any given object.

we have to check if this _RNA_UI dictionary exists if not create

if "_RNA_UI" not in pbone.keys():
            pbone["_RNA_UI"] = {}

And we have to use update() method to append this dictionary

pbone["_RNA_UI"].update({"myControl": {"min":0.0, "max":1.0, "soft_min":0.0, "soft_max":1.0}})
  • $\begingroup$ @Jerryno thanks. In First method "Standard Method" can Property name be dynamic? Or Second method is right for this kind of usage? $\endgroup$
    – ashwin
    Aug 3 '15 at 9:59
  • $\begingroup$ Both methods are fine and I would consider both standard. 1st is static property that is declared for all datablocks and supports all property types and 2nd is ID property which is declared only for single datablock and supports only floats, integers, lists and strings. That's about the only difference.. I don't know what you mean with dynamic name, can you clarify? $\endgroup$ Aug 3 '15 at 14:18
  • $\begingroup$ in 1st method can we change the min max and other parameters after it is created? and in 1st method how do i create a property that is dependent on some other objects shape keys, say using for loop... $\endgroup$
    – ashwin
    Aug 3 '15 at 15:42
  • $\begingroup$ Yes you can change the min/max just by re-declaring the property, see: blender.stackexchange.com/questions/28086/…. To make something dependent on a property you can use driver or a callback function or handler - depends on what you need, this would be best to ask as a new question if there isn't one yet. $\endgroup$ Aug 3 '15 at 15:49

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.