Scripting Resources for DigitalMicrograph™


Dave Mitchell's DigitalMicrograph™ Scripting Website

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


Example: Deselect All Selected Components
An example script which shows how to use the Component commands to deselect all selected components such as text annotations, ROIs etc, which are currently selected.
version:20080817, v1.0
D. R. G. Mitchell
Shows how to use Component commands including Root and Child components.
System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
Included Files
Main script file.
Source Code

// An example script which shows how to deselect a component

// which is selected within an image. A component can be a region

// of interest, text annotation etc.

// D. R. G. Mitchell, (remove the nospam from this email address to make this work

// v1.0, August 2008

// version:20080817

// Function to return the selected annotation

component selectedAnnotation(imagedocument imgdoc, component parent)


number children = parent.ComponentCountChildren()

component selected,dummy

number i

if (parent.ComponentIsSelected()) return parent

else if (children>0)




selected = imgdoc.selectedAnnotation(parent.ComponentGetChild(i))

if (ComponentIsValid(selected)) return selected



return dummy




// Get the frontmost image


image front:=getfrontimage()

imagedocument imgdoc=getfrontimagedocument()


// Get the root component and extract the selected component

component root=imgdoc.imagedocumentgetrootcomponent()

component selected=imgdoc.selectedannotation(root)


// Deselect all selected components



component parent=componentgetparentcomponent(selected)

number count=componentcountchildren(parent)


number i


for(i=0; i<count; i++)


component child=parent.componentgetchild(i)

if(componentisselected(child)) componentsetselected(child,0)