[Bug?]: Reading existing DropDownControl attributes

[Bug?]: Reading existing DropDownControl attributes

pludikar
Collaborator Collaborator
647 Views
6 Replies
Message 1 of 7

[Bug?]: Reading existing DropDownControl attributes

pludikar
Collaborator
Collaborator

Hi,

 

I'm attempting to clone some of the design solid menu Panels (eg create) and associated controls for my own AddIn purposes.  On the whole it works as expected.  However, attempting to clone a DropDownControl results in an error.

 

The issue occurs attempting to read the name and the resource folder of the existing DropDown.  In VSC, inspecting both attributes show a traceback message of:

 

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "...AppData/Local/Autodesk/webdeploy/production/a86b1e861af1608f41e2e5ec25336d404338c9db/Api/Python/packages\adsk\core.py", line 22335, in _get_name
    return _core.DropDownControl__get_name(self)
RuntimeError: 2 : InternalValidationError : nuInputControl

 

 

 

        app = adsk.core.Application.get()
        ui = app.userInterface
        allWorkspaces = ui.workspaces
        designWorkspace :adsk.core.Workspaces = allWorkspaces.itemById('FusionSolidEnvironment')
        designTabPanels = designWorkspace.toolbarTabs.itemById('SolidTab').toolbarPanels
        dd = [x for x in designTabPanels[0].controls if isinstance(x, adsk.core.DropDownControl)]

dd[0].name #Results in Error - should give result 'pattern'
dd[0].resourceFolder #As does this one - should give result ''

 

 

I don't think it's anything I'm doing

 

Regards

Peter

 

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
648 Views
6 Replies
Replies (6)
Message 2 of 7

kandennti
Mentor
Mentor

Hi @pludikar .

 

It seems that you need to refer to the controls Property of DropDownControl.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-fb4f52e6-5926-4543-b6a3-cd145b4f53db 

 

・・・
        dd = [x for x in designTabPanels[0].controls if isinstance(x, adsk.core.DropDownControl)]

        controls = [c for c in dd[0].controls]
        [print(f'{c.commandDefinition.name}\n {c.commandDefinition.resourceFolder}') for c in controls]

 

0 Likes
Message 3 of 7

pludikar
Collaborator
Collaborator

Hi @kandennti 

 

Unfortunately referring to the controls attribute is not the issue.

 

controls = [c for c in dd[0].controls]

will produce a list of the sub controls/buttons of the dropdown.  The name and resourceFolder of the parent dropdown is what throws the error.  

 

To clarify, here's more code with some context:

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

DESIGN_WORKSPACE = 'FusionSolidEnvironment'
cmdId = 'Test'
testTab_ = None

app = adsk.core.Application.get()
ui = app.userInterface
commandDefinitions_ = ui.commandDefinitions
allWorkspaces = ui.workspaces


def run(context):
    try:
        designWorkspace :adsk.core.Workspaces = allWorkspaces.itemById(DESIGN_WORKSPACE)

        designTabPanels = designWorkspace.toolbarTabs.itemById('SolidTab').toolbarPanels

        #now create separate Test tab and clone panels 
        toolbarTabs: adsk.core.ToolbarTabs = designWorkspace.toolbarTabs
        testTab_ = toolbarTabs.itemById(cmdId + 'Tab')
        if testTab_ is None:
            testTab_ :adsk.core.ToolbarTab = toolbarTabs.add(cmdId +'Tab', 'Test')

        testTabPanels_ = testTab_.toolbarPanels
        testTabPanel_ = testTabPanels_.itemById(cmdId +'_TabPanel')

        for panel in designTabPanels:
            if cmdId in panel.id:
                continue
            testPanel = testTabPanels_.add(cmdId+'--'+panel.id, panel.name)

            for control in panel.controls:
                try:
                    if isinstance(control, adsk.core.SeparatorControl):
                        testPanel.controls.addSeparator()
                        continue
                    elif isinstance(control, adsk.core.DropDownControl):
                        dd = testPanel.controls.addDropDown(control.name, control.resourceFolder) 
#Throws runtime error - control.name and control.resourceFolder are invalid
                        for subControl in control.controls:
                            dd.controls.addCommand(subControl.commandDefinition)
                    btn = testPanel.controls.addCommand(control.commandDefinition)
                    btn.isVisible = control.isVisible
                    btn.isPromoted = control.isPromoted
                except AttributeError:
                    continue
                except RuntimeError:
                    #Breaks here anytime dropDownControl is added
                    continue
                #clearPanels() # - uncomment this to clear the test tab!!
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def clearPanels():
    designWorkspace :adsk.core.Workspaces = allWorkspaces.itemById(DESIGN_WORKSPACE)
    toolbarTabs: adsk.core.ToolbarTabs = designWorkspace.toolbarTabs
    testTab_ = toolbarTabs.itemById(cmdId + 'Tab')

    for panel in testTab_.toolbarPanels:
        for control in panel.controls:
            try:
                control.deleteMe()
            except:
                continue
        try:
            panel.deleteMe()
        except:
            pass


clearPanels()

 

If you want to run this, it'll install cloned panels under a Test Tab.  Note: that none of the dropDown controls are cloned, and the controls in the drop down are cloned.

 

Note also: I've not provided complete code - just enough to demo the issue.  You'll have to run clearPanels() (uncomment as indicated in the code and run again) to reset and delete the new Tab.

 

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 4 of 7

kandennti
Mentor
Mentor

@pludikar .

I think the native DropDownControl is designed to be able to create a DropDownControl without a name or resourceFolder.

 

I guess we have to accept this as a specification rather than a bug.

 

It seems to be difficult to create a perfect clone.

0 Likes
Message 5 of 7

pludikar
Collaborator
Collaborator

@goyals 

 

Hi @kandennti 

Sadly, I have to disagree with you - F360 has one of 2 bugs here.  

Either:

  • The documentation is wrong and misleading.  This attribute isn't being used in a toolbar, so the highlighted area below doesn't apply.  There's also nothing to suggest that this won't work for a native control.

dropdowncontrol_Name.png

or:

  • The API is giving an error when it shouldn't:  This screen shot shows that the DropDownControl is actually a valid object, but the name and resource attributes throw errors.

VSC dropdown error.png

 

It has to be one or the other, it can't be both and it's within F360's API team's power to fix it.😊

 

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 6 of 7

kandennti
Mentor
Mentor

@pludikar .

 

If you just want to point out bugs, feel free to ignore me.


I looked up the TextCommands related to toolbars.
"UI.GetCurrentCommandToolbarInfo" seems to be able to get the toolbar information of the active workspace in JSON format.


For example, "Pattern" DropDownControl in "SolidCreatePanel".

1.png

 

Find the ID "SolidCreatePanel" from the retrieved JSON and find "menus".

 

2.png

 

What is in "menus" matches the order of what appears in the toolbar panel, including separators, as far as I can tell.
If you take the order into account, you may be able to get the desired "Pattern" characters.

 

3.png

 

I'm not sure about the resource, but the color of the menu does not change when the environment is changed, so I think it can be handled by preparing a white icon.


This is just my idea of "achieving the goal".

 

0 Likes
Message 7 of 7

pludikar
Collaborator
Collaborator

Hi @kandennti 

 

That's great  - thank you.  However, I think I'm about to embark on a new learning curve with Palettes.  At the moment it's not obvious how to access TextCommands from API/Python code - but I guess that it's going to be something to do with the TextCommandPalette Object.

 

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes