Skip to main content
Known Participant
August 26, 2020
Answered

Script menu commands that require additional input

  • August 26, 2020
  • 3 replies
  • 1203 views

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?

This topic has been closed for replies.
Correct answer renél80416020

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

 

 

 

 

3 replies

Known Participant
August 29, 2020

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.

renél80416020
Inspiring
August 29, 2020

Bonjour Mapple_Stirup

Content que mon message en français ait été compris...

Si tu veux d'autres renseignements, c'est toujours posible.

elleere

 

 

renél80416020
renél80416020Correct answer
Inspiring
August 28, 2020

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

 

 

 

 

Known Participant
August 28, 2020

That sounds easier than the way I was doing it, thanks!

m1b
Community Expert
Community Expert
August 27, 2020

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

Known Participant
August 27, 2020

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.

m1b
Community Expert
Community Expert
August 28, 2020

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.