Multi-selecting items from a given selection

Discuss and share scripts and script files...
Post Reply
Norn
Posts: 417
Joined: 24 Oct 2021 16:10

Multi-selecting items from a given selection

Post by Norn »

Multi-selecting items from a given selection:
Selecting the next to all selected items.
Selecting the odd row items of all selected items.
Selecting the even row items of all selected items.

The last popup menu script combines the previous three scripts.
How to use and execute a script: viewtopic.php?f=7&t=6560

Code: Select all

//Function : Selecting the next to all selected items
//Created  : 2022-06-05
//Modified : 2022-06-05
//Version  : 1.0

//Get selectedItems
 $selectedItems = "<get SelectedItemsPathNames>";

//First item of selectedItems
 $start = gettoken($selectedItems, 1, <crlf>);

//Last item of selectedItems
 $end = gettoken($selectedItems, -1, <crlf>);

//Get row number of $start
 $start = row($start);

// Get row number of $end, then +1
 $end = row($end)+1;

//Select all items from row $start to row $end
 sel $start, $end;

//Get selectedItems, then deselect all
 $list = "<get SelectedItemsPathNames>"; sel;



//Foreach $selectedItems [View the Help file "Foreach Loops"]
 foreach($item, $selectedItems, "<crlf>") {
    //Foreach $list
    foreach($item2, $list, "<crlf>") {
	   The $case variable is a switch, enable to selecting every $item2 in foreach loop. if $item == $item2 {$case = "1";} next $item2 will be selected, $item2 is next to $item
	   if $case == "1" {selectitems $item2, , , a; $case = "0";}    //selectitems $item, , , a;   ->   Add $item to the current selections
	   if $item == $item2 {$case = "1";}
	   }
	 }

Code: Select all

//Function: Multi-selecting items from a given selection (1, 3, 5 . . . 15 . . . 999 . . .)
//Created : 2022-06-05
//Modified: 2022-06-05
//Version : 1.0

//Get selectedItems
 $selectedItems = "<get SelectedItemsPathNames>";

//Deselect all
 sel;

//First item of selectedItems
 $start = gettoken($selectedItems, 1, <crlf>);

//Last item of selectedItems
 $end = gettoken($selectedItems, -1, <crlf>);



//The $case variable is a switch
 $case = "1";

//Foreach $selectedItems [View the Help file "Foreach Loops"]
 foreach($item, $selectedItems, "<crlf>") {
	   //The $case variable is a switch, enable to selecting every $item in foreach odd loop (or every $item in foreach even loop). For example: row 1, row 3, row 5 or row 2, row 4, row 6 of the selected list
	   if $case == "2" {$case = "0";}
	   if $case == "1" {selectitems $item, , , a; $case = "2";}    //selectitems $item, , , a;   ->   Add $item to the current selections
	   if $case == "0" {$case = "1";}
	   }

Code: Select all

//Function: Multi-selecting items from a given selection (2, 4, 6 . . . 16 . . . 1000 . . .)
//Created : 2022-06-05
//Modified: 2022-06-05
//Version : 1.0

//Get selectedItems
 $selectedItems = "<get SelectedItemsPathNames>";

//Deselect all
 sel;

//First item of selectedItems
 $start = gettoken($selectedItems, 1, <crlf>);

//Last item of selectedItems
 $end = gettoken($selectedItems, -1, <crlf>);



//The $case variable is a switch
 $case = "1";

//Foreach $selectedItems [View the Help file "Foreach Loops"]
 foreach($item, $selectedItems, "<crlf>") {
	   //The $case variable is a switch, enable to selecting every $item in foreach odd loop (or every $item in foreach even loop). For example: row 1, row 3, row 5 or row 2, row 4, row 6 of the selected list
	   if $case == "1" {$case = "0";}
	   if $case == "2" {selectitems $item, , , a; $case = "1";}    //selectitems $item, , , a;   ->   Add $item to the current selections
	   if $case == "0" {$case = "2";}
	   }
Popup menu:

Code: Select all

//Function: Multi-selecting items from a given selection
//Created : 2022-06-05
//Modified: 2022-06-05
//Version : 1.0

"Multi-selecting items from a given selection (1, 3, 5 . . . 15 . . .)";
//Get selectedItems
 $selectedItems = "<get SelectedItemsPathNames>";

//Deselect all
 sel;

//First item of selectedItems
 $start = gettoken($selectedItems, 1, <crlf>);

//Last item of selectedItems
 $end = gettoken($selectedItems, -1, <crlf>);



//The $case variable is a switch
 $case = "1";

//Foreach $selectedItems [View the Help file "Foreach Loops"]
 foreach($item, $selectedItems, "<crlf>") {
	   //The $case variable is a switch, enable to selecting every $item in foreach odd loop (or every $item in foreach even loop). For example: row 1, row 3, row 5 or row 2, row 4, row 6 of the selected list
	   if $case == "2" {$case = "0";}
	   if $case == "1" {selectitems $item, , , a; $case = "2";}    //selectitems $item, , , a;   ->   Add $item to the current selections
	   if $case == "0" {$case = "1";}
	   }






"Multi-selecting items from a given selection (2, 4, 6 . . . 16 . . .)";
//Get selectedItems
 $selectedItems = "<get SelectedItemsPathNames>";

//Deselect all
 sel;

//First item of selectedItems
 $start = gettoken($selectedItems, 1, <crlf>);

//Last item of selectedItems
 $end = gettoken($selectedItems, -1, <crlf>);



//The $case variable is a switch
 $case = "1";

//Foreach $selectedItems [View the Help file "Foreach Loops"]
 foreach($item, $selectedItems, "<crlf>") {
	   //The $case variable is a switch, enable to selecting every $item in foreach odd loop (or every $item in foreach even loop). For example: row 1, row 3, row 5 or row 2, row 4, row 6 of the selected list
	   if $case == "1" {$case = "0";}
	   if $case == "2" {selectitems $item, , , a; $case = "1";}    //selectitems $item, , , a;   ->   Add $item to the current selections
	   if $case == "0" {$case = "2";}
	   }






"Selecting the next to all selected items";
//Get selectedItems
 $selectedItems = "<get SelectedItemsPathNames>";

//First item of selectedItems
 $start = gettoken($selectedItems, 1, <crlf>);

//Last item of selectedItems
 $end = gettoken($selectedItems, -1, <crlf>);

//Get row number of $start
 $start = row($start);

//Get row number of $end, then +1
 $end = row($end)+1;

//Select all items from row $start to row $end
 sel $start, $end;

//Get selectedItems, then deselect all
 $list = "<get SelectedItemsPathNames>"; sel;



//Foreach $selectedItems [View the Help file "Foreach Loops"]
 foreach($item, $selectedItems, "<crlf>") {
    //Foreach $list
    foreach($item2, $list, "<crlf>") {
	   //The $case variable is a switch, enable to selecting every $item2 in foreach loop. if $item == $item2 {$case = "1";} next $item2 will be selected, $item2 is next to $item
	   if $case == "1" {selectitems $item2, , , a; $case = "0";}    //selectitems $item, , , a;   ->   Add $item to the current selections
	   if $item == $item2 {$case = "1";}
	   }
	 }
Attachments
Multi-selecting items from a given selection.gif
Multi-selecting items from a given selection.gif (1.15 MiB) Viewed 1582 times
Last edited by Norn on 06 Jun 2022 20:03, edited 3 times in total.
Win10, Win11 @100% 2560x1440 22H2

Filehero
Posts: 2645
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: Multi-selecting items from a given selection

Post by Filehero »

I appreciate your engagement, but I think some introducing words would be of some help especially to XY script novices. ;)

Anyway, @Don:

Regarding if $case == "1" {selectitems $item2, , , a; $case = "0";}

Shouldn't this or if 1 == 1 { msg "Yes" }; pop a "Dubios Syntax" message with "Syntax Checking" on?

From the manual's corresponding section:
if (expression) {
 statement;
}


Remarks
· Parentheses around the expression are mandatory.
· Curly braces around the statement block are mandatory (even if there is only one statement).

admin
Site Admin
Posts: 60611
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Multi-selecting items from a given selection

Post by admin »

Filehero wrote: 05 Jun 2022 21:07 Shouldn't this or if 1 == 1 { msg "Yes" }; pop a "Dubios Syntax" message with "Syntax Checking" on?
Yes, I would have expected that too, but it is tolerated. I don't really see any reason to be stricter here.

Filehero
Posts: 2645
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: Multi-selecting items from a given selection

Post by Filehero »

admin wrote: 06 Jun 2022 11:51 Yes, I would have expected that too, but it is tolerated. I don't really see any reason to be stricter here.
Me too, I was just curious.

Norn
Posts: 417
Joined: 24 Oct 2021 16:10

Re: Multi-selecting items from a given selection

Post by Norn »

Ok, I edited. :ninja:
Win10, Win11 @100% 2560x1440 22H2

Filehero
Posts: 2645
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: Multi-selecting items from a given selection

Post by Filehero »

Norn wrote: 06 Jun 2022 19:25 Ok, I edited. :ninja:
Good move! :)

Post Reply