Apply Custom Layout to Image in DigitalMicrograph

2019-07-31 19:09发布

问题:

I have an image in DigitalMicrograph GMS3 (v 3.21.1374.0) which i have applied a custom databar to (trying to learn how to do this via script here: add / apply custom databar to image in DigitalMicrograph GMS3)

I have a custom layout that I can add manually by doing the following:

  1. Right click on the image
  2. Hover on layout (in context menu)
  3. Left click "Apply Layout..."
  4. Select the custom layout in dialog that pops up (the one I want is called "CheckLayout")
  5. Click OK

How do I do this with a script? I know how to get the image and the imagedisplay objects but that is as far as I get.

//main - get front image and apply custom layout
image Img := GetFrontImage()
imageDisplay imgDisplay = Img.ImageGetImageDisplay(0)

//apply custom layout to image here

Any ideas?

回答1:

The layout is a property of an ImageDocument not an image. The correct way of doing this (provided there exists a layout of name 'MyLayout') is:

ImageDocument doc = GetFrontImageDocument()
doc.ImageDocumentApplyLayout("MyLayout")

You might additionally be interested in the commands:

void ImageDocumentApplyLayout( ImageDocument, String )
void ImageDocumentRemoveDatabar( ImageDocument )
Number ImageDocumentGetLayoutCount( ImageDocument )
String ImageDocumentGetLayoutName( ImageDocument, Number )

as used in

ImageDocument doc = GetFrontImageDocument()
number nLO = doc.ImageDocumentGetLayoutCount()
Result( "\n Layouts in document:" +  nLO )
For( number i=0; i<nLO; i++)
{
    string layoutName = doc.ImageDocumentGetLayoutName(i)
    Result( "\n\t"+i+":"+layoutName)
}


标签: dm-script