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: Single Button Dialog
An example script which shows the basic elements which go to make up a dialog. In this case the dialog has a single button which tells you when it has been pressed.
version:20091003, v1.0
D. R. G. Mitchell
Just run the script. It does not need any images displayed. Note dialogs require a lot of extra code, so the effort for a simple script is significant. However, if your script needs lots of data inputs or prompts, then it is worth wrapping it up in a dialog.
System Requirements
Dialog scripts are only generally compatible with PC-based versions of DigitalMicrograph - GMS 1.6 and later.
Known Issues
Included Files
Single script file.
Source Code



// the class createbuttondialog is of the type user interface frame, and responds to interaction

// with the dialog

// version20091003, v1.0

// D. R. G. Mitchell, Oct 2009

// (remove the nospam to make this email address work)


class CreateButtonDialog : uiframe


void buttonresponse(object self)


//this is the response when the button is pressed


okdialog("You pressed my button!")




// this function creates a button taggroup which returns the taggroup 'box' which is added to

// the dialog in the createdialog function.

taggroup MakeButton()


// Creates a box in the dialog which surrounds the button

taggroup box_items

taggroup box=dlgcreatebox(" Parameters ", box_items)




// Creates the button

TagGroup ExampleButton = DLGCreatePushButton("Push Me", "buttonresponse")



return box


// This function creates the dialog, drawing togther the parts (buttons etc) which make it up

// and alloc 'ing' the dialog with the response, so that one responds to the other. It also


// displays the dialog


void CreateDialogExample()


// Configure the positioning in the top right of the application window

TagGroup position;

position = DLGBuildPositionFromApplication()

position.TagGroupSetTagAsTagGroup( "Width", DLGBuildAutoSize() )

position.TagGroupSetTagAsTagGroup( "Height", DLGBuildAutoSize() )

position.TagGroupSetTagAsTagGroup( "X", DLGBuildRelativePosition( "Inside", 1 ) )

position.TagGroupSetTagAsTagGroup( "Y", DLGBuildRelativePosition( "Inside", 1 ) )


TagGroup dialog_items;

TagGroup dialog = DLGCreateDialog("Example Dialog", dialog_items).dlgposition(position);

dialog_items.dlgaddelement( MakeButton() );

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

dialog_frame.display("Dialog Template");


// calls the above function which puts it all together