# Custom properties on an action, any place for UI visibility?

I'm writing an importer/exporter for a game, and animations are identified by an ID number associated with a set of position/rotation keyframes. In the original 3DS Max exporter, they are controlled by a custom location/rotation controller, which handles the data.

It seemed like the natural mapping to Blender would be separate actions. I can add a custom integer property to bpy.types.Action easily to store the value, but there doesn't seem to be any kind of property sheet/panel for actions exposed in the UI (that I can find - for example the dope sheet/action editor has the property panel empty), so I'm not sure where to add UI elements to allow users to edit this property.

Is there something I have missed, or where can I put the UI? Otherwise, I could just require users to encode the ID into the action name, but that seems.. inelegant, at best, and prone to mistakes.

Can also add a custom property panel to the Action Editor, much the same way as it is added to other parts of the UI. Import the rna_prop_ui.PropertyPanel class and set the path from context to "object.animation_data.action" and the type to bpy.types.Action.

The default bl_label if not defined otherwise is "Custom Properties".

import bpy

from bpy.types import Panel
from rna_prop_ui import PropertyPanel

class ACTION_PT_custom_props(PropertyPanel, Panel):
bl_label = "Action Properties"
bl_idname = "ACTION_PT_custom_props"
bl_space_type = 'DOPESHEET_EDITOR'
bl_region_type = 'UI'
# required for PropertyPanel
#COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
_context_path = "object.animation_data.action"
_property_type = bpy.types.Action

@classmethod
def poll(self, context):
obj = getattr(context, "object", None)
return action is not None

def register():
bpy.utils.register_class(ACTION_PT_custom_props)

def unregister():
bpy.utils.unregister_class(ACTION_PT_custom_props)

if __name__ == "__main__":  # only for live edit.
register()


Although there is no current area for editing properties of an action, you can easily create one. Panels can be placed almost anywhere with conditional visibility. The script below adds a property panel on the dope sheet for an action property 'argument', but only when the current object has one selected:

import bpy

bpy.types.Action.argument = bpy.props.IntProperty(name="Argument", default=0)

class DopeActionProperties(bpy.types.Panel):
bl_label = "Action Properties"
bl_idname = "OBJECT_PT_dope_action"
bl_space_type = 'DOPESHEET_EDITOR'
bl_region_type = 'UI'

@classmethod
def poll(self, context):
try:
return context.object.animation_data.action != None
except AttributeError:
return False

def draw(self, context):
row = self.layout.row()
row.prop(context.object.animation_data.action, "argument")

bpy.utils.register_class(DopeActionProperties)