Macro - beginner - how to find/know the name of specific command

Dear forum,

I am trying to write a macro - with little success.
I am not even quite sure how to go about this question.

What I wish to do:
I have X numbers of images, I would like to measure the length of some structures on these images, and I would like to measure multiple structures pr. image.
I imagine to do this with the tool “Straight Line” and record it with the “Measure” function (so if I did it manually I would select the tool by clicking on the icon, draw the line and press “Ctrl +M”.

As I have many many images I would like a macro to:

  1. Open the image
  2. Make a dialog “measure more” y/n , y = after first length record, same image appears, n = next picture open.
  3. All records are written to a log file with image-name identifier.

I have a macro (not written by me), which I right now try to modify into this - but I am not a programmer and I just get stuck ALL the time.
Right now my problem is that I have no idea have to open/run/do the “draw line” function, I have tried run(“Straight Line”), open(“Straight Line”), Straight Line(), Lxyxy() and millions of other combination - I have basically no idea how to do this…
I have tried to look up tutorials and been searching the web for the name of this function (drawing/measuring the length of a line).

If anyone of you know how to write this or point me to some specific tutorial etc. I would much appreciate it, as I feel stuck right now.

If it is of any use - here is what I have, it "works correctly up untill the “run(“Draw Line”)”:

    macro "Batch Preparation" {
    dir = getDirectory("Choose a Directory ");
    list = getFileList(dir);  // returns an array with the file names
    FileNo = 0;  // Numbers of files for images with more than one spore
    for (i=0; i<list.length; i++) {
         pathname = dir+list[i];
         showProgress(i, list.length);
         if (endsWith(pathname,"tif")) open(pathname);
    	// settings selection area (size of area)
            RelSize = 1; // write rel. size 0-1 (ex. 5 mikron = 1- 1/6 = 0.83)
            W = getWidth()*RelSize;
            H = getHeight()*RelSize;
     	if (nImages>=1) {
            //CHOOSE SELECTION
            // - enter magnification for selection (6 mikron circle)
            // 0 = abort (wrong file , 5.0)
            Dialog.create("Key in Magnification (0=omit / 5.0)");
            Dialog.addNumber("Magnification: ",0);
    	Dialog.addString("Analyse another ornament y/n:","");
            Mag = Dialog.getNumber();
    	Other = Dialog.getString();
    	if (Other!="y") FileNo = 0; else FileNo=FileNo+1;   // count for >1 spore
            if (Mag==5)  run("Draw Line") ;
    print("Height of ornament");
    waitForUser("measure more");


Hi @Mathilde_Borg_Dahl,

and welcome to the forum.
regarding the macro language there are two things I would recommend to a beginner.

  1. let the IJ macro recorder run while you are clicking your processing sequence together. This shows you already the syntax of most menu commands (>Plugins >Macros >Record…)

  2. The resource for all commands which are not recordable is

On the macro functions page there are also many links to examples for specific purposes.
No question, that takes a little bit of time in the beginning to get in touch with it, but its worth to invest it. Since you have already a macro to start with it might be a little easier for the beginning.

The make line command would be e.g.:
makeLine(x1, y1, x2, y2);
makeLine(x1, y1, x2, y2, lineWidth);

Hope this gives you a good starting point regarding the macros.

1 Like

Thank you very much!
Now several hours later I have trimmed my script a lot! - and now it works! :slight_smile:

1 Like