Create Line meassuring tool for parallel dimensioning?

Dear all,

I want to recreate the behaviour of an older software wich does not run on my win10 pc anymore.

Basically i want to create a line measuring tool that has bars at the end of each line like this |------------| and annotates the line with its lenght at an appropriate position in a) a font and color of my choice with a b) box in the background with a color and trasparency of my choice.

I tried to addaped a piece of code i found online:

 macro "Line Length Tool -C00bL1de0L1ee1" {
        getCursorLoc(x, y, z, flags);
        xstart = x; ystart = y;
        x2=x; y2=y;        
        while (true) {
            getCursorLoc(x, y, z, flags);
            if (flags&16==0) {
                dx=x2-xstart; dy=y2-ystart;
                if (selectionType==5) {
                   run("Measure");
                   lengthlabel = "" + getResult("Length", nResults-1);  
                   //print(lengthlabel);                                    
				   Roi.setName(lengthlabel);
				    // get top left coordinates of bounding box
 					getSelectionBounds(x, y, width, height);    
     			   Overlay.addSelection;
     			   Overlay.drawString(lengthlabel, x, y) ;
     			   //run("Label");

                   //run("Select None");
                }
                exit;
            }
            if (x!=x2 || y!=y2)
{
                makeLine(xstart, ystart, x, y);

                //Color_and_annotate_line(xstart, ystart, x, y);
            }
            x2=x; y2=y;
            wait(10);
        };

    }
 }

It roughly works… But if i draw to long lines the label is far away from the line. I actually would like it to be in the center of the line without intersecting the line. A more intelligent solution that detects nearby lines would be even better. Furthermore it is missing the bar ends |-------|.

Here is the output of the old software:

In a second step i want to change the dialoge while meassureing as follws:
As long as the mouse button is pressed, the bar ends with an angle of 90 deg to the actuall meassured line |—| should span the whole of the image until they hit the boarder. If possible the line itself should have a different color than the bars only during meassurement.

As i am a complete novice to this software i would really appreciate some help.

Dear all,
If anybody could point me into the right direction this would be really appreciated.

Thanks in advance

Dear Norrin,

I was in a similar situation like you a while ago. I need to measure a lot of distances perpendicular to certain features in an image. Therefore I also wanted a line tool with “caps” at both ends. This link brings you to the thread I opened back then which also references older threads on the topic.

If you want, I can send you the most recent version I am using. It should be easy to modify the length of the perpendicular lines. It does not do any annotations of length so far though.

I really with there was more learning material on programming macro tools.

All the best,

Nils

Dear Norrin,

I was in a similar situation like you a while ago. I need to measure a lot of distances perpendicular to certain features in an image. Therefore I also wanted a line tool with “caps” at both ends. This link brings you to the thread I opened back then which also references older threads on the topic.

If you want, I can send you the most recent version I am using. It should be easy to modify the length of the perpendicular lines. It does not do any annotations of length so far though.

really with there was more learning material on programming macro tools.

All the best,

Nils

Dear Nils,
I would be very much interested your macro! I agree with you that the current learning material is lacking if you are a beginner. A more experienced user is probably able to get away with just the documentiation but i am mostly struggeling with finding the information i need.
Once i get a good pointer into the right direction it gets much easier.

Thank you in advance

Hey Norrin, sorry for the late reply. Here’s the macro I use at the moment:

macro "Perpendicular Line Tool - C000-B11-L0440-L3399-L8cc8" {
	var leftButton = 16;
	var isDown = false;
	
	while (true) {
		getCursorLoc(trash1, trash2, trash3, flags);
		if (flags&leftButton!=0) {
			Overlay.clear;
			run("Select None");
			getCursorLoc(xStart, yStart, zStart, flags);
			while (flags&leftButton!=0) {
				getCursorLoc(x, y, z, flags);
		    	drawPerpendicularLines(xStart, yStart, x, y);
			}
		}
	}
}

function drawPerpendicularLines(x1, y1, x2, y2) {
	Overlay.clear;
    makeLine(x1, y1, x2, y2);

    // get slope of line
    dx = (x2-x1);
    dy = (y2-y1);

    // calculate perp line endpoints
    xa = (x1 - dy/4); ya = (y1 + dx/4);
    xb = (x1 + dy/4); yb = (y1 - dx/4);

    xc = (x2 + dy/4); yc = (y2 - dx/4);
   	xd = (x2 - dy/4); yd = (y2 + dx/4);

    Overlay.drawLine(xa, ya, xb, yb);
    Overlay.drawLine(xc, yc, xd, yd);	    
    Overlay.show;
    wait(30);
    }

It’s still a bit buggy but very useable. If you adjust the coordinates of the perpendicular lines and add some function to annotate you shoul dbe good to go.