Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Grouped Items to individual pages?

Engaged ,
Feb 02, 2015 Feb 02, 2015

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!

TOPICS
Scripting
421
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guide ,
Feb 02, 2015 Feb 02, 2015

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 );

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 05, 2015 Feb 05, 2015

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");

  }

  }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 05, 2015 Feb 05, 2015
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines