4
$\begingroup$

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.

$\endgroup$

2 Answers 2

1
$\begingroup$

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

enter image description here

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)
        ad = getattr(obj, "animation_data", None)
        action = getattr(ad, "action", 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()
$\endgroup$
0
$\begingroup$

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)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .