1
$\begingroup$

I want to place a shortcut in the panel I'm creating for changing the F-curves Default Interpolation Type found in Preferences> Animation> F-Curves.

I have the Python Tooltips enabled and it says:

PreferencesEdit.keyframe_new_interpolation_type

How do I write a script to access this operator with its functionality?

$\endgroup$
1
$\begingroup$

You can access that Preferences property with the following code:

bpy.context.preferences.edit.keyframe_new_interpolation_type

To use this in a panel:

    row.prop(context.preferences.edit, "keyframe_new_interpolation_type")

The full code (using the UI Panel Simple template found in the Text Editor> Templates menu):

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
        row = layout.row()
        row.prop(context.preferences.edit, "keyframe_new_interpolation_type")

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

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

if __name__ == "__main__":
    register()

Which displays like this, in the Object tab of the Properties Editor:

enter image description here

If you need to set this value manually you can see the list of strings this property expects to be set to in the Blender 2.80 Python API.

$\endgroup$
  • $\begingroup$ Oh my word! It works and it was so simple. How did you find it? $\endgroup$ – Ryan Aug 28 at 20:49
  • $\begingroup$ I looked up how to access the User Preferences in 2.79 here, typed bpy.context.preferences (as 2.80 has 'Preferences' instead of 'User Preferences') in Blender's Python Console and used Autocomplete to display the various options. $\endgroup$ – Ray Mairlot Aug 28 at 20:54
  • $\begingroup$ This helped so much. Thank you. $\endgroup$ – Ryan Aug 28 at 20:56

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.