Replacing table rows in certain range

Hi guys, let’s say I have a table with tone of rows, and I’d like to empty all the rows from 33 to 50 or any given range with a little script. I tried writing for loop with little success due to lack of coding experience. How do I code this, since n.replaceRow() only takes one variable? and also why n.replaceRow(0) doesn’t replace a cell with an empty one as it says it should in TD documentation?

Hey @GJG,

If you would want to remove any values from a range of rows, you should be able to do so like this:

# save a reference to my table in a variable
myTable = op('table1')

# loop over a range starting at 33 to 50
for i in range(33,51):
	myTable.replaceRow(i)

Are you getting an error when running your example?

cheers
Markus

Hi Markus! thanks for quick reply. Your code works! :slight_smile: I just had to add ‘’ in myTable.replaceRow( i, ‘’ ) and it did the job. For some reason leaving just one argument doesn’t empty the cells anymore.

Anyways, thanks again mate and have a jolly lockdown :slight_smile:

Hi @GJG,

what build and OS are you working in? Wondering as I don’t have that issue here at all…

Cheers
Markus

I’m using Catalina on mac

latest build? TouchDesigner 2020.20625?

Yeah, everything latest.

If you wouldn’t mind me asking. Let’s say instead of replacing cells with nothing I’d like to replace them with all the rows from another table, how do I structure the argument?

for i in range (minRange,maxRange):
    table1.replaceRow(i,table2[smthn?, 0])

Thanks Again :slight_smile:

Hey @GJG,

very starnge, we’ll investigate the required empty string…

But to your question, this worked for me:

a = op('/project1/table1')
b = op('/project1/table2')

for i in range(minRange, maxRange):
	a.replaceRow(i, b.row(i))

cheers
Markus

You are the best, thanks Markus!