If only a single .blend uses your property, tick the Register checkbox for the script in Text Editor. The text datablock name must end with .py
!
The script will be run when the .blend is loaded. Note that auto-run is disabled by default. Click Reload Trusted in the Info header and confirm (Revert).
import bpy
def my_enum_cb(self, context):
print(self, self.my_enum, context)
bpy.types.PoseBone.my_enum = bpy.props.EnumProperty(
items=(
('identi_1', 'Name 1', 'Descript 1'),
('identi_2', 'Name 2', 'Descript 2'),
('identi_3', 'Name 3', 'Descript 3'),
),
name="My Enum",
default="identi_2",
update=my_enum_cb
)
bpy.data.objects["Armature"].pose.bones["Bone"].my_enum = "identi_3"
If you need this property to be globally available, turn the code into an addon, install and enable it. Don't forget to save user prefs after enabling it, or you will have to tick the checkbox every time you start Blender:
bl_info = {
"name": "My Enum Addon",
"author": "Your Name Here",
"version": (1, 0),
"blender": (2, 75, 0),
"location": "",
"description": "",
"warning": "",
"wiki_url": "",
"category": "Rigging",
}
import bpy
# Define our own panel (optional)
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Bone properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "bone"
def draw(self, context):
layout = self.layout
pbone = context.active_pose_bone
if pbone is not None:
layout.prop(pbone, "my_enum")
else:
layout.label("No active PoseBone.")
def my_enum_cb(self, context):
print(self, self.my_enum, context)
def register():
bpy.types.PoseBone.my_enum = bpy.props.EnumProperty(
items=(
('identi_1', 'Name 1', 'Descript 1'),
('identi_2', 'Name 2', 'Descript 2'),
('identi_3', 'Name 3', 'Descript 3'),
),
name="My Enum",
default="identi_2",
update=my_enum_cb
)
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.PoseBone.my_enum
if __name__ == "__main__":
register()
# This is not supposed to be done in an addon.
# Every access to bpy.data and bpy.contet during init is prohibited.
#bpy.data.objects["Armature"].pose.bones["Bone"].my_enum = "identi_3"
register()
, and delete them inunregister()
. Install the addon, enable it and save user preferences, so that it loads automatically every time. Or use the Register checkbox in Text editor instead of using an addon if the script is specific to that .blend file. $\endgroup$