Posted by
Jeremias Brand on
Nov 26, 2014; 8:43pm
URL: http://imagej.273.s1.nabble.com/Macro-for-polyline-tool-with-constant-length-of-segments-tp5010647.html
Hi,
I am working on a macro that allows me to draw a segmented line and then
measures all the angles between the segments.
Measuring the angles works fine, but I also need to have segments of
equal length to assure repeatability. I am working of this macro for the
polygon:
http://imagej.nih.gov/ij/macros/tools/PolygonTool.txt
<mailto:
[hidden email]>
How can I fix the length of the segments? I have figured out how to
terminate the first segment at a specific length, but I do not know how
to continue the next segment form that point onward.
Here is my code so far:
macro "Polygon Tool -C00bB12P51f1f2b6b7eafb1b151451" {
requires("1.45n");
toolName = IJ.getToolName();
size = 6/getZoom;
x = newArray(2000);
y = newArray(2000);
getCursorLoc(x2, y2, z2, flags);
x[0] = x2; y[0] = y2;
x[1] = x2; y[1] = y2;
n = 2;
setOption("DisablePopupMenu", true);
Overlay.drawRect(x[0]-size, y[0]-size, size*2, size*2);
Overlay.show;
while (flags&20!=0) // left and right click
getCursorLoc(x2, y2, z2, flags);
while (true) {
getCursorLoc(x2, y2, z2, flags);
if (flags&20!=0) {
modKey = flags&14!=0; //right-click, control or alt
while (flags&16!=0)
getCursorLoc(x2, y2, z2, flags);
if (modKey) {
makeSelection("polyline", x, y, n);
Overlay.removeSelection(Overlay.size-1);
setOption("DisablePopupMenu", false);
exit;
}
n++;
}
run("Measure");
length = getResult('Length', nResults-1);
if (length>=200) {
exit;
}
x[n-1] = x2;
y[n-1] = y2;
makeSelection("freeline", x, y, n);
wait(10);
}
}
Please forgive me if this is a very amateur question. I just started
writing macros. Any help would really be appreciated!
Cheers,
Jeremias
--
*****************************
Jeremias Brand
University of Basel
Zoological Institute, Evolutionary Biology
Vesalgasse 1
4051 Basel
Switzerland
http://evolution.unibas.ch/scharer--
*****************************
Jeremias Brand
University of Basel
Zoological Institute, Evolutionary Biology
Vesalgasse 1
4051 Basel
Switzerland
http://evolution.unibas.ch/scharer--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html