Script to draw line and/or take measurements from pixel coordinates
Hello again.
I've recently asked how to save a set of coordinates in pixels (X;Y) to a .txt/.csv using a script, and got several successful replies to solve my previous problem. I now have a follow-up.
My goal would be to create a script that would allow me to draw lines between two coordinate-specific points, indicated with X;Y coordinates (in pixels) on the image. I have found several scripts online that gave me some hints about the general setup for such a script, but ideally I would like one that could "continue the work" started by the previous script. In other words, I would like to be able to draw lines between the specific points-coordinates that I marked and saved in the .txt/.csv file. Alternatively, a script that does both things at once (export the pixel coordinates to a .txt/.csv, and draw the lines).
The lines would, ideally, not always be consecutive. In other words, I wouldn't want a continuous line that goes from point 1 to point 2 to point 3 to point 4 and so on. Rather, a line from point 1 to 2, then 3 to 4, and so on. This probably complicates things a lot with the script, so the most versatile solution, I think, would be a script capable of reading the X;Y coordinates from a .txt/.csv and then draw from there.
My current "workaround" to this problem is to manually compile a script where I would draw each individual line, using the coordinates found and saved in the .txt/.csv. In other words, a "basic template" like this:
drawLine([startX1,startX2],[endX1,endY1],3);
drawLine([startX1,startX2],[endX2,endY2],3);
[...]
This should allow me to draw separate lines just where I need them. However, as it goes without saying, replacing the coordinates manually like that is a bit slow, and would also require to make a separate script for each "drawing" I need to make. If, however, there was a way to automatize that...for example, telling the script that "startX1" values are found in the A2 cell of the .csv file, or that the "startX1;startY1" coordinates are always the ones from the first point marked with the Count Tool...I don't know >.<
So...any ideas? My best "solution" is trying to automatize the process with autohotkey (so I'd first save the coordinates from the .csv, then have autohotkey compile a script with copy-pastes, and lastly run the script in photoshop to draw the lines), but it's evidently not optimal, nor particularly elegant.
A further evolution would be a script capable of also taking the pixel measurement between the marked points. To be honest this can very easily be done simply with an excel formula and a bit of trigonometry, after getting the X;Y coordinates exported to a .csv -- doing it with a script would just be for "elegance's sake", but I don't really need it. If there is an easy way to do it, then it'd be really nice to have that too; if not, nevermind.
Bonus last question: is there maybe a way to rename the "labels" used by the Count Tool? The script I'm using now to save the points coordinates uses the Count Tool to mark the points with numbers (1,2,3,4,5,...). I tried searching online and didn't find anything about a way to custom-rename the "name of the points" (labels) of a count, so I'm guessing there is no way to do it. Anyway, it would have been a nice extra touch to be able to mark the points with custom labels (in a fixed order), for example "bottle tip", "dish center", and so on. Really not that important though 😛
