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: Set and Reset Pulldown Menus
An example dialog script which shows how to create a dialog where a user can make a selection from a pulldown menu, and then reset that menu by pressing a Reset button.
version:20060221, v1.0
D. R. G. Mitchell
Resetting menus is often necessary either via a reset/cancel button or via the action of another dialog element, such a second menu, button etc.
System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
Included Files
Main script file.
Source Code

// simple dialog script to demonstrate the resetting of pulldown menus

// version:20060221, v1.0


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

// Feb 2006


// variables


number returnno

string returnname, returnstring

taggroup intfield1


class DialogLibraryTestClass : uiframe


number change_count, action_count;


void tracknamechange( object self, TagGroup tg)



dlggetnthlabel(tg, returnno, returnname)




void cancelpane( object self) // when the 'Cancel' button is pressed


documentwindow windoc=getdocumentwindow(0)




// This part of the script does the resetting, when the reset button is pressed


void reset(object self) // when the 'Reset' button is pressed



// The command below looks up the taggroup for the pulldown menu. When the pulldown was created

// (see the MakePulldowns() I set the identifier for the pulldown menu taggroup (to a string called 'MyPullDown')before it was grouped

// with other things, like labels. This keeps the structure of the tag group simple. It also avoids needing

// to use a global taggroup variable for the pulldown. By way of contrast, for the integer field (intfield1) I did not set an identifier

// and so need to use a global variable to access it in subsequent functions. Global variables are best avoided wherever possible,

// so use identifiers and look them up within functions


taggroup Getthepulldown=self.lookupelement("MyPullDown")



// The command below is included only for demonstration of how to actually determine the internal structure of the

// the tag group you are trying to control or reset. If you comment out the taggroupopenbrowserwindow command,

// the script will run as you might expect.




// The string ("Value") which appears in the TagGroupSetTagAsNumber command below is derived by using the

taggroupopenbrowserwindow() command.

// The structure of the tag group can vary depending on how you have grouped elements. In some instances the relevant tags

// may be strings and these can be set with the corresponding taggroupsettagasstring command

// The command below sets the pulldown menu to which ever value you choose - in this case back to the first choice item


TagGroupSetTagAsNumber( GetthePulldown, "Value", 1 )


// Other reset commands can be used to set other dialog elements, such as an integer field in this case,

// back to an appropriate initial value - 1 in this case.






TagGroup MakeFields() // makes the integer field


taggroup label1=dlgcreatelabel("Pulldown Value").dlganchor("Center")

intfield1 = DLGCreateIntegerField(0,10).DLGAnchor("Center");


taggroup group1=dlggroupitems(label1,intfield1)

return group1




TagGroup Makepulldowns() // creates the pulldown menu


TagGroup pulldown_items;

TagGroup pulldown = DLGCreatePopup(pulldown_items, 1, "tracknamechange")


// Edit these lines to change your user list


pulldown_items.DLGAddPopupItemEntry("Default Choice");

pulldown_items.DLGAddPopupItemEntry("Choice 2");

pulldown_items.DLGAddPopupItemEntry("Choice 3");

pulldown_items.DLGAddPopupItemEntry("Choice 4");

pulldown_items.DLGAddPopupItemEntry("Choice 5");

pulldown_items.DLGAddPopupItemEntry("Choice 6");

pulldown_items.DLGAddPopupItemEntry("Choice 7");



// The command below labels the taggroup for the pulldown menu with a string - 'MyPullDown'. This is used in the Reset function

// to source the taggroup, without having to use a global variable for the tag group




taggroup label2=dlgcreatelabel("Choose Here").dlganchor("Centre")

taggroup pulldowngroup=dlggroupitems(label2, pulldown)


return pulldowngroup



// This creates the reset and cancel buttons in the dialog


TagGroup MakeButtons()


taggroup pushbuttons

TagGroup CalculateButton = DLGCreatePushButton("Reset", "Reset").DLGSide("Bottom");


TagGroup CancelButton = DLGCreatePushButton(" Cancel ", "cancelpane").DLGSide("Bottom");


pushbuttons=dlggroupitems(calculatebutton, cancelbutton)



return pushbuttons




// function to create the dialog


void createdialog()


TagGroup dialog_items;

TagGroup dialog = DLGCreateDialog("Enter Specimen Number and User Name", dialog_items);

dialog_items.DLGAddElement(makepulldowns() );

dialog_items.DLGAddElement( MakeFields() );

dialog_items.dlgaddelement(MakeButtons() );

dialog.DLGTableLayout(2,2, 0);


object dialog_frame = alloc(DialogLibraryTestClass).init(dialog)

dialog_frame.display("Set and Reset Pulldowns")




// Main Program