Segmented Line Tool

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Segmented Line Tool

lechristophe
Dear all,

I'm trying to replicate the Segmented Line Tool with a Macro Tool using
getcursorLoc().

(So the Tool should do the following : once pressed, draw a segmented
line from the first point clicked, with a new segment each time a
location is clicked, exactly the behavior of the Segmented Line tool).

The problems are :

- I can't find a condition for a "while" loop that draws a line from the
last clicked position to the current location until the left button is
pressed.

- How to detect if the left button pressing inside this "while" loop, to
end the segment.

- After the button is pressed, how to go on with a new segment.

Why am I trying to do that ? Because I want then to replace the straight
segment by whatever I want between the two points (for exemple, a
macro-defined LIveWire tracing between the two points, or a straight
line if "shift" is pressed...)


Would anybody be kind enough to help me on that, or even better give me
the piece of macro code that replicates the Segmented Line tool, so that
I just have to replace the makeLine(x1,y1,x2,y2) by whatever I want ?



Thank you in advance,
Reply | Threaded
Open this post in threaded view
|

Re: Segmented Line Tool

lechristophe
Just a little add-on ty my question :

How difficult would it be to have the macro replicate the Polygon Tool
macro ? I assume only the end of the macro would be different,
generating a closing line. But how to detect "double click" ?

Christophe



Christophe Leterrier wrote:

> Dear all,
>
> I'm trying to replicate the Segmented Line Tool with a Macro Tool using
> getcursorLoc().
>
> (So the Tool should do the following : once pressed, draw a segmented
> line from the first point clicked, with a new segment each time a
> location is clicked, exactly the behavior of the Segmented Line tool).
>
> The problems are :
>
> - I can't find a condition for a "while" loop that draws a line from the
> last clicked position to the current location until the left button is
> pressed.
>
> - How to detect if the left button pressing inside this "while" loop, to
> end the segment.
>
> - After the button is pressed, how to go on with a new segment.
>
> Why am I trying to do that ? Because I want then to replace the straight
> segment by whatever I want between the two points (for exemple, a
> macro-defined LIveWire tracing between the two points, or a straight
> line if "shift" is pressed...)
>
>
> Would anybody be kind enough to help me on that, or even better give me
> the piece of macro code that replicates the Segmented Line tool, so that
> I just have to replace the makeLine(x1,y1,x2,y2) by whatever I want ?
>
>
>
> Thank you in advance,
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Segmented Line Tool

Gabriel Landini
In reply to this post by lechristophe
On Thursday 11 January 2007 16:25, Christophe Leterrier wrote:
> I'm trying to replicate the Segmented Line Tool with a Macro Tool using
> getcursorLoc().

Not sure if it will help, but here is my routine to handle points in a macro.
I updated to the right click does not bring the popup menu.

Left click, selects
Right click aborts.

Connecting the collected points to create a polyline or polygon should be
easy.

Mind the line breaks introduced by the mailer.
Cheers,

Gabriel

//--------------8<----------------------
//  GetPointsDemo.txt/
//  by G. Landini, derived from GetCursorLocDemo.txt macro
//  12/1/2007
//
//  This macro demonstrates how to use the getCursorLoc() function
//  to get pixel values interactively from inside a macro.
//  Run the macro, move the cursor over the active image, then
//  press left mouse button to get the point values.
//  Press the right mouse button to end the macro.

requires("1.37r");
leftButton=16;
rightButton=4;
run("Select None");
setOption("DisablePopupMenu", true);
// get points
getCursorLoc(x, y, z, flags);

while (flags&rightButton==0)  { //until right pressed
     getCursorLoc(x, y, z, flags);
     if (flags&leftButton!=0 ){ //left pressed
          makeRectangle(x, y, 1, 1);
          p=getPixel(x,y);

          if (bitDepth()==24)
               print("x:" + x +"  y:" + y + "  R:" + p&0xff0000>>16 + "  G:" +
p&0x00ff00>>8 + "  B:" + p&0x0000ff);
          else
               print("x:" + x +"  y:" + y + "  grey:" + p);

          while (flags&leftButton!=0){  //trap until left released
               getCursorLoc(x, y, z, flags);
          }
     }
}
run("Select None");
setOption("DisablePopupMenu", false);
print("Finished");
//--------------8<----------------------