scriptTable questions

scriptTable questions

Anonymous
Not applicable
361 Views
1 Reply
Message 1 of 2

scriptTable questions

Anonymous
Not applicable

Hello,

 

I'm having some problems using the cmds.scriptTable library, and the rest of the internet has not been helpful so far.  What I'm trying to do is add and remove single rows from a cmds.scriptTable.  There are built in functions to do this but they do not seem to behave in a consistent manor.  When I add two rows, and delete one of them, all of the rows seem to go blank.  This symptom goes away when I add an extra blank row at the end, but that doesn't seem like a very good solution.

 

// -- code sample that has blank last line

import maya.cmds as cmds
 
def edit_cell(row, column, value):
    return 1
 
window = cmds.window(widthHeight=(400, 300))
form = cmds.formLayout()
table = cmds.scriptTable(rows=2, columns=3, label=[(1,"Column 1")], width=420, height=400, cellChangedCmd=edit_cell, excludingHeaders=True)
cmds.scriptTable(table, cellIndex=(1,1), edit=True, cellValue="1")
cmds.scriptTable(table, cellIndex=(2,1), edit=True, cellValue="2")
cmds.scriptTable(table, edit=True, deleteRow=1)
cmds.showWindow( window )


// -- Code sample that behaves correctly

import maya.cmds as cmds

def edit_cell(row, column, value):
    return 1

window = cmds.window(widthHeight=(400, 300))
form = cmds.formLayout()
table = cmds.scriptTable(rows=2, columns=3, label=[(1,"Column 1")], width=420, height=400, cellChangedCmd=edit_cell, excludingHeaders=True)
cmds.scriptTable(table, cellIndex=(1,1), edit=True, cellValue="1")
cmds.scriptTable(table, cellIndex=(2,1), edit=True, cellValue="2")
cmds.scriptTable(table, edit=True, insertRow=3)
cmds.scriptTable(table, edit=True, deleteRow=1)
cmds.scriptTable(table, edit=True, deleteRow=2)
cmds.showWindow( window )

 

thanks in advance,

 

James

0 Likes
362 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Just in case anybody else runs into this problem, here is my solution.  Since the native remove and add flags do not work, you need to write your own functions for them.  Each function should save the state of the table in your own data structure, perform the action on that data structure, and then clear the table and repopulate it with your data structure.

 
thanks,
 
James

 

0 Likes