abrasic/abratools

Icon Switcher

RathalosArt opened this issue · 2 comments

Hello there, I was wondering if there's a way to switch between icons in a custom script.

class script_info:
    name = 'Keyframe Mode Switcher'
    icon = 'IPO_CONSTANT'
    context = 'GRAPH_EDITOR'

def execute():
    import bpy
    # Get the current default interpolation type
    current_interpolation = bpy.context.preferences.edit.keyframe_new_interpolation_type
    
    # Toggle between 'CONSTANT' and 'BEZIER'
    new_interpolation = 'BEZIER' if current_interpolation == 'CONSTANT' else 'CONSTANT'
    
    # Set the new default interpolation type
    bpy.context.preferences.edit.keyframe_new_interpolation_type = new_interpolation

This script basically switches the interpolation mode between bezier and constant, and I would like the icons to reflect that.

I'm not a programmer at all, and I got help from someone just to make this work.

I would also have a suggestion for a functionality that would be super helpful:
Delete static channels.

Hello,

I was wondering if there's a way to switch between icons in a custom script.

Yes, this is possible. In your case, you could do the following inside of your script_info class:

class script_info:
    import bpy
    name = 'Keyframe Mode Switcher'
    icon = "IPO_" + bpy.context.preferences.edit.keyframe_new_interpolation_type # This will dynamically set the icon to whatever interpolation that you have set in your preferences
    context = 'GRAPH_EDITOR'

Delete static channels

Thank you for your feature request. There seems to be an add-on for that kind of thing already, but I am willing to create a variant of my own that can work within abraTools.

The latest version now has a tool that allows you to remove static F-Curves.