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: 

Troubles with Table CommandInputs

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
edidos
498 Views, 6 Replies

Troubles with Table CommandInputs

I am having an issue where, when I have toolbarCommandInputs and more than one row in the table, everything except the first row piles up in the bottom left corner.

 

table1 = group2.children.addTableCommandInput('table1', '', 4, "3:1:2:3")
table1.minimumVisibleRows = 4
table1.maximumVisibleRows = 8

updateTable(table1, [[[1,2,3], [1], 2, True, 105]])

boolValue2 = table1.commandInputs.addBoolValueInput('boolValue2', 'New', False, '', True)
table1.addToolbarCommandInput(boolValue2)

boolValue3 = table1.commandInputs.addBoolValueInput('boolValue3', 'Delete', False, '', True)
table1.addToolbarCommandInput(boolValue3)


def updateTable(table, shapes):
    selected = table.selectedRow

    table.clear()

    for i, s in enumerate(shapes):
        dd = table.commandInputs.addDropDownCommandInput('dropDownTable{}'.format(i), '', 0)
        dd.listItems.add("Flat", s[2]==0, '')
        dd.listItems.add("Cylinder", s[2]==1, '')
        dd.listItems.add("Sphere", s[2]==2, '')
        dd.listItems.add("Plane", s[2]==3, '')
        dd.listItems.add("Line", s[2]==4, '')
        dd.listItems.add("Point", s[2]==5, '')
        table.addCommandInput(dd, i, 0)

        bv = table.commandInputs.addBoolValueInput('boolValueTable{}'.format(i), 'Auto', True)
        bv.value = s[3]
        table.addCommandInput(bv, i, 1)

        tb = table.commandInputs.addTextBoxCommandInput('textBoxTable{}'.format(i), '', '{} ({})'.format(len(s[0])+len(s[1]), len(s[0])), 1, True)
        table.addCommandInput(tb, i, 2)

        fs = table.commandInputs.addFloatSpinnerCommandInput('floatSpinnerTable{}'.format(i), '', '', 0, 100000, 5, s[4]) 
        table.addCommandInput(fs, i, 3)

    table.selectedRow = selected
6 REPLIES 6
Message 2 of 7
kandennti
in reply to: edidos

Hi edidos.

 

I created a script like this to reproduce the problem.
However, the problem could not be reproduced.

#Fusion360API Python script

import adsk.core, adsk.fusion, traceback

_ui  = None
_handlers = []

class MyCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            cmd = adsk.core.Command.cast(args.command)
            inputs = cmd.commandInputs
            
            onDestroy = MyCommandDestroyHandler()
            cmd.destroy.add(onDestroy)
            _handlers.append(onDestroy)

            table1 = inputs.addTableCommandInput('table1', '', 4, "3:1:2:3")
            table1.minimumVisibleRows = 4
            table1.maximumVisibleRows = 8

            updateTable(table1, [
                [[1,2,3], [1], 0, True, 105],
                [[1,2,3], [1], 1, True, 105],
                [[1,2,3], [1], 2, True, 105],
                [[1,2,3], [1], 3, True, 105],
                [[1,2,3], [1], 4, True, 105],
                [[1,2,3], [1], 5, True, 105]])

            boolValue2 = table1.commandInputs.addBoolValueInput('boolValue2', 'New', False, '', True)
            table1.addToolbarCommandInput(boolValue2)

            boolValue3 = table1.commandInputs.addBoolValueInput('boolValue3', 'Delete', False, '', True)
            table1.addToolbarCommandInput(boolValue3)

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

def updateTable(table, shapes):
    selected = table.selectedRow

    table.clear()

    for i, s in enumerate(shapes):
        dd = table.commandInputs.addDropDownCommandInput('dropDownTable{}'.format(i), '', 0)
        dd.listItems.add("Flat", s[2]==0, '')
        dd.listItems.add("Cylinder", s[2]==1, '')
        dd.listItems.add("Sphere", s[2]==2, '')
        dd.listItems.add("Plane", s[2]==3, '')
        dd.listItems.add("Line", s[2]==4, '')
        dd.listItems.add("Point", s[2]==5, '')
        table.addCommandInput(dd, i, 0)

        bv = table.commandInputs.addBoolValueInput('boolValueTable{}'.format(i), 'Auto', True)
        bv.value = s[3]
        table.addCommandInput(bv, i, 1)

        tb = table.commandInputs.addTextBoxCommandInput('textBoxTable{}'.format(i), '', '{} ({})'.format(len(s[0])+len(s[1]), len(s[0])), 1, True)
        table.addCommandInput(tb, i, 2)

        fs = table.commandInputs.addFloatSpinnerCommandInput('floatSpinnerTable{}'.format(i), '', '', 0, 100000, 5, s[4]) 
        table.addCommandInput(fs, i, 3)

    table.selectedRow = selected
            
class MyCommandDestroyHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            adsk.terminate()
        except:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

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

        global _ui
        _ui = app.userInterface
        
        cmdDef = _ui.commandDefinitions.itemById('table_test')
        if cmdDef:
            cmdDef.deleteMe()

        cmdDef = _ui.commandDefinitions.addButtonDefinition('table_test', 'table_test', 'table_test')

        onCommandCreated = MyCommandCreatedHandler()
        cmdDef.commandCreated.add(onCommandCreated)
        _handlers.append(onCommandCreated)
        
        cmdDef.execute()

        adsk.autoTerminate(False)
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

I believe the fastest way to solve the problem is to publish code that reproduces the problem.

 

Message 3 of 7
edidos
in reply to: kandennti

I am very sorry for not testing it on its own. I thought that no other part of the script would be in any way related to the table but I seem to be wrong. Here is a Link  to a repo containing the script and the required libraries. I was not able to attach it as a zip.

Message 4 of 7
edidos
in reply to: kandennti

I have copied your test into a new script and it reproduced the same Issue.

I will add OS and version info as this may be a Fusion360 bug. 

 

Screenshot 2019-12-13 at 13.53.16.png

 

Message 5 of 7
edidos
in reply to: edidos

I was hoping to edit the main post but can't figure out how:

 

OS: macOS 10.14.5

Fusion: 2.0.7029

Message 6 of 7
kandennti
in reply to: edidos

The source code of the link destination is amazing. I am looking forward to the completion of the add-in.

 

This is the state I tried here. (win10 64bit home)

1.png

Unfortunately, we could not reproduce the problem.

 

 

It may be irrelevant, but I used TableCommandInput when I made this add-in in the past.
https://github.com/kantoku-code/Fusion360-TSplineBodyDoorway 
The reason is unknown, but since the display was incorrect with the combination of "TableCommandInput" and "TextBoxCommandInput" at this time, there was an experience that the display became correct when changed to "StringValueCommandInput".

Message 7 of 7
edidos
in reply to: kandennti

Thank you.

This is the workaround I am using now since there were other problems with text boxes, like when there are more rows than can be displayed at once. String inputs seem to have problems as well, the read-only does not seem to work reliably. I am now undoing any changes to the string input in the input changed handler. It feels acceptable for now, I hope all these things get fixed eventually. I will accept this as a solution since it seems to be the best workaround at this moment.

 

I believe this add-in will be very useful for working with STL's I hope to release an initial working version in a few weeks.

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