• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

546

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

Guide , 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);
}

Votes

Translate

Translate
Adobe
Community Expert ,
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

Votes

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.

Votes

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
Guide ,
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);
}

Votes

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!

Votes

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