There are two problems with the second half of the code
If I don’t have the pop-up folder expanded in designer it throws TypeError: Window : T2T3T1 Popups/T2 Popup is not open. I can get past this by just opening up the folder.
2: For line 12 or TypeError: addRows(): 2nd arg can’t be coerced to org.python.cogsre.PySequence
I don’t know what coerced means, but the way i understand the addRows function works is addRows(dataset, int (default bottom), PySequence). both tables have same number of columns with the same headers
AddRows requires a sequence of sequences - a Python list of lists, where each sublist has as many elements as there are columns in the dataset (the types also have to match, but that’s another problem).
If you just need to add a single row, then use system.dataset.addRow, not addRows; or, pack your values into another sequence: newData2 = system.dataset.addRows(data2, [selected])
It’s very unlikely this is going to do what you want/work at all, though - if you’re allowing multi-selection on the source table, then your selected variable will have an inconsistent length, which is not compatible with the way you’re passing things into the addRows function. If you have a single-column destination dataset, then you could “transpose” the sequence with a list comprehension: newData2 = system.dataset.addRows(data2, [[row] for row in selected])
That comprehension will take an input long list: [0, 1, 2, 3]
and transpose it into a 2-d sequence of single-element lists:
I have the table set to select Single Interval. I figured since the deleteRows worked of both single or interval selection addRows would function in a similar fashion.
You were correct that what I’m doing is not compatible with the way I’m passing things into the addRows function. When I inputted your suggesting lines of code it threw a different error on the same line.
IndexError: Number of values (1) in row 1 doesn’t match number of columns (12) in dataset.
table.selectedRows is a list of row indexes. Your ultimate goal is to copy a list of row contents into your destination dataset. You will need to create a data structure (a list of lists suitable for addRows is easiest) at the source before trying to paste them into the destination.
@pturmel’s last snippet does what you need - go through each selected row, then copy the contents of each column from the source dataset into a python list (and each of those rows is then put into another list)
The output of that comprehension will be directly able to pass to system.dataset.addRows()
I am trying the same thing but getting error as long object not iterable …
deletedRows = [[vTab.getValueAt(r, c) for c in range(vTab.columnCount)] for r in selectedRow]
# for row in range(len(selectedData)):
newData=system.dataset.addRows(downTable, downSelectedRow+1, deletedRows)
vTab = system.dataset.deleteRows(vTab, selectedRow)
I want the selected rows to be deleted and deleted rows to be copied in table 2 but my above code deletes deleted rows but only one from that deleted rows(last selected row) is getted added/copied to table 2…plz help
I am trying to help, but I am struggling to understand what you are after.
Are you saying that the user selects a number of rows from Table 1, and then performs some action, maybe clicks a button, and then those selected rows should be removed from Table 1 and added to Table 2?
yes right…the below-shared code deletes selected rows in table 1 but from that selected rows only one row gets added to table 2 but I want all the selected rows to be added in table 2 …consider if I selected 3 rows from table 1 then after clicking on the button it deletes all that selected 3 rows but from that deleted rows only one row gets added to table 2