How do you get properties (like endpoint coordinates) of a line tool or pen tool usage?

Suppose I press U/P to invoke the line tool/pen tool and I make a single line segment. How do I retrieve the coordinates of the endpoints of the line segment?

I know that I can select the layer with the line segment on it and do:

const app = require('photoshop').app;
let bounds = Object.values(app.activeDocument.activeLayers[0].bounds);

However, the bounds do not tell me the orientation of that line segment (does it slope upwards or downwards from the left?)

How do I actually access the coordinates of the line segment?

How about subpath items in path items?

It contains path points

Note: you might need to convert vector mask into vector path in advance.

For line tool as pre-defined shape layer… you could use keyOriginType atribute that stores info about start point and end point.

Please keep in mind that this is not true for all lines. The line must be made by line tool only.

Hi Jarda!

Thanks for this information. I am unsure how to access that. My first thought is by retrieving it with a batch command

   _obj: "get",
   _target: [{
      _ref: "layer",
      _enum: "ordinal"}],

but I’m not sure how this data would be fed into something I can manipulate. This feels like a basic question, and I thought I collected notes on this, but I cannot find any information on it.

You can use Alchemist plugin as seen on screenshot. There is “code” tab where it can generate source code for you.

Thanks for the link. That’s actually what I used to retrieve the batchplay descriptor. What confused me was putting it in a function. What I ended up doing with the “get” basic event descriptor from the previous post (as per your suggestion to, specifically, look at the code tab, which helped a lot) was destructuring the output like this:

const [layerInfo] = await batchPlay([eventGetLayerInfo],{});
return layerInfo;

then I was able to access the coordinates you mentioned via, for example:
which should return a number.

Thanks for that suggestion! That let me consolidate some functionality instead of relying on the layer bounds. This even exposes more properties that a line layer would have, letting me put the function behind some checker to make sure that the right kind of layer is selected.

1 Like