I can't seem to get the move method to work, it lists move( relativeObject, insertionLocation ) or would I use the transform method here instead?
I can't seem to find examples of move or transform being used unfortunately.
Copy link to clipboard
move(), as I understand it, corresponds to the "Arrange" command in the Object menu. So, it "moves" a path above or below another path (in the example below, named path1 and path2).
var paths = app.activeDocument.pathItems; paths["path1"].move(paths["path2"], ElementPlacement.PLACEAFTER);
It sounds like what you want is translate(dx, dy), which moves the path by dx and dy distances from the present position. So
moves the path 100 points in the positive x direction and 100 points in the positive y direction.
Alternatively, you can assign new values for the position property:
paths["path1"].position = [x, y];
I've not figured out how transform and transformation matrices work.
Nice! .position is what I was looking for.
Without having to complicate things and introduce me having to do math with the visible bounds, is there a way to get the .position to apply to the mask of a clipped group? Unfortunately the .position factors in the whole content and not the mask.
Most items have a position property. So in the clipping mask from the preceding thread (Trying to assign a variable name to a masked object using a menu command in jsx), you can reassign the position of the whole "clipping set" group,
clippingSet.position = [x, y];
just the "clipping path"
clippingSet.pathItems["clippingPath"].position = [x, y];
or just the "masked artwork".
clippingSet.pathItems["maskedArtwork"].position = [x, y];
The key is getting the hang of Illustrator's object model to be able to reference the items you want.
Yeah I'm pretty sure I'm setting the position of the entire set and it's not working,.. it's moving the entire set, which is what I want, ... but it's using the masked artwork as what determines the position.
Yeah if I run this code in an existing document, the final .position line of code doesn't put the circle at [0,0], but instead the square.
var myDoc = app.activeDocument; var square = myDoc.pathItems.rectangle(-100,100,100,100); var circlemask = myDoc.pathItems.ellipse(-120,120,60,60); var finalGroup = myDoc.groupItems.add(); square.moveToBeginning(finalGroup); circlemask.moveToBeginning(finalGroup); finalGroup.clipped = true; finalGroup.position = [0,0];
Yes, because the position of the finalGroup is the same as the position of the square (this is the case before and after you move it). The outer part of the square still exists, it's just hidden and not directly selectable from the artboard, but if you switch to Outline mode (Ctrl+Y) or select it from the layers panel, you'll see it still exists.
So there's no way easy way to set the position using the circle in a script?
I can use math I guess, but I was hoping for an easier way.
Yes, math it is, but it shouldn't be that hard. All you need is to calculate the distances between the circle and the finalGroup and subtract these distances from the final position you want.
var myDoc = app.activeDocument; var square = myDoc.pathItems.rectangle(-100,100,100,100); var circlemask = myDoc.pathItems.ellipse(-120,120,60,60); var finalGroup = myDoc.groupItems.add(); square.moveToBeginning(finalGroup); circlemask.moveToBeginning(finalGroup); finalGroup.clipped = true; var xInterval = circlemask.position - finalGroup.position; var yInterval = circlemask.position - finalGroup.position; finalGroup.position = [0 - xInterval, 0 - yInterval];
Caveats: (1) "position" does not include stroke weight, so you will have to calculate for that, and (2) the x and y elements cannot be assigned individually, i.e. "position" must be assigned an array [x, y].
Is there an easy way to expand all strokes inside a grouped object?
Also if jsx feature requests are a thing, .clipposition seems like it should be a thing.
I haven't used either myself, but to expand a path (brings up dialog box):
or to outline a stroke: