DO12 - Libraries and Select FROMSCRIPT

I want to select files in Libraries by script (see below for minimalist script) but nothing is selected.

Realpath = C:\Temp\temp\temp.txt

Libpath = lib://Temp/temp/temp.txt

[code]Option Explicit

Function OnInit(initData)
initData.name = "Command_Test"
initData.min_version = "12"
InitData.group = "++ Test ++"
initData.default_enable = True
End Function

Function OnAddCommands(addCmdData)
Dim cmd: Set cmd = addCmdData.AddCommand()
cmd.name = "Test"
cmd.method = "OnTest"
End Function

Function OnTest(funcData)

' Dopus.clearOutput
Dopus.output funcData.func.sourcetab.path
Dopus.output DOpus.FSUtil.DisplayName(funcData.func.sourcetab.path, "e")
Dopus.output DOpus.FSUtil.DisplayName(funcData.func.sourcetab.path, "r")

            funcData.func.command.ClearFiles()
            funcData.func.command.AddFile("temp.txt")
            funcData.func.command.AddFile("C:\Temp\temp\temp.txt")
            funcData.func.command.AddFile("lib://Temp/temp/temp.txt")

            funcData.func.command.RunCommand("Select FROMSCRIPT DESELECTNOMATCH MAKEVISIBLE")

End Function[/code]

The paths to files in libraries have an extra part, normally hidden from view, which identifies which of the library folders they are below. You need to feed that path in, or calculate it, in order to select a file in a library.

The paths look like this:

lib://Pictures/?7e6911a3/Subfolder/Etc/File.jpg

The number part will be different for different libraries and paths, but will be consistent, so you could just find that and use it.

Or you could use something like the below example, which takes the real full path to the file, then finds it in the list of files and gets the library library path from it, and then feeds that to the select command.

(If you uncomment the DOpus.Output line in the example, you'll see it outputs a path like the one above.)

VBScript:

[code]Function OnClick(ByRef clickData)
Dim cmd, setRealPaths, folderItem

Set cmd = clickData.func.command
cmd.deselect = false ' Prevent automatic deselection
cmd.ClearFiles

Set setRealPaths = DOpus.Create.StringSet
setRealPaths.insert "C:\Temp\temp\temp.txt"
' ...Insert any other paths you want to select here...

For Each folderItem in clickData.func.sourcetab.all
	If (setRealPaths.exists(folderItem.RealPath)) Then
		' DOpus.Output folderItem
		cmd.AddFile folderItem
	End If
Next

cmd.RunCommand "Select FROMSCRIPT DESELECTNOMATCH MAKEVISIBLE" 

End Function[/code]

JScript:

[code]function OnClick(clickData)
{
var cmd = clickData.func.command;
cmd.deselect = false; // Prevent automatic deselection
cmd.ClearFiles();

var setRealPaths = DOpus.Create.StringSetI();
setRealPaths.insert("C:\Temp\temp\temp.txt");
// ...Insert any other paths you want to select here...

for (var eSel = new Enumerator(clickData.func.sourcetab.all); !eSel.atEnd(); eSel.moveNext())
{
	if (setRealPaths.exists(eSel.item().RealPath))
	{
		// DOpus.Output(eSel.item());
		cmd.AddFile(eSel.item());
	}
}

cmd.RunCommand("Select FROMSCRIPT DESELECTNOMATCH MAKEVISIBLE");

}[/code]