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: Taggroup Creation-Saving-Adding to Global Info

Shows how to add bits of information to a taggroup. This taggroup can be added directly to the the Global Info, or saved as a settings file.

version:20080303, v1.0
D. R. G. Mitchell
Saving settings and preferences to the Global Info is very useful. The Global Info tags are non-volatile and so will be retained after shutdown. Taggroups are useful for collecting together such data. These can be added to the Global Info or saved as a standalone settings file.
System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
Follow the instructions in the code. This code adds a taggroup called 'Test of Taggroup Addition' to the Global Info. The final thing the script does is to display the Global Info in a taggroup browser window. Ensure you select the 'Test of Taggroup Addition' taggroup by clicking on it once and then select delete. If you do not delete it, the next time the script is run an error will occur, because taggroups can not be overwritten. They must be first deleted if they are to be replaced.
Included Files
Main script file.
Source Code

// example code showing how to add bits of information to a taggroup.

// this taggroup can be added directly to the the Global Info, or directly

// saved as a settings file


// version:20080303


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

// v1.0, March 2008


// Create a new taggroup which will hold all the information


taggroup newtags=newtaggroup()


// Get some data to add to the top level of the taggroup


string packagename="My package"

string defaultpath="C:/whatever"

string version="20080203"

number priority=3

number index


// Add a labelled tag and then its value to the respective variable


index=newtags.taggroupcreatenewlabeledtag("Default Path")



index=newtags.taggroupcreatenewlabeledtag("Package Name")



index =newtags.taggroupcreatenewlabeledtag("Package Priority")



index =newtags.taggroupcreatenewlabeledtag("Package Version")



// The above adds top level entries to the taggroup which appear as




Default Path:C:/whatever

Package Name:My Package

Package Priority:3

Package Version:20080203




// Next a new taggroup is created on each pass of the loop. This

// Adds taggroups called Item 1, Item 2 etc to menu item Items.


// Each of these sub groups contains the fields




Command Name:Hello1

Main Menu Name:Hello1

Script Name:hello1

Sub Menu Name:hello1






// The value 1 gets incremented on each pass. Obviously in real code, variables from,

// for example dialog fields, would be sourced and added to these taggroups.


number nomenuentries=5

number i


taggroup itemtag=newtaggroup()



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


taggroup isubgroup=newtaggroup()

index = isubgroup.taggroupcreatenewlabeledtag("Command Name")

isubgroup.taggroupsetindexedtagasstring(index, "hello"+i)


index = isubgroup.taggroupcreatenewlabeledtag("Main Menu Name")

isubgroup.taggroupsetindexedtagasstring(index, "hello"+i)


index = isubgroup.taggroupcreatenewlabeledtag("Script Name")

isubgroup.taggroupsetindexedtagasstring(index, "hello"+i)


index = isubgroup.taggroupcreatenewlabeledtag("Sub Menu Name")

isubgroup.taggroupsetindexedtagasstring(index, "hello"+i)


index = isubgroup.taggroupcreatenewlabeledtag("Type")

isubgroup.taggroupsetindexedtagaslong(index, i)


index = isubgroup.taggroupcreatenewlabeledtag("Version")

isubgroup.taggroupsetindexedtagaslong(index, i)


itemtag.taggroupaddlabeledtaggroup("Item"+i, isubgroup)





// This displays the contents of the final taggroup.

okdialog("About to display the newly created taggroup.")





// Uncomment the next sections - delete the /* and the */ // to see how the newly created tag group

// gets added to the Global Info - remember to delete the taggroup 'Test of Taggroup Addition' when you are done

// and also how it gets saved as a settings file


// Add this to the persistent tag group (Global Info)


// Get the persistent taggroup


taggroup ptags=getpersistenttaggroup()


// Before adding the taggroup, must check to see if it already exists

// if yes it will generate an error, existing tags can not be overwritten

// they must be delected first


string tagname="Test of Taggroup Addition"




// Yes the tag does exist - so delete it

okdialog("Taggroup ' "+tagname+" ' already exists - deleting it")

taggroupdeletetagwithlabel(ptags, tagname)



taggroupaddlabeledtaggroup(ptags, tagname, newtags)

okdialog("The tag group ' '"+tagname+" ' has been added to the Global Info")





// Save this tagggroup as a setting file by


string settingsname

packagename="I am a label"

if(!saveasdialog("Save the settings", settingsname, settingsname)) exit(0)


taggroupsavetofilewithlabel(newtags, settingsname, packagename)