Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
JeromeBriot
618 Views, 7 Replies

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

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.

 

7 REPLIES 7
Message 2 of 8
JeromeBriot
in reply to: JeromeBriot

Hello,

 

Am I the only one to face this issue ?

 

Thanks

Message 3 of 8
goyals
in reply to: JeromeBriot

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
Message 4 of 8
JeromeBriot
in reply to: goyals

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.

 

Message 5 of 8
goyals
in reply to: JeromeBriot

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
Message 6 of 8
JeromeBriot
in reply to: goyals

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.

Message 7 of 8

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()))

 

Message 8 of 8

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()

 



 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report