Copy link to clipboard
Copied
Hello Experts
I am looking for a way to edit multiple objects at the same time.
These are cases where the Global Edit and the Select menu is not able to find all the objects I want to edit.
At some point I recall that maybe there was a shortcut ket sequence that would work. Alt+Shift+?+?.
For example, I want to change the size of multiple objects that are of different sizes to the same size. But when I select them individually and go to Properties to edit their size the H & W show the H & W of the group, not individuals objects. In this case, how do I edit the size of individuals objects?
Thanks!
if you have multiple objects and you want to resize each of them variably, you'll need a script. As you pointed out, transform each uses a uniform scale percentage, so you'd have to select all of the items that should be scaled by a certain percentage, then scale them, deselect and then select the next group.
Fortunately a script for this purpose is really straightforward. Obtain an array of the items you want to process (this could be by pre-selecting them in the UI before running the script,
...Copy link to clipboard
Copied
Transform Each... or more advanced script-based solutions.
Mylenium
Copy link to clipboard
Copied
Thanks. But Transform each does not allow me to specify the width or height of the objects, which is what I want to do. It only allows me to scale them by a %.
Any other ideas?
Copy link to clipboard
Copied
There is a script called "Set all the Things"
But could you perhaps show a screenshot of the problem?
Copy link to clipboard
Copied
if you have multiple objects and you want to resize each of them variably, you'll need a script. As you pointed out, transform each uses a uniform scale percentage, so you'd have to select all of the items that should be scaled by a certain percentage, then scale them, deselect and then select the next group.
Fortunately a script for this purpose is really straightforward. Obtain an array of the items you want to process (this could be by pre-selecting them in the UI before running the script, targeting a certain layer, or programatically identifying the necessary elements. for the purposes of this example, I'll assume you already have an array of items.. Then if need be, we can discuss how to obtain that array. Try this snippet:
function resizeObjectsToSpecificSize()
{
var doc = app.activeDocument;
var layers = doc.layers;
var itemsToResize = [];
//populate the array of items to resize.. for this example, i'm just targeting everything on layers[0];
for(var i=0;i<layers[0].pageItems.length;i++)
{
itemsToResize.push(layers[0].pageItems[i]);
}
const DW = 50; //desired width: 50pt
const DH = 50; //desired height: 50pt
for(var i=0;i<itemsToResize.length;i++)
{
itemsToResize[i].width = DW;
itemsToResize[i].height = DH;
}
}
resizeObjectsToSpecificSize(app.activeDocument.layers[0]
Edit* the above will set the absolute height/width to whatever values are in those constants. To scale proportionally, you'll need to identify the largest dimension of the current object, then do the math to get a scale percentage which will scale the object such that the largest dimension matches your desired dimension. like this:
var myItem = doc.layers[0].pageItems[0];
var largestDimension = myItem.width > myItem.height ? myItem.width : myItem.height;
const desiredDimension = 50; //50pt desired dimension of largest side of object
var scaleFactor = (desiredDimension/largestDimension)*100; // (target value divided by current value) quantity to get a ratio, multiplied by 100 to make a percentage
myItem.resize(scale,scale);
Copy link to clipboard
Copied
Excellent! I will try that out.
Many thanks.
Copy link to clipboard
Copied
Yes - I would like to know more about how to add objects to an array. I brought the layer with the objects I wanted to re-size to the top and ran the script, but got an error on line 52 - which I assume is the final Resize line.
Copy link to clipboard
Copied
to add objects to an array, you have a couple options. either way you do it, you'll need to declare an array and store it to a variable, like so:
var myArray = [];
Nothing in it yet. just an empty array. To add things to the array, you can explicitly set values by index, like so:
myArray[0] = app.activeDocument.pageItems[0];
or the same thing inside a loop, and so you replace 0 with your loop variable, like so:
for(var i=0;i<10;i++)
{
myArray[i] = app.activeDocument.pageItems[i];
}
But neither of these are really ideal. Best practice is to use the Array.push() method, which inserts an element into the end of the array. this is nice because you don't need to know what index you're putting something into, and the array can be any size you want. Just push() and it'll add another element. here's how that looks
for(var i=0;i<myLayer.pageItems.length;i++)
{
myArray.push(myLayer.pageItems[i]);
}
While this looks a lot like the other loop above, this one is different because you could use multiple loops in conjunction to build one larger array. As an example, let's say you wanted to add all of the pageItems from "Layer 1", "Layer 2", and "Layer 3". Consider what would happen if we tried to just use 3 separate loop bodies back to back to back, using the above method of inserting an element by index:
var myArray = [];
for(var i=0;i<Layer1.pageItems.length;i++)
{
myArray[i] = Layer1.pageItems[i];
}
for(var i=0;i<Layer2.pageItems.length;i++)
{
myArray[i] = Layer2.pageItems[i];
}
for(var i=0;i<Layer3.pageItems.length;i++)
{
myArray[i] = Layer3.pageItems[i];
}
At first glance, it might look like this is going to add all of the pageItems to myArray.. But a closer inspection (or perhaps just running it and seeing what happens) will result in unexpected results... The array is much smaller than expected, and perhaps only contains a couple of items from Layer1 or Layer2 (if those layers had more pageItems than Layer3)... This is because in each loop, we're explicitly setting the value of myArray[0] to the first pageItem on whatever layer is currently being looped. So the second loop overwrites the value written by the first loop, and so on.
By utilizing Array.push(), you can use multiple different loops to populate your array, or even a nested loop.. Using the same example as above, 3 layers and we want an array with all the pageItems on them, it would look like this:
var myArray = [];
var sourceLayerNames = ["Layer 1", "Layer 2", "Layer 3"];
for(var i=0,curLayer;i<sourceLayerNames.length;i++)
{
curLayer = layers[sourceLayerNames[i]];
for(var j=0j<curLayer.pageItems.length;j++)
{
myArray.push(curLayer.pageItems[j]);
}
}
As for the error you got, I'm not really sure.. If you could send the file you're using, I can test it and see where the script may be erroring out.