// Scale Bar Maker // Draws a scale bar of the specified length, position and color. // Requires an image with a calibrated scale (this can be done // using the "Set Scale" command). // // See Also: Analyze>Tools>Scale Bar command if (nImages == 0) { exit("There are no images open."); } pixelH = getHeight(); pixelW = getWidth(); getPixelSize(scale, pixelSize, trash); getMinAndMax(min, max); Dialog.create("Scale Bar Parameters"); Dialog.addNumber("Length in current units:", 1); choice1 = newArray("Black", "White"); Dialog.addChoice("Color:", choice1); choice2 = newArray("Top Left", "Top Right", "Bottom Left", "Bottom Right"); Dialog.addChoice("Position:", choice2); Dialog.show(); inLength = Dialog.getNumber(); inColor = Dialog.getChoice(); inPos = Dialog.getChoice(); sbLength = inLength / pixelSize; sbHeight = pixelH / 100; if (inColor == "Black") { sbColor = 0; } else { sbColor = max; } if (inPos == "Top Left") { sbXcoord = pixelW / 30; sbYcoord = pixelH / 30; } else if (inPos == "Top Right") { sbXcoord = pixelW - sbLength - (pixelW / 30); sbYcoord = pixelH / 30; } else if (inPos == "Bottom Left") { sbXcoord = pixelW / 30; sbYcoord = pixelH - sbHeight - (pixelH / 30); } else if (inPos == "Bottom Right") { sbXcoord = pixelW - sbLength - (pixelW / 30); sbYcoord = pixelH - sbHeight - (pixelH / 30); } setColor(sbColor); fillRect(sbXcoord, sbYcoord, sbLength, sbHeight); textSize = pixelH / 50; textYcoord = sbYcoord - (pixelH / 200); label = toString(inLength) + " " + scale; setFont("SansSerif", textSize); drawString(label, sbXcoord, textYcoord);