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

 

Example: Selecting a Camera from Script
Function
An example script which shows how to select a camera using the ObjectList object returned from the Camera Manager.
Version
20190603, v1.0
Author
D. R. G. Mitchell
Acknowledgements

Thanks to Bernhard Schaffer for explaining, the otherwise undocumented, object lists in his excellent free ebook 'DM Scripting Handbook - How to Script'.

Comments

If you have more than one camera attached to your microscope, there are occasions where you might want to select one using script. The CM_GetCurrentCamera() command will select which ever camera is currently selected in the DigitalMicrograph interface. However, to select an alternative camera you have to source the corresponding camera object list from the CameraManager. As the name suggests, this is a list of objects. However, using these very useful object lists is not documented in the online help (Bernhard's book to the rescue - thanks). This example script will source the list of camera objects and display a prompt to select one. In this example script this is done by entering a number. In practice, using a popup menu in a dialog would be a much more elegant solution. If you check the Camera menu in DigitalMicrograph after running this script, you can confirm that the selected camera has been changed to your selection.

System Requirements
This will only work on a system which has multiple Gatan cameras attached to it. It should be compatible with all recent versions of DigitalMicrograph. It has been tested on GMS 2.32.
Known Issues
If you have only one camera attached, you will have only one option to select.
Supported
Yes
Included Files
Main script file.
Source Code
See attached source code.