Changing addon icons not working

Joshua.mursic
Advocate

Changing addon icons not working

Joshua.mursic
Advocate
Advocate

Hello, I am trying to update the icon of a button in my addon. But when i set the .resourceFolder property, the icon does not update. If I reset the panel customization, the icon updates, or if I remove it from the panel and then put it back, it will also update. Am I missing something? 

import adsk.core,os
from ...lib import fusion360utils as futil


app = adsk.core.Application.get()
ui = app.userInterface

filePath = os.path.join(os.path.dirname(os.path.abspath(__file__)))
iconPath1 = os.path.join(filePath,"icon1")
iconPath2 = os.path.join(filePath,"icon2")
buttonFunction = 1


def command_created(args: adsk.core.CommandCreatedEventArgs):
    if buttonFunction == 1:
        args.command.parentCommandDefinition.resourceFolder = iconPath2
        futil.add_handler(args.command.execute, command_1)
        futil.add_handler(args.command.destroy, command_destroy)
    else:
        args.command.parentCommandDefinition.resourceFolder = iconPath1
        futil.add_handler(args.command.execute, command_2)
        futil.add_handler(args.command.destroy, command_destroy)


def command_1(args: adsk.core.CommandEventArgs):
    app.log("switching to icon 2")
    app.log(f"{iconPath2}")
    args.command.parentCommandDefinition.resourceFolder = iconPath2


def command_2(args: adsk.core.CommandEventArgs):
    app.log("switching to icon 1")
    app.log(f"{iconPath1}")
    args.command.parentCommandDefinition.resourceFolder = iconPath1


def command_destroy(args: adsk.core.CommandEventArgs):
    global buttonFunction
    if buttonFunction == 1:
        buttonFunction = 2
    else:
        buttonFunction = 1


0 Likes
Reply
Accepted solutions (1)
255 Views
2 Replies
Replies (2)

john.kirchner
Autodesk
Autodesk
Accepted solution

This issue should be fixed in the current Insider build/the next Fusion release, which will be later this month.

One workaround is related to what you observed - force an update of the icon through a different function. So you can add this line after setting the resourceFolder and it should work:

args.command.parentCommandDefinition.name = args.command.parentCommandDefinition.name

 



0 Likes

Joshua.mursic
Advocate
Advocate

Fantastic, thank you for the workaround

 

0 Likes