Expand row selectionI want to select a specific group of rows surrounding a row I can easily identify. In the instance below, I'm able to capture the row of interest, I now need to expand that by 11 rows above and 15 rows below to have the data block of interest.
Current Data Table() << Select where( Contains( As Column(2), "1st Thickness" );
Automation and ScriptingRe: Expand row selectionhi, you can use
dt = current data table();
block of interest = (dt << get selected rows()) + -11::15;
dt << Select Rows( block of interest )
Re: Expand row selectionDon't use Select Where, use Get Rows Where
It will return the row number for the row that has your 1st Thickness value,
then use Select Rows() to select the 11 rows above and 15 rows below
Re: Expand row selectionHogi
Looks interesting but gives me an error "Index argument in access or evaluation of 'Index' ,.................................."
Thanks
Re: Expand row selection@hogi approach is correct. The syntax isn't.
Here is my approach
dt = current data table();
block of interest = (dt << get selected rows())[1];
block of interest = index(block of interest-11,block of interest+15);
dt << Select Rows( block of interest );
I suggest you change your paradigm a bit to not count on getting code that you just cut and paste into your script but rather, study the code provided and then mold it into your code, given the new insights it provides.
Re: Expand row selectionFew more suggestions
Names Default To Here(1);
dt = Current Data Table();
Try(
r = (dt << get selected rows())[1];
dt << Select Where(r - 11 <= Row() <= r + 15);
);
Names Default To Here(1);
below = 11;
above = 15;
dt = Current Data Table();
r = dt << Get Selected Rows();
If(N Items(r) != 1,
Throw("Incorrect amount of rows selected");
);
rows_of_interest = Max(1, r - below)::Min(N Rows(dt), r + above);
dt << Select Rows(rows_of_interest);
Write();Re: Expand row selectionJim
This works but it only selects the additional rows for the first selected row in the matrix. I guess I should set up an iteration for each initially selected row number to capture them all?
Re: Expand row selectionJim
I added iteration and I seem to be getting what I'm after.
Thanks
dt = current data table();
Current Data Table() << Select where( Contains( As Column(2), "1st Thickness" ));
sel_rows = Current Data Table() << Get Rows where( Contains( As Column(2), "1st Thickness" ));
j=1;
For( i = 1, i <= N Items( sel_rows ), i++,
block_of_interest = (dt << get selected rows())[j];
block_of_interest = index(block_of_interest-11,block_of_interest+15);
dt << Select Rows( block_of_interest );
j=j+27;
);
Re: Expand row selectionBased on your initial message it seemed like you only wanted to select based on single row. Looping is definitely the easiest option you have and depending on your data it might be fast enough without any optimizations.
Names Default To Here(1);
dt = Current Data Table();
selrows = dt << get selected rows();
For Each({r}, selrows,
dt << Select Where(r - 11 <= Row() <= r + 15, current selection("extend"));
);
wait(0);
And a bit more complicated option
Names Default To Here(1);
dt = Current Data Table();
selrows = dt << get selected rows();
rows_of_interest = {[]};
For Each({r}, selrows,
rs = Max(1, r - 11)::Min(N Rows(dt), r + 15);
Insert Into(rows_of_interest, rs`);
);
Substitute Into(rows_of_interest, Expr(List), Expr(V Concat));
dt << select rows(rows_of_interest);
wait(0);