Copy link to clipboard
Copied
Is there a way to look at the group items and move them to individual pages based on their size?
My goal is to select for example 3 grouped items.
Check the width and height to see if a landscape or portrait file should be opened. Then place the group on the correct file.
Group 1: 5" wide x 9" tall
Open the file
C:/Master Templates/8.5x11 Portrait.ait
Because the group is taller than it is wide
Put Group 1 on that page
Group 2: 6.5" wide x 8" tall
Open the file
C:/Master Templates/8.5x11 Portrait.ait
Because the group is taller than it is wide
Put Group 2 on that page
Group 3: 12" wide x 9.25" tall
Open the file
C:/Master Templates/8.5x11 Landscape.ait
Because the group is wider than it is tall
Put Group 3 on that page
Windows 7 64-Bit CS4
Thanks!
Copy link to clipboard
Copied
This should get you started...
var doc = app.activeDocument;
var group = doc.groupItems;
for(var i = 0; i < group.length; i++)
{
var template;
if (group.height > group.width)
{
template = new File("C:/Master Templates/8.5x11 Portrait.ait");
} else {
template = new File("C:/Master Templates/8.5x11 Landscape.ait");
}
var temp = app.open(template);
var newItem = group.duplicate(temp,ElementPlacement.PLACEATBEGINNING );
}
Copy link to clipboard
Copied
OK So thank you so much that is working beautifully!! So now I am working on getting the grouped items to scale into a specific size of my templates.....any thoughts on how to do that? My scaling portion is not working correctly....I am just working on the portrait layout first then will work on the landscape.
#target illustrator
var doc = app.activeDocument;
var group = doc.groupItems;
var maxHeightPort = 689.0;
var maxWidthPort = 567.0;
var maxHeightLand = 518.0;
var maxWidthLand = 738.0;
var scaleRatio = 0;
for(var i = 0; i < group.length; i++)
{
var template;
if (group.height > group.width)
{
template = new File("C:/Master Templates/8.5x11 Portrait.ait");
if(group.height < maxHeightPort){
scaleRatio = maxHeightPort / group.height;
group.width = group.width * scaleRatio;
group.height = group.height * scaleRatio;
group.resize(group.width, group.height);
}
if(group.width < maxWidthPort){
scaleRatio = maxWidthPort / group.width;
group.width = group.width * scaleRatio;
group.height = group.height * scaleRatio;
group.resize(group.width, group.height);
}
} else {
template = new File("C:/Master Templates/8.5x11 Landscape.ait");
}
moveItem();
}
function moveItem(){
var temp = app.open(template);
var newItem = group.duplicate(temp,ElementPlacement.PLACEATBEGINNING);
if (newItem.position != "0,0"){
newItem.position = [0,0];
}
else{
//alert("Is 0,0");
}
}
Copy link to clipboard
Copied
your scale ratio is always 0.
so when you multiply your width or height by 0 you get 0...
the .resize function in in percentage.
so you need to work out what percentage to scale.
use the below to get a handle on whats next.
this will set all items selected to 50x100 pts
var sel = app.activeDocument.selection;
myW = 50
myH = 100
for(var i = 0; i < sel.length; i++)
{
w = sel.width;
h = sel.height;
perW = (myW / w)*100;
perH = (myH / h)*100;
sel.resize(perW,perH)
}
my thoughts are that you don't want to distort your artwork.
So if Height is larger then Width,
open portrait.ait and place item.
then:
something like this:
var sel = app.activeDocument.selection;
maxW = 50
maxH = 100
for(var i = 0; i < sel.length; i++)
{
w = sel.width;
h = sel.height;
percentageToGetMaxH = (maxH / h)*100;
percentageToGetMaxW = (maxW / w)*100;
if ((percentageToGetMaxH/100)*w < maxW)
{
sel.resize(percentageToGetMaxH,percentageToGetMaxH);
}else{
sel.resize(percentageToGetMaxW,percentageToGetMaxW);
}
}
You will need to reverse the last if statement if sending to landscape.
hope this makes sense.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now