I've put together a test script to illustrate the problem below. If you run the script you will see the table header has all of it's text left justified. It is supposed to be centered. I duplicated the lines of code that are controlling the formatted text for the last column in the header and put it into the InputChangedEventHandler. If you adjust one of the slidders you will see the text change to centered in the last column. It appears that the formatting will not work until after the form is opened.
I need to fire the InputChangedEventHandler when the form opens to correct the problem.
Here is the form when it is opened:

Here is the form after one of the sliders is moved:

Eric
import adsk.core, adsk.fusion, adsk.cam, traceback
_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)
_handlers = []
_rowNumber = 0
# Event handler for the execute event.
class MyExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
pass
# _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)
cmd = adsk.core.Command.cast(args.command)
#Create table as header
#create list (nested list for each line in table. each list item should be another nested list with the last item being
# a code (ex: 't') to indicate the type of control)
textAdd = [ [ ['MATERIAL','h'],['DROP HT.','h'],['USER MIN','h'],['USER MAX','h'],['TEST NOT CENTERED','h'] ] ]
# createTable_withTextAndCtrls(self,id,name,inputs,minRows,maxRows,rowSpace,colSpace,numRows,spacing,textAdd,transparency = False)
self.createTable_withTextAndCtrls('table1','name of table',inputs,1,len(textAdd),1,1,len(textAdd),'1:1:1:1:3',textAdd,True)
# textBox_H00
# textBox_H01
# textBox_H02
# textBox_H03
# textBox_H04
#REFORMATTING TABLE TEXT IN HEADER HERE REFORMATTING TABLE TEXT IN HEADER HERE REFORMATTING TABLE TEXT IN HEADER HERE REFORMATTING TABLE TEXT IN HEADER HERE
t1 = inputs.itemById('textBox_H04')
t1.formattedText = '<div align="center", style="font-size:11px", style="color:blue" ><b>TEST NOT CENTERED</b></div>'
print('')
#REFORMATTING TABLE TEXT IN HEADER HERE REFORMATTING TABLE TEXT IN HEADER HERE REFORMATTING TABLE TEXT IN HEADER HERE REFORMATTING TABLE TEXT IN HEADER HERE
#SLIDER EXAMPLE
#create list (nested list for each line in table. each list item should be another nested list with the last item being
#addFloatSliderCommandInput(id, name,unitType, min, max, hasTwoSliders)
textAdd = [ [['Mat1','t'] , ['12','t'] , ['1.00','t'] , ['3.00','t'] , ["",1.00,3.00,True,True,'sl']] ,
[['Mat1','t'] , ['18','t'] , ['2.00','t'] , ['4.00','t'] , ["",2.00,4.00,True,True,'sl']] ]#slider
# createTable_withTextAndCtrls(self,id,name,inputs,minRows,maxRows,rowSpace,colSpace,numRows,spacing,textAdd,transparency = False)
self.createTable_withTextAndCtrls('slidderTable','slidder table',inputs,1,len(textAdd),2,2,len(textAdd),'1:1:1:1:3',textAdd,False)
# 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)
# Connect to the inputChanged event.
onInputChanged = MyCommandInputChangedHandler()
cmd.inputChanged.add(onInputChanged)
_handlers.append(onInputChanged)
print('')
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def createTable_withTextAndCtrls(self,id,name,inputs,minRows,maxRows,rowSpace,colSpace,numRows,spacing,textAdd,transparency = False):
"""textAdd = [ [ ['Hemp','t'] , ['12','t'] , ['1.00','t'] , ['3.00','t'] ,
['1.00','1.50','3.00','sl'] , (cont for additional rows) ] ] (t = text, sl = slider)"""
# Create the table.
#returnValue = commandInputs_var.addTableCommandInput(id, name, numberOfColumns, columnRatio)
table = adsk.core.TableCommandInput.cast(inputs.addTableCommandInput(id, name, numRows, spacing))
table.minimumVisibleRows = minRows
table.maximumVisibleRows = maxRows
table.columnSpacing = colSpace
table.rowSpacing = rowSpace
if transparency == False:
table.tablePresentationStyle = adsk.core.TablePresentationStyles.itemBorderTablePresentationStyle
table.hasGrid = False
else:
table.tablePresentationStyle = adsk.core.TablePresentationStyles.transparentBackgroundTablePresentationStyle
table.hasGrid = False
# Create a selection command input and add it to the table.
ct = 0
for j in range(0,len(textAdd)):
for i in range(0,len(textAdd[j])):
#returnValue = commandInputs_var.addTextBoxCommandInput(id, name, formattedText, numRows, isReadOnly)
if textAdd[j][i][len( textAdd[j][i] )-1] == 'h':
#HEADER
text = inputs.addTextBoxCommandInput('textBox_H' + str(j) + str(i),
'textBox H' + str(ct),
'<div align="center", style="font-size:10px" , style="color:blue" ><b>' + textAdd[j][i][0] + '</b></div>',
1, True)
table.addCommandInput(text, j, i, False, False)
print(text.id)
elif textAdd[j][i][len( textAdd[j][i] )-1] == 'sl':#;print( textAdd[j][i][len( textAdd[j][i] )-1] )
#SLIDER
#addFloatSliderCommandInput(id, name, unitType, min, max, hasTwoSliders)
sliderInput = inputs.addFloatSliderCommandInput('sliderFloat{}'.format(j),
'Float Slider',
str(textAdd[j][i][0]),#unitType
float(textAdd[j][i][1]),#Min
float(textAdd[j][i][2]),#Max
bool(textAdd[j][i][3]))#hasTwoSliders True or False)
table.addCommandInput(sliderInput, j, i, 0, 0)
if textAdd[j][i][4] == True: sliderInput.setText(str(textAdd[j][i][1]),str(textAdd[j][i][2]))
elif textAdd[j][i][len( textAdd[j][i] )-1] == 't':
#TEXT BOX
text = inputs.addTextBoxCommandInput('textBox' + str(j) + str(i),
'textBox ' + str(ct),
'<div align="center", style="font-size:11px" ><b>' + textAdd[j][i][0] + '</b></div>',
1,
True)
table.addCommandInput(text, j, i, False, False)
elif textAdd[j][i][len( textAdd[j][i] )-1] == 'sp':
#SPINNER
#addFloatSpinnerCommandInput(id, name, unitType, min, max, spinStep, initialValue)
#["",1.00,3.00,.1,1.00,'sp']
spinnerInput = inputs.addFloatSpinnerCommandInput('spinnerFloat{}'.format(j),
'Float Spinner',
str(textAdd[j][i][0]),#unitType
float(textAdd[j][i][1]),#Min
float(textAdd[j][i][2]),#Max
float(textAdd[j][i][3]),#spinStep
float(textAdd[j][i][4]))#initialValue
table.addCommandInput(spinnerInput, j, i, 0, 0)
ct+=1
return table
class MyCommandInputChangedHandler(adsk.core.InputChangedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
eventArgs = adsk.core.InputChangedEventArgs.cast(args)
changedInputs = eventArgs.input
inputs = eventArgs.firingEvent.sender.commandInputs
#REFORMATTING TABLE TEXT IN HEADER HERE REFORMATTING TABLE TEXT IN HEADER HERE REFORMATTING TABLE TEXT IN HEADER HERE REFORMATTING TABLE TEXT IN HEADER HERE
t1 = inputs.itemById('textBox_H04')
t1.formattedText = '<div align="center", style="font-size:11px", style="color:blue" ><b>TEST CENTERED</b></div>'
print('')
#REFORMATTING TABLE TEXT IN HEADER HERE REFORMATTING TABLE TEXT IN HEADER HERE REFORMATTING TABLE TEXT IN HEADER HERE REFORMATTING TABLE TEXT IN HEADER HERE
except:
_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', 'Static Stress Analysis', 'Static Stress Analysis', '')
# 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()))