16 Replies Latest reply on Dec 12, 2015 1:21 PM by CarlosCanto

# Illustrator Resize Path to a certain length

Hi,

I was wondering if it is possible to set the pathItem length to a certain number. In this thread measure the length of a path in Illustrator   the calculation of how to measure the length is explained. When I try to set the app.activeDocument.selection[0].length = 10 Basically nothing happens. How can I manage to set the length of a given path to a certain measurement?

• ###### 1. Re: Illustrator Resize Path to a certain length

the length property of a line is read only.
if its a straight line you can do some trigonometry to re-position 1 of the points.

if its an arc, the math gets harder!

• ###### 2. Re: Illustrator Resize Path to a certain length

If they are straight lines you could perhaps use '.width' for horizontal and '.height' for vertical. If they are two point lines, you could also check and compare the x/y of the two points relationship to each other to know which orientation the line is and when to then use .width or .height. But I would rather see Qwertyfly... bust out some trig. ;-)

• ###### 3. Re: Illustrator Resize Path to a certain length

if you use resize, transform, or modify the width and height you also need to reset stroke width an any other effect. (as far as I can tell).

Hows this...

I am assuming that point a stays put and point b is moved to the new location.

and I have not bothered with inch or mm so you have to be working in points.

left the alert at the end so you can gauge the amount of change as a scale in percentage.

```var sel = app.activeDocument.selection;
var newLength = "120"; //this is in points
if(sel[0].pathPoints.length == 2){
var scale = newLength/sel[0].length;
var A = sel[0].pathPoints[0].anchor;
var B = sel[0].pathPoints[1].anchor;
var newB = [((B[0]-A[0])*scale)+A[0],((B[1]-A[1])*scale)+A[1]];
sel[0].pathPoints[1].anchor = newB;
sel[0].pathPoints[1].leftDirection = newB;
sel[0].pathPoints[1].rightDirection = newB;
}
```
• ###### 4. Re: Illustrator Resize Path to a certain length

For basic straight lines with the "basic" brush applied using w/h seems to be fine in my tests. But yeah I suspect you could run into distortion and problems with this approach beyond these basic criteria.

Nice snippet. I still chuckle when I think of seeing you comment that you don't feel you are that great at math in a previous post, yet you just keep posting nuggets of math goodness. ;-)

• ###### 5. Re: Illustrator Resize Path to a certain length

with the basic things like trig and simple algebra I can nut it out(with the help of Google), but it leaves me with a numb brain.
the complex ideas (still simple as far as maths goes) just hurt.

take this page, I would love to have a better understanding of bezier curves. and this looks to be a good source of info.

A Primer on Bézier Curves

I'm starting to get lost by the time polynomials get mentioned.

by the time he's talking about the relationship of polnomial functions to matrix operations,

my brain has up and left the building and I'm poking around the back of the cupboard looking for the remains of a bottle of scotch.

• ###### 6. Re: Illustrator Resize Path to a certain length

Every time i see one of these posts by you Qwerty, i think to myself "it's just about time i stop slacking and learn these complex math concepts once and for all." Then i never do anything about it. But this time I am. I'm buying an advanced algebra book and I'm going to learn everything i need to know to understand that whole mind numbing writeup on Bezier curves.

Thanks for unknowingly motivating me to do so.

• ###### 7. Re: Illustrator Resize Path to a certain length

@ william, may the mathematical force be with you.

Qwertyfly wrote:   with ..... complex ideas ..... I'm starting to get lost ..... my brain has up and left the building

+1

• ###### 8. Re: Illustrator Resize Path to a certain length

Could you perhaps post a picture and a more detailed explanation of what your goal is? Is the pathItem that you want to resize just a line segment with 2 points and you want to change the distance between those 2 points? Or are you trying to set the width or height of a rectangle or other shape?

'length' is not a property that has anything to do with the size of an object. length refers to the number of items inside an array. the code snippet you posted above is attempting to set the number of items in your selection to 10. It can't simply set the length to a different number because length is just the number of items that exist. It can't create or destroy items randomly to accommodate the new value for length that you're assigning.

assuming you're trying to resize the actual object, try using the 'width' or 'height' property to get your desired result. example:

app.activeDocument.selection[0].width = 10;

Note that i added an index to selection. width is not a property of selection, but it is a property of the items contained within the selection array. assuming your selection is just 1 path, it's ok to simply say 'get me the first item of the selection array and set it's width property to 10'.

Hope this helps.

• ###### 9. Re: Illustrator Resize Path to a certain length

@ william, we already touched upon using .width and other related properties above. I do agree an image of what paths are desired to be targeted would be helpful.

• ###### 10. Re: Illustrator Resize Path to a certain length

woops. i got so caught up in the discussion about math and trig and manipulating bezier curves that i completely missed that.

sorry all.

• ###### 11. Re: Illustrator Resize Path to a certain length

"length" of a pathItem is actually the length of the bezier path.

• ###### 12. Re: Illustrator Resize Path to a certain length

No biggie, yeah the math stuff is distracting.

• ###### 13. Re: Illustrator Resize Path to a certain length

You are correct Silly. I saw "selection.length" and immediately saw a red flag, since selection is an array. i did not know about the length property of a pathItem until after i made that reply and i did a quick test.

• ###### 14. Re: Illustrator Resize Path to a certain length

iit's not a well named property.

As length is used to describe the number of items in an array.

The path item property should be distance or something, not length

• ###### 15. Re: Illustrator Resize Path to a certain length

Let's face it, understanding the ineptness and omissions of the Adobe scripting documentation is worse than basic math, let alone advanced math.

• ###### 16. Re: Illustrator Resize Path to a certain length

that's why I like vb property names better

pathItems.count = 5 '5 items

pathItem.length = 5 '5 points