Scripting Resources for DigitalMicrograph™

banner

Dave Mitchell's DigitalMicrograph™ Scripting Website

Home | Scripts | Examples | Functions | Recent Updates | Tutorials | Resources | Publications | Consulting | Projects | Contact & Bio |PyJEM| Search

 

Functon: Find Image by Title
Function
Finds an image using its title.
Version

version:20211025, v1.0

Author
D. R. G. Mitchell
Acknowledgements
-
Comments

GMS 3 introduced the concept of Workspaces. These are essentially desktops within GMS in which specific sets of data can be displayed or worked upon. The problem with Workspaces is that in order to make them work, the ImageDocument commands had to be modified to make them Workspace-aware. If you are working on a GMS 3 installation, you can find these modified commands, along with other new commands for Workspaces under Help/Search/Scripting/Workspaces.

Personally, I do not much care for Workspaces and I have deliberately avoided using any of the Workspace commands, because of backwards compatibility issues with GMS 2. Scripts using such commands will not run on GMS 2 - which is where most of my work and probably the majority of GMS users currently are.

Scripts using ImageDocument . . () commands which were written for GMS 2, will still run under GMS 3 - but the behaviour may not be what is expected. The crux of this issue is that in GMS 2 ImageDocument . . . () commands could be used to globally sort through all imagedocuments (these are the parent containers for an image). I use this functionality all the time to close/show/hide an image. Under GMS 3 this changes and the original ImageDocument . . . () commands, which are not Workspace-aware, will act only on the currently selected Workspace. Of course, under GMS 3 you can use Workspace-aware ImageDocument . . () commands, some of which are global in scope, but such commands will not be GMS 2 compatible.

The function presented here is a cludge to get around this issue. If somebody has a more elegant solution, please let me know. Instead of using the ImageDocument . . . () commands, it uses DocumentWindow . . . () commands. These too have some new Workspace-aware commands added under GMS 3 - but the functionality used here avoids the new commands and so will be backwardly compatible with GMS 2.

This function searches for a documentwindow on the basis of the title - supplied by the user. So if you are searching for an image you will need to know its name. A wrinkle here is that the documentwindow title includes the sequence lettering (A: , BB: , etc) which prepends each image name in the window title - the lettering changing according to the sequence of images in the stack. This function looks for the first space in the filename and then deletes everything from that space leftwards to leave only the name, which is then compared with the user-supplied name. If a match is found, then four different things can be done with this function. The window can be shown, closed, or hidden and the image variable sourced - the behaviour depends on the numerical value of the the imageaction variable passed into the function. If the target window is displayed in a Workspace which is not currently selected, then hiding or closing that window will not change the selected Workspace. If that window is shown, then the Workspace hosting it will be selected. If the image variable is sourced, it is returned by reference and can be used for image processing etc. Simply sourcing the image variable will not change the selected workspace.

System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
-
Supported
Yes
Included Files
Main script file.
Source Code

See attached script file.