3 Replies Latest reply on Feb 5, 2015 2:42 PM by Qwertyfly...

    Grouped Items to individual pages?

    subieguy2 Level 1

      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!

        • 1. Re: Grouped Items to individual pages?
          Qwertyfly... Level 4

          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[i].height > group[i].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[i].duplicate(temp,ElementPlacement.PLACEATBEGINNING );
          }
          
          • 2. Re: Grouped Items to individual pages?
            subieguy2 Level 1

            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[i].height > group[i].width)
                    {  
                        template = new File("C:/Master Templates/8.5x11 Portrait.ait");
              if(group[i].height < maxHeightPort){
              scaleRatio = maxHeightPort / group[i].height;
              group[i].width = group[i].width * scaleRatio;
              group[i].height = group[i].height * scaleRatio;
              group[i].resize(group[i].width, group[i].height);
              }
              if(group[i].width < maxWidthPort){
              scaleRatio = maxWidthPort / group[i].width;
              group[i].width = group[i].width * scaleRatio;
              group[i].height = group[i].height * scaleRatio;
              group[i].resize(group[i].width, group[i].height);
              }
                     } else {  
                        template = new File("C:/Master Templates/8.5x11 Landscape.ait");  
                     }  
              moveItem();
            }
            
            
            function moveItem(){
              var temp = app.open(template);
                 var newItem = group[i].duplicate(temp,ElementPlacement.PLACEATBEGINNING);
              if (newItem.position != "0,0"){
              newItem.position = [0,0];
              }
              else{
              //alert("Is 0,0");
              }
              }
            
            
            
            
            
            
            
            
            
            
            
            
            
            • 3. Re: Grouped Items to individual pages?
              Qwertyfly... Level 4

              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[i].width;
                  h = sel[i].height;
                  perW = (myW / w)*100;
                  perH = (myH / h)*100;
              sel[i].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[i].width;
                  h = sel[i].height;
                  percentageToGetMaxH = (maxH / h)*100;
                  percentageToGetMaxW = (maxW / w)*100;
                  if ((percentageToGetMaxH/100)*w < maxW)
                  {
                      sel[i].resize(percentageToGetMaxH,percentageToGetMaxH);
                  }else{
                     sel[i].resize(percentageToGetMaxW,percentageToGetMaxW);
                  }    
              }
              

               

              You will need to reverse the last if statement if sending to landscape.

               

              hope this makes sense.