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: 

Dialogue is not displayed after clicking on the button

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
tomas.bangoA2EPZ
130 Views, 2 Replies

Dialogue is not displayed after clicking on the button

Hi I am a beginner in both programming and python and I need help. So far I have managed to solve every problem somehow but unfortunately here I have no idea.

The file so far is more of an empty template, I would like to click it to see a dialog with dropdown options

 

My try: (file also attached)

 

#Author-
#Description-

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

handlers = []

class SCbuttonPressedEventHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self,args):
        try:
            app=adsk.core.Application().get()
            ui=app.userInterface
            cmd=args.command #Bůh ví co jsou další dva řádky.
            intupts=cmd.commandInputs

            dropdownInput1=intupts.addDropDownCommandInput('dropdown1','Vyber dílu', adsk.core.DropDownStyles.TextListDropDownStyle);
            dropdown1Items=dropdownIn1.listItems
            dropdown1Items.add('Šroub',True,'')
            dropdown1Items.add('T-profil',False,'')

            onExecute=SCbuttonOKEventHandler()
            cmd.execute.add(onExecute)
            handlers.append(onExecute)
       
        except:
            if ui:
                ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


class SCbuttonOKEventHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self,args):
        try:
            app=adsk.core.Application().get()
            ui=app.userInterface
            cmd=args.command #Bůh ví co jsou další dva řádky.
            intupts=cmd.commandInputs
           

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


def run(context):
    ui=None
    try:
        app=adsk.core.Application.get()
        ui=app.userInterface
       
        commandDefinitions=ui.commandDefinitions
        SCbuttondef=commandDefinitions.addButtonDefinition('FCK','MyAddin','.l..','resources')
        addinsToolbarPanel=ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
       
        SCbuttonControl=addinsToolbarPanel.controls.addCommand(SCbuttondef,'SCbuttonControl')
        SCbuttonControl.isPromotedByDefault=True #Vkládá nástroj do lišty samo
        SCbuttonControl.isPromoted=True

        SCbuttonpressed=SCbuttonPressedEventHandler()
        SCbuttondef.commandCreated.add(SCbuttonpressed)
        handlers.append(SCbuttonpressed)

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

def unset():
    app = adsk.core.Application.get()
    ui  = app.userInterface

    SCbuttondef=ui.commandDefinitions.itemById('FCK')
    if SCbuttondef:
        SCbuttondef.deleteMe()

    addinsToolbarPanel=ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')

    SCbuttonControl=addinsToolbarPanel.controls.itemById('FCK')
    if SCbuttonControl:
        SCbuttonControl.deleteMe()

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

        unset()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
2 REPLIES 2
Message 2 of 3

Hi @tomas.bangoA2EPZ .

 

Fixed two places in "SCbuttonPressedEventHandler".

class SCbuttonPressedEventHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args):
        try:
            # app = adsk.core.Application().get() <-here
            app = adsk.core.Application.get()
            ui = app.userInterface
            cmd = args.command  # Bůh ví co jsou další dva řádky.
            intupts = cmd.commandInputs

            dropdownInput1 = intupts.addDropDownCommandInput(
                'dropdown1', 'Vyber dílu', adsk.core.DropDownStyles.TextListDropDownStyle)
            # dropdown1Items = dropdownIn1.listItems <-here
            dropdown1Items = dropdownInput1.listItems
            dropdown1Items.add('Šroub', True, '')
            dropdown1Items.add('T-profil', False, '')

            onExecute = SCbuttonOKEventHandler()
            cmd.execute.add(onExecute)
            handlers.append(onExecute)

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

 

If you can use this one, it will make it easier to see the code.

1.png

Message 3 of 3

OMG! 😄 Thank you so much for your help with this. I've been looking at it for hours and didn't notice this. Now I can move on. Have a great day

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report