Script for shortening paths

New Here ,
May 15, 2021 May 15, 2021

Copy link to clipboard

Copied

Hello - 

 

Does anyone know of a script for Illustrator that can shorten paths from the end points? The script would affect multiple paths on the same layer.

For example:

Paths on layer is 10 pts, 20 pts and 25 pts long.

Script prompts user for how much they want reduce length of path. 

User enters 2 pts

Paths are now 8 pts, 18 pts and 23 pts long and are located in the same position as it was previously (except a little shorter on each end)

Thanks for your help!

TOPICS
Scripting

Views

271

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 , May 16, 2021 May 16, 2021
// select your lines before running var diff = prompt("Decrease path length by (points):", "", " "); var sel = app.activeDocument.selection; for (var i = 0; i < sel.length; i++) { var h = sel[i].height, w = sel[i].width; var c = Math.sqrt(Math.pow(h, 2) + Math.pow(w, 2)); var percentage = ((c - diff) / c) * 100; selection[i].resize(percentage, percentage, true, false, false, false, 0, Transformation.CENTER); }

Likes

Translate

Translate
Adobe Community Professional ,
May 15, 2021 May 15, 2021

Copy link to clipboard

Copied

no I haven't seen a script for such a task.

 

can you show the kind of paths you want to shorten? '

 

post a screen shot or better yet a sample ai file

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
New Here ,
May 16, 2021 May 16, 2021

Copy link to clipboard

Copied

Hello - thank you for your reply.  I made an example file showing a hypothetical before and after.  In my example, the lines are shorted by 10pts each, regardless of the original size of the line.  In addition, the angles of the lines remain the same (those lines that are not straight up and down).  In addition, the lines are shorted equalty from each end, so that the midpoint of the line is in the same location.  Apologes for the pdf file, but it would not let me an an AI file for some reason.

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 ,
May 16, 2021 May 16, 2021

Copy link to clipboard

Copied

// select your lines before running
var diff = prompt("Decrease path length by (points):", "", " ");
var sel = app.activeDocument.selection;
for (var i = 0; i < sel.length; i++) {
    var h = sel[i].height,
    w = sel[i].width;
    var c = Math.sqrt(Math.pow(h, 2) + Math.pow(w, 2));
    var percentage = ((c - diff) / c) * 100;
    selection[i].resize(percentage, percentage, true, false, false, false, 0, Transformation.CENTER);
}

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
New Here ,
May 16, 2021 May 16, 2021

Copy link to clipboard

Copied

LATEST

Loaded the script in and it looks like it works as I hoped it would.  Well done, thank you very much!

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