How to select all Smooth pathPoints that have two handles aligned at horizontal or vertical axis?

Explorer ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

How to select all Smooth pathPoints that have two handles aligned at horizontal or vertical axis? Via scripting.

Thanks!

TOPICS
Draw and design, Scripting

Views

94

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Enthusiast , Apr 27, 2021 Apr 27, 2021
var paths = app.activeDocument.pathItems; for (var i = 0; i < paths.length; i++) { var points = paths[i].pathPoints; for (var j = 0; j < points.length; j++) { var x = points[j].anchor[0], y = points[j].anchor[1]; var Rx = points[j].rightDirection[0], Ry = points[j].rightDirection[1]; var Lx = points[j].leftDirection[0], Ly = points[j].leftDirection[1]; if ((Rx == Lx && Ry != Ly) || (Ry == Ly && Rx != Lx)) { points[j].selected = PathPointSelecti...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

each pathPoint has 2 properties called leftDirection and rightDirection each of which hold an array of 2 numbers representing the (x,y) position of the end of the control handle. if the "left" or "x" coordinate of both left/rightDirection are the same, then they're aligned vertically. If the "top" or "y" coordinate of both left/rightDirection are the same, they're aligned horizontally. 

var myPath = app.activeDocument.pathItems[0];
myPoint = myPath.pathPoints[0];
if(myPoint.pointType === PointType.CORNER)
{
	//probably skip this point since it can never be
	//the type of smooth edge point you're looking for
	alert("this is a corner point.");
}
else if(myPoint.leftDirection[0] === myPoint.rightDirection[0])
{
	alert("handles are aligned vertically");
}
else if(myPoint.leftDirection[1] === myPoint.rightDirection[1])
{
	alert("handles are aligned horizontally");
}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

Thanks, DilliamWowling, but your code not works for me. Maybe i'm doing something wrong.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

my comment was intended to be educational, not functional. I was showing you how to accomplish what you want to do.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

LATEST

Thanks, DilliamWowling, my JavaScript programming skills are very limited.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

var paths = app.activeDocument.pathItems;
for (var i = 0; i < paths.length; i++) {
    var points = paths[i].pathPoints;
    for (var j = 0; j < points.length; j++) {
        var x = points[j].anchor[0], y = points[j].anchor[1];
        var Rx = points[j].rightDirection[0], Ry = points[j].rightDirection[1];
        var Lx = points[j].leftDirection[0], Ly = points[j].leftDirection[1];
        if ((Rx == Lx && Ry != Ly) || (Ry == Ly && Rx != Lx)) {
            points[j].selected = PathPointSelection.ANCHORPOINT;
        }
    }
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

Works! Thanks! femkeblanco

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines