How to test if an instance of the standalone viewer still exists

I want a dialog that's attached to a viewer window to be closed if the viewer window was closed. I tried several things to test if the viewer still exists but couldn't find a proper way. My current workaround is not satisfying because it also closes the dialog if it's own viewer window still exists but another viewer got the focus:

If IsObject(DOpus.viewers.lastactive) Then If DOpus.viewers.lastactive = data.Func.viewer Then data.Func.viewer.Command("goto," & index-1) Else dlg.EndDlg End If Else dlg.EndDlg End If

You can use OnViewerEvent to be notified when the viewer window is closed.

I haven't worked with the dialog changes in v12... and not much in v11 either for that matter.

But at a quick glance you can set Dialog specific variables. So, not sure how you're launching your dialog or if there is some built-in association between the dialog object and the viewer window that can be used, but I quickly tested the following:

Install this test button: you will click it to get a prompt to set a global variable... which for this test will be the viewer "ID" from the ViewerEventData.viewer value logged by the script below...

<?xml version="1.0"?> <button backcol="none" display="both" label_pos="right" textcol="none"> <label>viewerDlg</label> <icon1>#foldertabgrouplist</icon1> <function type="normal"> <instruction>@toggle:if $glob:viewerDlg</instruction> <instruction /> <instruction>@ifset:$glob:viewerDlg</instruction> <instruction>@set glob:viewerDlg</instruction> <instruction /> <instruction>@ifset:else</instruction> <instruction>@set glob:viewerDlg={Rs|Specify viewerDlg value...}</instruction> </function> </button>

Install this test OnViewerEvent event handler script: ViewerEvent_Handler.osp (1.59 KB)
Open the Opus script output window, then launch the image viewer. Switch from the viewer to the output window to see a log message outputting the viewer ID. Copy it and set the variable from the test button to this value. See what happens in the script output log when you close the viewer.

Point being, if there isn't some other way - this script shows that you can test for the "destroy" ViewerEvent.event to detect that a viewer has been closed, as well as check for whether or not the ID of the viewer matches the ID which you can store in a variable (which in your case I would assume should be a Dialog scoped variable for your dialog object instead of the Global scoped variable my test toolbar button works with).

Does that help?

Thanks for your answers. I got it working now by adding the OnViewerEvent function to my script. It's also useful to detect if the currently shown image has changed so the dialog can follow that change.