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

Resize Clip Group

Engaged ,
Dec 25, 2022 Dec 25, 2022

Copy link to clipboard

Copied

I am looking for a script to resize selected clipped groups (usually 3) to a specific dimension, 50X70 cm

I don't care for keeping the selected groups dimensions ratio

Can anybody help ?

 

TOPICS
Scripting

Views

405

Translate

Translate

Report

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

correct answers 1 Correct answer

Enthusiast , Dec 25, 2022 Dec 25, 2022

 

 

 

(function() {
  var w = 500; // Width, mm
  var h = 700; // Height, mm
  var pos = null;

  for (var i = 0, len = selection.length; i < len; i++) {
    var s = selection[i];
    var m = null;
    if (s.typename === 'GroupItem' && s.clipped) {
      m = getMask(s.pageItems);
    } else {
      m = s;
    }

    // Get scale ration and resize
    var rX = 100 * mm2px(w) / m.width;
    var rY = 100 * mm2px(h) / m.height;
    s.resize(
      rX, // X
      rY, // Y
      true, // Change Positions
...

Votes

Translate

Translate
Adobe
Enthusiast ,
Dec 25, 2022 Dec 25, 2022

Copy link to clipboard

Copied

 

 

 

(function() {
  var w = 500; // Width, mm
  var h = 700; // Height, mm
  var pos = null;

  for (var i = 0, len = selection.length; i < len; i++) {
    var s = selection[i];
    var m = null;
    if (s.typename === 'GroupItem' && s.clipped) {
      m = getMask(s.pageItems);
    } else {
      m = s;
    }

    // Get scale ration and resize
    var rX = 100 * mm2px(w) / m.width;
    var rY = 100 * mm2px(h) / m.height;
    s.resize(
      rX, // X
      rY, // Y
      true, // Change Positions
      true, // Change Fill Patterns
      true, // Change Fill Gradients
      true, // Change Stroke Pattern
      100, // Stroke scale %
    );

    // Horizontal stack order from first selected object
    if (i == 0) {
      pos = m.position;
    } else {
      s.translate(pos[0] - m.position[0] + m.width, pos[1] - m.position[1]);
      pos = m.position;
    }
  }


  function getMask(arr) {
    for (var i = 0, len = arr.length; i < len; i++) {
      var p = arr[i];
      if (p.typename === 'PathItem' && p.clipping) {
        return p;
      } else if (p.typename === 'CompoundPathItem' && p.pathItems.length && p.pathItems[0].clipping) {
        return p;
      }
    }
  }

  function mm2px(n) {
    return n * 2.83464567;
  }
})();

 

 

 

2022-12-26 11.30.33.gif

Votes

Translate

Translate

Report

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 ,
Dec 26, 2022 Dec 26, 2022

Copy link to clipboard

Copied

Perfect!
Thank you, @Sergey Osokin

It is possible to distribute resized clip groups one next to the other ?  

Votes

Translate

Translate

Report

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
Enthusiast ,
Dec 26, 2022 Dec 26, 2022

Copy link to clipboard

Copied

If I understand correctly, you need to make a stacked order? I updated the script code in a previous post.

2022-12-26 18.07.45.gif

Votes

Translate

Translate

Report

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 ,
Dec 26, 2022 Dec 26, 2022

Copy link to clipboard

Copied

LATEST

Yes, this is what I was looking for, many thanks I leaned a lot about clipped groups!

Votes

Translate

Translate

Report

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