Button to toggle selected by checkbox?

What would I need to add to, or combine with thisSelect HIDEUNSEL NOPATTERNto make this command toggle on and off? Of course I am putting it in a button. Thanks

(If the button editor is in single-line mode, click Advanced at the bottom.)

Set the button's Function type to Script Function, then paste this as the body:

@script jscript

function OnClick(clickData)
{
	var cmd = clickData.func.command;
	if (clickData.func.sourcetab.selected.count == 0)
	{
		cmd.RunCommand("Select NOPATTERN SHOWHIDDEN");
	}
	else
	{
		cmd.RunCommand("Select HIDEUNSEL NOPATTERN");
		cmd.RunCommand("Select NONE");
	}
}

If anything is selected, it will hide everything that is not selected.

If nothing is selected, it will reveal all the things that had been hidden by that method previously.

Works great! Did not know ways to do this, but also did not know about count as a property of the Item object. To know it now is useful in many ways for scripting. Thanks

It's not a property of the Item object actually... clickData.func.sourcetab.selected returns a collection of Item objects, and all collections in Opus support various helper properties like Count.

Good times.

OK, Good to know! Is there a listing of these helper properties or are they similar to the general construct of a base object (when it applies) in OOP? This is very helpful, and answers many questions I have regarding scripting! Thanks a lot!

Opus's own scripting objects are documented in the manual.

Generic collections are part of Windows scripting and not something Opus adds, but you can find some examples of how to deal with them pinned to the top of the script development forum.

Thanks!

Where can you find this button editor? I want to play around with it. It's not 'Tools/Opus CLI / Ad-Hoc Script Editor' right?

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Editing_the_Toolbar.htm