VBScript Select Question

v11.8.2 Beta on Windows 7 64-bit. If I run the following simple test script against a tab where one or more files is selected, the end result is that no files are selected.

Dim cmd Set cmd = DOpus.NewCommand cmd.SetSourceTab DOpus.listers(0).activetab cmd.runcommand "Select NONE" cmd.runcommand "Select ALL"
The Select NONE statement is evidently being executed but not the Select ALL. Am I doing something wrong?

Regards, AB

For me it seems to work. Unfortunately I have no idea why it fails for you.

How did you run it? Presumably from a toolbar button? What version of Windows and Opus?

I have now tried the same code from a toolbar button on a Windows 7 laptop, a Windows 8.1 desktop, and a vanilla W7 configuration in a VM, just in case there is something in my config that is affecting the outcome. Same behaviour in all cases.

Regards, AB

I ran it inside the CLI of DOpus (command: cli) on a Win7-x64 with v11.8.2.
Using the code in a script button does indeed yield a different result, no files selected at the end. I changed the code to use data.func.sourcetab instead of DOpus.listers(0).activetab btw.

I thought it might be related to the fact, that DO deselects affected files (if configured to do so), so I tried to "disconnect" the script from the file listing by using data.func.command.ClearFiles().
That helps, but for some weird reason, just echoing data.func.command.files.count in the beginning of the script, will make "SELECT ALL" work, at least for all items that were not selected before. You'd need to use ClearFiles() additionally to really get all items selected afterwards. Do I fully understand what's going on? I guess I do not. o)

[code]@script vbscript

Function OnClick(data)
'one of the following two code-lines needs to run to make SELECT ALL have an effect
DOpus.Output "Selected items: " & data.func.command.files.count
'if ClearFiles() is used, any previously selected item will be selected afterwards too, if not, the selection only toggles
data.func.command.ClearFiles()

Dim cmd
Set cmd = DOpus.NewCommand
cmd.SetSourceTab data.func.sourcetab
cmd.runcommand "Select NONE"
cmd.runcommand "Select ALL"

End Function
[/code]

Me neither! :laughing:
Thanks for the independent testing.

Regards. AB

I switched things around as I couldn't see a need for an additional command object (scriptbutton):

Function OnClick(data)
        Set cmd=data.func.command
        cmd.SetSourceTab DOpus.listers(0).activetab 'Not really needed in a scriptbutton, but.
        cmd.deselect=False
        cmd.runcommand "Select NONE"
        cmd.runcommand "Select ALL"
End Function

The .deselect property does the same as @nodeselect in a regular command.
When testing in CLI the same works without wrapping it in a function if you replace "data.func.command" with "DOpus.NewCommand".

My original code uses cmd.SetSourceTab DOpus.listers(0).activetab so it can be run from a floating toolbar or system wide hotkey. On related matters, I note that DOpus.listers.count throws an error if no listers are open.

Object doesn't support this property or method: 'DOpus.listers.count' (0x800a01b6)

It would be useful if it returned zero so that commands that were not launched from a fixed toolbar could test to see if any listers were available.

Regards, AB

The separate DOpus.listers.count problem was fixed in 11.8.3.

Is the problem in the root post still there? What are the steps to reproduce that? What kind of listers are open, and where/how do you run the script code to make it happen? The code seems to work correctly via both a toolbar button and the CLI, at least in 11.8.3.

[quote="leo"]The separate DOpus.listers.count problem was fixed in 11.8.3.

Is the problem in the root post still there? What are the steps to reproduce that? What kind of listers are open, and where/how do you run the script code to make it happen? The code seems to work correctly via both a toolbar button and the CLI, at least in 11.8.3.[/quote]
Thanks for the DOpus.listers.count fix. The original Select All problem is still there. I'll attach an OCB. It is almost vanilla but includes a toolbar called Test with a single "Select All" button that launches the command. After clicking the button, nothing is selected.


Regards, AB

v11.8c.ocb (1.47 MB)

What's the point of doing Select None followed by Select All anyway?

The problem is with Select All. When it manifested I thought maybe it's a more general problem with Select so I injected a Select None to see how that went. Start with one or more files selected and you will see that it works just fine whereas Select All fails with or without the preceding Select None.

Regards, AB

The problem is with Select All. When it manifested I thought maybe it's a more general problem with Select so I injected a Select None to see how that went. Start with one or more files selected and you will see that it works just fine whereas Select All fails with or without the preceding Select None.

Regards, AB[/quote]
I wonder, did you see my earlier post?

Yes I did, but in my opinion there is still a problem as can be demonstrated with this button. Nothing is selected after it has been run.


Regards, AB

Yes I did, but in my opinion there is still a problem as can be demonstrated with this button. Nothing is selected after it has been run.
[/quote]
I was wondering about similar code myself for a few seconds, but I found that a scriptbutton already
have a command object from the beginning, and if that object's deselect property isn't changed it won't work.

The real/main command object is provided to a OnClick handler/function through ClickData.Func.Command.
That is the reason I said you were creating an additional command object.

Btw, the first (and only) sentence in the OnClick description says: "The OnClick event is the main entry point for a script function."

If you run the Select command on the correct Command object (the one given to your OnClick function, not a newly created one) it will work as expected.

Alterbatively, if you set that object not to deselect when it is complete then it should work even if another command object is then used for some reason.

Running select commands in a second command object means the main one has no knowledge of them and will not automatically avoid deselecting the things they select.

Yes, understood. My challenge is to force a script that is launched from a floating toolbar to operate on the "foreground" lister/tab rather than the source lister/tab. From a fixed toolbar the sample code selects all items on the associated parent lister/tab. However, from a floating toolbar it operates on whatever lister is currently set as Source. When more than one lister is open, the foreground lister might be Dest or Off. There is no way that I can see to force the foreground lister to become the target for subsequent commands.

[code]@script vbscript

Function OnClick(ocd)
with ocd.func.command
.ClearFiles()
.runcommand "Select ALL"
end with
End Function[/code]
Regards, AB

This seems to meet all those requirements:

[code]@script vbscript

Function OnClick(ClickData)
Set cmd = ClickData.Func.Command
cmd.SetSourceTab DOpus.listers(0).activetab
cmd.Deselect = False
cmd.RunCommand "Select ALL"
End Function[/code]

Excellent. Thanks Leo.

Regards, AB

Just for me: What's the line "cmd.SetSourceTab DOpus.listers(0).activetab" for? Isn't it obsolete?

That's the instruction that selects the FOREGROUND lister as the target for subsequent commands. Without it, the target is the SOURCE lister which is not necessarily the same as the FOREGROUND lister when you have multiple listers open. When a script is launched from a floating toolbar there is no inherent association with a specific lister so the default is to use the SOURCE lister.

Regards, AB