3
$\begingroup$

I am making a custom panel for a rig and I would like to be able to easily insert keyframes on my rig properties the same way we can already do in the default properties panel.

I'd basically like to add these buttons:

enter image description here

As you can see, I already tried to implement them but I can't get them to work properly:

enter image description here

Q: How to implement/draw these buttons for custom properties?

$\endgroup$

1 Answer 1

7
$\begingroup$

UILayout.use_property_split and UILayout.use_property_decorate

Setting UILayout.use_property_split in conjunction with UILayout.use_property_decorate to True, marks down the animation button. (Currently not over-documented) My understanding is the split makes room for it, and the decorate draws it.

enter image description here

With developer extras on, right click > view source. Found this in bl_ui.properties_space.py giving a big hint

    layout.use_property_decorate = False  # No animation.

Quick demo with object location, using the Text Editor > Templates > Python > UI Simple Panel template

import bpy


class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True
        layout.use_property_decorate = True
        obj = context.object

        col = layout.column()
        col.prop(obj, "location")


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


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


if __name__ == "__main__":
    register()
$\endgroup$
5
  • $\begingroup$ Omg, Thank you, that worked brilliantly ! Just a little question, what is "developer extras" ? is it something we can enable in user preferences or something that is already in Blender (that I didn't know the name of) ? $\endgroup$
    – azagwen
    Dec 22, 2019 at 5:44
  • 1
    $\begingroup$ @azagwen Yes, in setting panel, interface $\endgroup$
    – HikariTW
    Dec 22, 2019 at 7:16
  • $\begingroup$ Might be cool having a demo for multiple properties and how to set this up for only one of them. $\endgroup$
    – brockmann
    Dec 22, 2019 at 15:31
  • $\begingroup$ @brockmann Almost did... then didn't. Surprised the answer hasn''t attracted much interest. Find it a handy little button. $\endgroup$
    – batFINGER
    Dec 23, 2019 at 16:03
  • $\begingroup$ Time will come, I think add-on dev's still busy replacing all the assignments with annotations :) No big deal, it's your answer @batFINGER $\endgroup$
    – brockmann
    Dec 23, 2019 at 23:31

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.