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: Deselect All Selected Components
Function
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
version:20080817, v1.0
Author
D. R. G. Mitchell
Acknowledgements
Comments
Shows how to use Component commands including Root and Child components.
System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
Supported
Yes
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, adminnospam@dmscripting.com (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)

{

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

{

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

if(componentisvalid(selected))

{

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)

}

}