Skip to main content
New Participant
May 30, 2017
Question

Transform all objects by multiplier

  • May 30, 2017
  • 6 replies
  • 1908 views

Hi there!

I'm new to scripting and I can't find an example of a javascript that mimics Transform panel behaviour.

I need to change width or height of all selected objects that are on different layers (without grouping) by certain set of multipliers (I don't wanna input them manually every time). And that objects should be transformed relative to the center reference point.

I've tried different solutions that I've found on the internet but I can't figure out how to do that.

When I do it manually I hit Ctrl+A, then type in Transform panel [*0,6512], hit Enter. So I want to automate it.

Is that possible? Could someone help me please?

This topic has been closed for replies.

6 replies

Loic.Aigon
Brainiac
June 2, 2017

Exactly.

Disposition_Dev
Brainiac
May 31, 2017

This is exactly what I had in mind, Loic. Good work.

Loic.Aigon
Brainiac
May 31, 2017

Thanks williamadowling

Loic.Aigon
Brainiac
May 30, 2017

So to be illustratorly useful :

var sel = app.selection;

var n = sel.length;

while ( n-- ) sel.resize ( 50, 50 )

Disposition_Dev
Brainiac
May 30, 2017

Loic,

This will work to resize each item, but each item will be resized relative to it's own center, which means that if you resize two items, their positions (relative to one another) will change. See this screenshot as an example.

http://imgur.com/xyn8Bdh 

In order to resize each piece individually, you'll also have to include logic that repositions the art after it's resized so it's placement relative to the desired reference point, remains the same.

Silly-V
Brainiac
May 31, 2017

You can perform a transform like how you wish by script only, without having to necessarily use a document selection. This can be done by temporarily changing your document's origin to a desired location and performing the transform scripting commands then. The origin would be in the center of the bounding box of the art in question, or any arbitrary point.

Re: Rotate around a custom pivot???

Loic.Aigon
Brainiac
May 30, 2017

williamadowling​ I constantly jump from InDesign Scripting forum to here and sometimes I miss the fact I am not in the good room My apologises for those being misleaded.

Disposition_Dev
Brainiac
May 30, 2017

Loic, I don't believe Illustrator has that same functionality as the Illustrator API is severely anemic compared with InDesign's API.

eoneof, What you're looking for is definitely doable, but requires a few custom components and calculations to make sure the art is resized relative to the center of a given reference point.

Do you have any code written you'd like us to help with or are you looking for someone to write the code?

eoneofAuthor
New Participant
May 30, 2017

I have a suitable piece of code from other script:

if ( documents.length > 0)

  mySelection = activeDocument.selection;

  if (mySelection instanceof Array) {

  initBounds = mySelection[0].visibleBounds;

  ul_x = initBounds[0];

  ul_y = initBounds[1];

  lr_x = initBounds[2];

  lr_y = initBounds[3];

  for (i=1; i<mySelection.length; i++) {

  groupBounds = mySelection.visibleBounds;

  if (groupBounds[0]<ul_x){ul_x=groupBounds[0]}

  if (groupBounds[1]>ul_y){ul_y=groupBounds[1]}

  if (groupBounds[2]>lr_x){lr_x=groupBounds[2]}

  if (groupBounds[3]<lr_y){lr_y=groupBounds[3]}

              var wid = lr_x-ul_x 

              alert (wid)

  }

           

  }

Here I managed to get to know current objects' width, but I have no idea what's next.

Disposition_Dev
Brainiac
May 30, 2017

when you say "current object" do you mean the current selection?

That snippet seems needlessly cryptic. But perhaps it's just a different style than i'm used to writing. It looks like that snippet alerts the difference between lr_x and ul_x (initBounds[2] - initBounds[0]) which is the right edge - left edge.

This is a way to give you the information about the width of multiple ungrouped objects, but it will not help you to resize anything since you cannot resize a selection of objects. You can only resize a single object at a time. So you can either loop each object and resize it individually (which would then require additional logic to reposition it so it's in the same relative position to your chosen reference point) or else you could take the existing selection, temporarily group it together, resize the entire group at once, then ungroup it.

Loic.Aigon
Brainiac
May 30, 2017

Transfomations are both easy to apply and tough to acquire (Understanding CoordinateSpaces, reference points, bridges between points and contextual units). You may be interested in PageItem Collection's transform() method :

InDesign ExtendScript API (10.0)

And in UnitValue, always valuable to use in combination with transform:

http://www.indesignjs.de/extendscriptAPI/indesign10/#UnitValue.html