Copy link to clipboard
Copied
I noticed you can still use menu commands in a script, say like Transform - Rotate, and other ones that require additional input... how does that work, can you fill in the required fields from the script as well?
Or is are those menu commands just there so the script can launch and the user fills them in?
Bonjour Maple_Stirrup
Pour agir en fonction de l'objet que sert de masque, il faut se référer à cet objet.
Pour une rotation autour du centre:
1 chercher le centre (pathItems[0])
2 faire tourner l'ensemble (groupe masqué)
3 chercher le nouveau centre (pathItems[0])
4 calculer les écarts centre position 1 et centre position 2 en x et en y
5 faire subir à l'ensemble (groupe masqué) une translation (dx,dy)
Travail à l'ancienne car exécute commande est une possibilité récente dans les scripts.
De elleere
Copy link to clipboard
Copied
Hi Maple_Stirrup, you can perform transformations on pageItems using those item's "methods" which do something to the item. For example, a PathItem has a these methods.
So, for example, the rotate method looks like this:
yourPathItem.rotate(angle[,changePositions][,changeFillPatterns][,changeFillGradients][,changeStrokePattern][,rotateAbout])
Here's how you'd use it:
// grab the first path item in the document
var myPathItem = app.activeDocument.pathItems[0];
// rotate it by 45 degrees
myPathItem.rotate(45);
// rotate it by another 45 degrees from the bottom left
myPathItem.rotate(45, false, false, false, false, Transformation.BOTTOMLEFT);
The second version includes all the optional parameters. Parameters are the equivalent of the "fields" you enter when you rotate via the GUI. The 45 parameter is the rotation angle.
Mark
Copy link to clipboard
Copied
I appreciate the response, but I was specifically wondering if I could use the menu commands. The reason is because the rotate method doesn't center the rotation around the mask of a masked object, but instead, it centers it around all of the objects that it masks... and with what I'm trying to do, the masked objects are existing artwork that's randomly sized, so the rotate method makes the masked artwork jump around in all different directions.
I ran into the same problem with mirroring, and it took me an extra long time to figure out how to readjust. It's frustrating when there's one button that does something fast and easy, but inside a script which normally gives you more options and more control... that there's actually situations where a script gives you less.
Copy link to clipboard
Copied
Oh, oops. I understand now. Sorry, I jumped to the conclusion. 🙂
There is a cool technique you can do with rotating, not sure if it's applicable in your case, but if you can work out the point you wish to rotate around, you can then translate the item so that that point is at the "document origin" (the 0, 0 point), rotate it around (from memory, please check) Transformation.DOCUMENTORIGIN and then translate it back by the same amount you moved it firstly. In this way you can rotate around an arbitrary point on the artboard.
Another idea is to have a look at Execute Menu Command.
Copy link to clipboard
Copied
Nice. Not sure which link is more complete, but this one tells what each command is tied to as well: https://ten5963.wordpress.com/illustrator-ccver-22-menu-commands-list/
Also, tring to figure out the center of my mask, and then rotating around that might be easier than the way I'm doing it, I'm not sure. I find the distance away from each side of artboard, which the art can extend beyond the artboard..., and use those numbers to calculate the repositioning coordinates, but your way is sounding easier.
Edit: Oh I see, you can't rotate around specific coordinates, but around those 9 anchor points. That way still might be easier.
Copy link to clipboard
Copied
Bonjour Maple_Stirrup
Pour agir en fonction de l'objet que sert de masque, il faut se référer à cet objet.
Pour une rotation autour du centre:
1 chercher le centre (pathItems[0])
2 faire tourner l'ensemble (groupe masqué)
3 chercher le nouveau centre (pathItems[0])
4 calculer les écarts centre position 1 et centre position 2 en x et en y
5 faire subir à l'ensemble (groupe masqué) une translation (dx,dy)
Travail à l'ancienne car exécute commande est une possibilité récente dans les scripts.
De elleere
Copy link to clipboard
Copied
That sounds easier than the way I was doing it, thanks!
Copy link to clipboard
Copied
Not sure if I'm improperly using the correct answer marking here or not, but..... renél80416020's post led to ultimately fixing my primary problem the easiest way, so I marked it as correct.
Copy link to clipboard
Copied
Bonjour Mapple_Stirup
Content que mon message en français ait été compris...
Si tu veux d'autres renseignements, c'est toujours posible.
elleere
Copy link to clipboard
Copied
Yes absolutely! 🙂 I learned from renél80416020's post too! (Apologies for my embarrassing start to this thread—I forgot you were a more experienced scripter.)