Skip to main content
Participant
August 17, 2015
Question

Resize group

  • August 17, 2015
  • 1 reply
  • 324 views

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

This topic has been closed for replies.

1 reply

Disposition_Dev
Legend
August 17, 2015

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