Message 1 of 3
Placing sliders inside a table
Not applicable
02-20-2020
08:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm just getting started with the API and I'm trying to mock up a visual of what I would like my add-in to look like. For a particular piece of user feedback I would like to display several sliders inside a table, this would allow me to add other text/information in cells to the left and right of the slider, on the same row.
When I try and use table.addCommandInput to place a slider inside a table cell it often display's below the table instead. Doing this also breaks the row order for the table. Sample code and screenshot are below, the example table I am referring to is the last one at the bottom of the dialogue box.
Any ideas as to what is causing this would be much appreciated.
import adsk.core, adsk.fusion, adsk.cam, traceback
_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)
_handlers = []
# Event handler for the execute event.
class MyExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
_ui.messageBox('Command executed.')
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Event handler for the destroy event.
class MyDestroyHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
adsk.terminate()
# Event handler for the commandCreated event.
class MyCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
eventArgs = adsk.core.CommandCreatedEventArgs.cast(args)
inputs = adsk.core.CommandInputs.cast(eventArgs.command.commandInputs)
# Create the table.
tableCount = 0
textBoxCount = 0
table = adsk.core.TableCommandInput.cast(inputs.addTableCommandInput('table' + str(tableCount), 'Inputs', 2, '1:1'))
table.minimumVisibleRows = 3
table.maximumVisibleRows = 3
table.columnSpacing = 1
table.rowSpacing = 1
table.tablePresentationStyle = adsk.core.TablePresentationStyles.itemBorderTablePresentationStyle
table.hasGrid = False
tableCount += 1
# Create a selection command input and add it to the table.
for j in range(3):
text = inputs.addStringValueInput('texta' + str(textBoxCount), 'Text ' + str(textBoxCount), 'Text ' + str(textBoxCount))
text.isReadOnly = True
table.addCommandInput(text, j, 0, False, False)
text = inputs.addStringValueInput('textb' + str(textBoxCount), 'Text ' + str(textBoxCount), 'Some more text ' + str(textBoxCount))
text.isReadOnly = True
table.addCommandInput(text, j, 1, False, False)
textBoxCount += 1
table = adsk.core.TableCommandInput.cast(inputs.addTableCommandInput('table' + str(tableCount), 'Inputs', 2, '1:1'))
table.minimumVisibleRows = 3
table.maximumVisibleRows = 3
table.columnSpacing = 1
table.rowSpacing = 1
table.tablePresentationStyle = adsk.core.TablePresentationStyles.transparentBackgroundTablePresentationStyle
table.hasGrid = False
tableCount += 1
# Create a selection command input and add it to the table.
for j in range(3):
text = inputs.addStringValueInput('texta' + str(textBoxCount), 'Text ' + str(textBoxCount), 'Text ' + str(textBoxCount))
text.isReadOnly = True
table.addCommandInput(text, j, 0, False, False)
text = inputs.addStringValueInput('textb' + str(textBoxCount), 'Text ' + str(textBoxCount), 'Some more text ' + str(textBoxCount))
text.isReadOnly = True
table.addCommandInput(text, j, 1, False, False)
textBoxCount += 1
table = adsk.core.TableCommandInput.cast(inputs.addTableCommandInput('table' + str(tableCount), 'Inputs', 3, '1:1:1')) #1:1:1 parameter controls the number of columns, '3' is number of columns but doesn't seem to do anything'
table.minimumVisibleRows = 3
table.maximumVisibleRows = 3
table.columnSpacing = 1
table.rowSpacing = 1
table.tablePresentationStyle = adsk.core.TablePresentationStyles.itemBorderTablePresentationStyle
table.hasGrid = False
tableCount += 1
stringInput = inputs.addStringValueInput('string1', '', 'Entry 1')
stringInput.isReadOnly = True
table.addCommandInput(stringInput, 0, 0, 0, 0)
stringInput = inputs.addStringValueInput('string1', '', 'Entry 2')
stringInput.isReadOnly = True
table.addCommandInput(stringInput, 1, 1, 0, 0)
stringInput = inputs.addStringValueInput('string1', '', 'Entry 3')
stringInput.isReadOnly = True
table.addCommandInput(stringInput, 2, 2, 0, 0)
stringInput = inputs.addStringValueInput('string1', '', '<div align="center">Entry 4</div>')
stringInput.isReadOnly = True
table.addCommandInput(stringInput, 0, 2, 0, 0) #row, column, ??, ??
table = adsk.core.TableCommandInput.cast(inputs.addTableCommandInput('table' + str(tableCount), 'Inputs', 1, '1'))
table.minimumVisibleRows = 1
table.maximumVisibleRows = 1
table.columnSpacing = 1
table.rowSpacing = 10
table.tablePresentationStyle = adsk.core.TablePresentationStyles.itemBorderTablePresentationStyle
table.hasGrid = False
tableCount += 1
textboxInput = inputs.addTextBoxCommandInput('readonly_textBox', 'Text Box 1', '<div align="center">This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. </div>', 2, True)
textboxInput.isReadOnly = True
textboxInput.numRows = 6
table.addCommandInput(textboxInput, 0, 0, 0, 0) #row, column, ??, ??
#only known way to centre text inside a table looks to be to create a centered text box and then put this inside the table
table = adsk.core.TableCommandInput.cast(inputs.addTableCommandInput('table' + str(tableCount), 'Inputs', 1, '1'))
table.minimumVisibleRows = 3
table.maximumVisibleRows = 3
table.columnSpacing = 1
table.rowSpacing = 20
table.tablePresentationStyle = adsk.core.TablePresentationStyles.itemBorderTablePresentationStyle
table.hasGrid = False
tableCount += 1
ImageInput = inputs.addImageCommandInput('image', 'Image', "resources/image.png")
ImageInput.isReadOnly = True
table.addCommandInput(ImageInput, 0, 0, 0, 0) #row, column, ??, ??
textlineInput = inputs.addTextBoxCommandInput('readonly_textBox', '', 'This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. This is an example of a read-only text box. ', 2, True)
textlineInput.numRows = 6
table = adsk.core.TableCommandInput.cast(inputs.addTableCommandInput('table' + str(tableCount), 'Inputs', 4, '1:2:1:1')) #1:1:1 parameter controls the number of columns, '3' is number of columns but doesn't seem to do anything'
table.minimumVisibleRows = 3
table.maximumVisibleRows = 10
table.columnSpacing = 1
table.rowSpacing = 1
table.tablePresentationStyle = adsk.core.TablePresentationStyles.itemBorderTablePresentationStyle
table.hasGrid = False
tableCount += 1
sliderinput = inputs.addIntegerSliderCommandInput('intSlider', 'Integer Slider', 0, 100)
sliderinput.valueOne = 66
sliderinput.isEnabled = False
sliderinput.isFullWidth = False
table.addCommandInput(sliderinput, 0, 1, 0, 0)
#table.addCommandInput(sliderinput, 1, 1, 0, 0)
sliderinput3 = inputs.addIntegerSliderCommandInput('intSlider3', 'Integer Slider3', 0, 100)
sliderinput3.valueOne = 99
sliderinput3.isEnabled = False
sliderinput3.isFullWidth = False
table.addCommandInput(sliderinput, 1, 1, 0, 0)
#sliderinput2 = inputs.addFloatSliderCommandInput('floatSlider', 'Float Slider', 'percent', 0, 100.0, False)
#sliderinput2.valueOne = 66.6
#sliderinput2.isEnabled = False
#table.addCommandInput(sliderinput2, 1, 1, 0, 0)
stringInput = inputs.addStringValueInput('string8', '', 'Name 8')
stringInput.isReadOnly = True
table.addCommandInput(stringInput, 1, 0, 0, 0)
stringInput = inputs.addStringValueInput('string9', '', 'Name 9')
stringInput.isReadOnly = True
table.addCommandInput(stringInput, 1, 2, 0, 0)
stringInput = inputs.addStringValueInput('string10', '', 'Name 10')
stringInput.isReadOnly = True
table.addCommandInput(stringInput, 1, 3, 0, 0)
stringInput = inputs.addStringValueInput('string1', '', 'Name 1')
stringInput.isReadOnly = True
table.addCommandInput(stringInput, 0, 0, 0, 0)
stringInput = inputs.addStringValueInput('string2', '', 'Name 2')
stringInput.isReadOnly = True
table.addCommandInput(stringInput, 0, 2, 0, 0)
stringInput = inputs.addStringValueInput('string3', '', 'Name 3')
stringInput.isReadOnly = True
table.addCommandInput(stringInput, 0, 3, 0, 0) #row, column, ??, ??
stringInput = inputs.addStringValueInput('string4', '', 'Name 4')
stringInput.isReadOnly = True
table.addCommandInput(stringInput, 3, 0, 0, 0) #row, column, ??, ??
stringInput = inputs.addStringValueInput('string5', '', 'Name 5')
stringInput.isReadOnly = True
table.addCommandInput(stringInput, 3, 1, 0, 0) #row, column, ??, ??
#message = '<div align="center">A "full width" message using <a href="http:fusion360.autodesk.com">html.</a></div>'
#tab1ChildInputs.addTextBoxCommandInput('fullWidth_textBox', '', message, 1, True)
# Connect to command execute.
onExecute = MyExecuteHandler()
eventArgs.command.execute.add(onExecute)
_handlers.append(onExecute)
# Connect to the command terminate.
onDestroy = MyDestroyHandler()
eventArgs.command.destroy.add(onDestroy)
_handlers.append(onDestroy)
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def run(context):
try:
global _app, _ui
_app = adsk.core.Application.get()
_ui = _app.userInterface
# Create a command.
cmd = _ui.commandDefinitions.itemById('tableTest')
if cmd:
cmd.deleteMe()
cmd = _ui.commandDefinitions.addButtonDefinition('tableTest', 'Table Test', 'Table Test', '')
# Connect to the command create event.
onCommandCreated = MyCommandCreatedHandler()
cmd.commandCreated.add(onCommandCreated)
_handlers.append(onCommandCreated)
# Execute the command.
cmd.execute()
# Set this so the script continues to run.
adsk.autoTerminate(False)
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))