GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Switching to a default file in the viewer panel

Hi there,
I am trying to create a script that displays a file "index.html" in the internal viewer panel if such a file exists inside the current folder but the function seems to not find the file. Additionally I don't know how to send a file to the viewer panel. This is how far I have come:

Function OnAfterFolderChange(afterFolderChangeData)
If afterFolderChangeData.result Then
If Left(afterFolderChangeData.tab.files, 14) = "index.html" Then
DOpus.Output "found it!"
End If

Any help would be greatly appreciated!

This should get you started.

function OnInit(initData) {
    initData.name = 'testindex';
    initData.version = '1.0';
    initData.copyright = '';
    initData.desc = '';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnAfterFolderChange(afterFolderChangeData) {
    var targetFile = afterFolderChangeData.tab.path + '\\index.html';
    if (!DOpus.FSUtil.Exists(targetFile)) return;
    var cmd = DOpus.Create.Command;
    cmd.RunCommand('Select NONE');
    cmd.RunCommand('Select index.html');
    cmd.RunCommand('Set VIEWPANE=on');
}

testindex.js.txt (565 Bytes)

Thank you for the script, it really helps a lot!
Unfortunately the Viewpane does not change its content when the file is selected by the script for some reason.
Edit: I tried

cmd.RunCommand('show VIEWPANE=index.html');

but it opens the external viewer and not the viewer "panel" inside Dopus.

Exchange the second to last line with

cmd.RunCommand('Select index.html MAKEVISIBLE');

Seorde, please link your account, and we might be able to add something which makes doing this easier and more flexible (e.g. files outside the current folder) in the next update.

lxp thank you so much for your help!
It works perfectly now, I just had to replace MAKEVISIBLE with SETFOCUS since the description of MAKEVISIBLE reads :

Similar to the SETFOCUS argument except the viewer pane will not update to show the new selection.

@Leo I don't have a license yet. I want to pitch Dopus as the perfect solution for our company's needs and this was the missing part.

We added these in Directory Opus 12.16.1 (Beta) to make this kind of thing easier:

  • Added command to tell the Lister viewer pane to open a specific file. e.g. Show VIEWPANECMD="open,C:\My Image.png ".

  • Added Show VIEWPANECMD=clear to unload any current file and clear the viewer pane.

Thanks Leo this works perfectly when I create a button and make a direct link to a file!
However I'm not able to make it work in the script.

function OnAfterFolderChange(afterFolderChangeData) {
    var targetFile = afterFolderChangeData.tab.path + '\\index.html';
    if (!DOpus.FSUtil.Exists(targetFile)) return;
    var cmd = DOpus.Create.Command;
cmd.RunCommand('Show VIEWPANECMD="open,\\index.html"');

same with

cmd.RunCommand('Show VIEWPANECMD="open,targetFile"');

I also tried with an absolute path:

cmd.RunCommand('Show VIEWPANECMD="open,c:\text.txt"');


and while I'm at it:
Do you know why this works perfectly until the folder depth reaches 5?

function OnAfterFolderChange(afterFolderChangeData) {
    var targetFile = afterFolderChangeData.tab.path + '\\index.html';
    if (!DOpus.FSUtil.Exists(targetFile)) return;
    var cmd = DOpus.Create.Command;
cmd.RunCommand('Select index.html SETFOCUS');

The folder path is not to long:

U:\Library\Drive\LTO1\HH\SAS

If the file is in folder "HH" the script works.
If it is in SAS it does not.

Have you debugged it at all to find out if the event is being run in all the situations you expect, which file it is looking for, if it is finding the file, and print the commands it is running?

That's the first thing I would do. Use DOpus.Output to print things to the script log.

I'm sorry Leo, this is way over my head. I can basically only copy lxp's script from above and hope for the best.
I've seen the DOpus.Output function being mentioned in the introduction of the scripting documentation, but I don't know where to put it.
I don't want to waste your time, I was just hoping you would spot an obvious syntax error I made or something.

The syntax looks OK apart from the missing } at the end, which I assume is just a copy & paste error in the posts not the scripts.

If you open the script log (Tools > Script Log), do you get any error messages?

Are you expecting this to run when you change folders by manually navigating in a window which is already open, or are you trying to make it work when doing something else like opening a whole lister layout or folder tab group?

Yes I hope the script to display a certain file when ever I enter a folder.

function OnAfterFolderChange(afterFolderChangeData)
{
    var targetFile = afterFolderChangeData.tab.path + '\\index.html';
    if (!DOpus.FSUtil.Exists(targetFile)) return;
    var cmd = DOpus.Create.Command;
cmd.RunCommand('Show VIEWPANECMD="open,\\index.html"');
}

Tools > Script Log

is giving no output.

However, the title of the Viewer Pane changes to "Index.html (Shell Icon)" as I just realized while taking a screenshot:

So is the problem with the script, or do you get the same icon if you select the index.html file manually to display it in the viewer?

You may need to debug the script. We can only offer limited time and support for this unless you link your account (it is 8 years old now, after all).

Yes, when I select the file manually it's displayed just fine in the Viewer Pane.
I'm sorry Leo as I said I don't want to waste your time. This is my private account and I have a meeting tomorrow morning to pitch this in my company. If all goes well I'll link a bunch of accounts.
I'm going with the other script for tomorrow (the one that only works with 4 folder depth), but it's enough to demonstrate how amazing Dopus is :slight_smile:

1 Like