Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Bug? Unable to delete a button promoted to a panel when its parent is a dropdown

JeromeBriot
Mentor

Bug? Unable to delete a button promoted to a panel when its parent is a dropdown

JeromeBriot
Mentor
Mentor

Hello,

 

Here is a example:

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        cmdDefs = ui.commandDefinitions

        testButton = cmdDefs.addButtonDefinition('TestButton',
                                                'TestButton',
                                                'TestButton',
                                                'resources')

        makePanel = ui.allToolbarPanels.itemById('SolidMakePanel')

        makePanel.controls.addSeparator()
        dropdown = makePanel.controls.addDropDown('TestDrodown', 'resources', 'TestDrodown', '', True)
        button = dropdown.controls.addCommand(testButton)
        button.isPromoted = True

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def stop(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        cmdDefs = ui.commandDefinitions

        cmdDef = cmdDefs.itemById('TestButton')
        if cmdDef:
            cmdDef.deleteMe()


        makePanel = ui.allToolbarPanels.itemById('SolidMakePanel')
        cntrls = makePanel.controls

        cntrl = cntrls.itemById('TestButton')
        if cntrl:
            cntrl.isPromoted = False
            cntrl.deleteMe()

        cntrl = cntrls.itemById('TestDrodown')
        if cntrl:
            cntrl.deleteMe()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

When the add-in is stopped, all controls are removed except the promoted button.

 

Thank you.

 

0 Likes
Reply
Accepted solutions (1)
834 Views
7 Replies
Replies (7)

JeromeBriot
Mentor
Mentor

Hello,

 

Am I the only one to face this issue ?

 

Thanks

0 Likes

goyals
Autodesk
Autodesk

I tried with the script you shared but unable to see any issue. Please look at the attached video.



Shyam Goyal
Sr. Software Dev. Manager
1 Like

JeromeBriot
Mentor
Mentor

Thank you @goyals 

 

But I didn't see the promoted button on the animated GIF.

 

Normaly a "?" button should appear in the SOLID toolbar when you run the add-in.

 

0 Likes

goyals
Autodesk
Autodesk

I just added the button in SolidCreate panel instead of SolidMakePanel that might be the reason. This is the only change I made in your script.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes

JeromeBriot
Mentor
Mentor

Did you modify the ressource folder? Because a button can only be promoted if it's linked to an icon.

 

It could explain why we can't see the button on the toolbar in your video.

0 Likes

saurabh.singhKD42F
Alumni
Alumni
Accepted solution

Hi.

Below code will work fine for deleting the promoted button.

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        cmdDefs = ui.commandDefinitions

        testButton = cmdDefs.addButtonDefinition('TestButton',
                                                'TestButton',
                                                'TestButton',
                                                'resources')

        makePanel = ui.allToolbarPanels.itemById('SolidMakePanel')

        makePanel.controls.addSeparator()
        dropdown = makePanel.controls.addDropDown('TestDrodown', 'resources', 'TestDrodown', '', True)
        button = dropdown.controls.addCommand(testButton)
        button.isPromoted = True

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def stop(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        cmdDefs = ui.commandDefinitions
        cmdDef = cmdDefs.itemById('TestButton')
        if cmdDef:
            cmdDef.deleteMe()

        makePanel = ui.allToolbarPanels.itemById('SolidMakePanel')
        cntrls = makePanel.controls

        cntrl = cntrls.itemById('TestDrodown').controls.itemById('TestButton')
        if cntrl:
            cntrl.isPromoted = False
            cntrl.deleteMe()

        cntrl = cntrls.itemById('TestDrodown')
        if cntrl:
            cntrl.deleteMe()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

1 Like

JeromeBriot
Mentor
Mentor

Thank you @saurabh.singhKD42F

 


@saurabh.singhKD42F wrote:
        makePanel = ui.allToolbarPanels.itemById('SolidMakePanel')
        cntrls = makePanel.controls

        cntrl = cntrls.itemById('TestDrodown').controls.itemById('TestButton')
        if cntrl:
            cntrl.isPromoted = False
            cntrl.deleteMe()

 



 

1 Like