1 Reply Latest reply on Aug 17, 2015 9:35 AM by williamadowling

    Resize group

    CREAT-IT Level 1

      Hi,

       

      I have a group called "Preview" and I want to resize it proportionally.

       

      If Width > Heigth then width of group must be set to 350px

       

      If Width < Heigth then height of group must be set to 350px

       

      I am familiar with scripting , but new with Illustrator scripting.

       

      Thanks in advance.

       

      Greetings,
      Robin

        • 1. Re: Resize group
          williamadowling Level 4

          Do you have any live strokes that need to be accounted for? If so, we'll need to calculate the width/height differently. But this works with no live strokes.

           

          function resizeGroup(){
              app.preferences.setIntegerPreference("rulerType", 6);
              var docRef = app.activeDocument;
              var preview = docRef.layers[0].groupItems.getByName("Preview");
              var pW = preview.width;
              var pH = preview.height;
              var maxWidth = (350/pW)*100;
              var maxHeight = (350/pH)*100;
              if(pW > pH){
                    preview.resize(
                        maxWidth,
                        maxWidth,
                        true,
                        true,
                        true,
                        true,
                        00,
                  )
              }
              else if(pH > pW){
                    preview.resize(
                        maxHeight,
                        maxHeight,
                        true,
                        true,
                        true,
                        true,
                        00,
                  )
          
          
              }
          }
          resizeGroup();