Need help to create a button to toggle select all/none?

Hi,

I created a script to smartly select ALL or select NONE depending on currently selected items.

Edit: added the correction needed to work properly

Function OnClick(ByRef clickData)
    Dim cmd, selCount
    Set cmd = clickData.func.command
    selCount = clickData.func.sourcetab.selected.count
    If selCount <= 1 Then
        ' If no item or only 1 is selected then select ALL
		cmd.deselect = false
        cmd.RunCommand "Select ALL"
    Else
        ' If more than one item is selected, unselect ALL
        cmd.RunCommand "Select NONE"
    End If
End Function

But when the select ALL command runs, it selects ALL but unexpectedly deselect the currently selected item. Why ?

You need to add

cmd.deselect = false

Of course. I was searching how to apply the @nodeselect. Thanks.