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

Script Resize selection Proportionately based on top object dimensions

Explorer ,
Nov 19, 2025 Nov 19, 2025

Figured out a way to loop through a selection and resize everything proportionately to the top object. Is there a way to do this more elegantly? Transformation.DOCUMENTORIGIN seems to be the key, as all objects will be resized relatively, otherwise they are resized based on their own anchors. I reset the view at the end or otherwise it's way off.

    function ccCalcPerc(from, to) {
        //currently only illustrator
        //Times 72 if you're in inches
        return (to * 72) / from * 100
    }
    function aiObjBounds(obj) {
        //Get Geometric Bounds 
        /* Left, Top, Right and Bottom 
        + - 1 - +
        |       |
        0       2
        |       |
        + - 3 - +
        */
        var bounds = obj.typename === "Artboard" ? obj.artboardRect : obj.geometricBounds,
            left = bounds[0];
        top = bounds[1];
        right = bounds[2];
        bottom = bounds[3];
        width = right - left;
        height = top - bottom;

        props = {
            bounds: [left, top, right, bottom],
            left: left,
            top: top,
            right: right,
            bottom: bottom,
            width: Math.abs(width),
            height: Math.abs(height),
            obj: obj
        };

        return props;
    }
var aD = app.activeDocument;
d = aiObjBounds(aD.selection[0]);
b = 5;
aSel = aD.selection;
        var wPerc = ccCalcPerc(d.width, sizeIN);
        var hPerc = ccCalcPerc(d.height, sizeIN);//Add conditional to use height Percentage instead
for (k in aSel) {
//To scale proportionately, the percentage is calculated once and used for both.
    aSel[k].resize(wPerc, wPerc, true, true, true, true, 100, Transformation.DOCUMENTORIGIN)
}
aD.selection = null;
aSel[0].selected = true;
app.executeMenuCommand("Fit Artboard to selected Art")
app.executeMenuCommand("fitin");
app.executeMenuCommand("zoomout");

 

TOPICS
How-to , Scripting
163
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
Advocate ,
Nov 25, 2025 Nov 25, 2025

Bonjour @_wckdTall_ 

Je n'ai pas compris le sens de cette fonction ?

function ccCalcPerc

 Pour la suite, je pense que le script qui suit peut correspondre à votre demande

// JavaScript Document for Illustrator
// de elleere Landry René
// Pour échelle 2:1 tapez 2
// Pour 1:2 tapez 0.5
function test() {
  if (!selection) return;
  var wPerc, hPerc;
      wPerc = hPerc = 2;
  var T = Transformation.DOCUMENTORIGIN;
  var doc = activeDocument;
  var aSel = app.selection;
  var origin = doc.rulerOrigin;
      doc.rulerOrigin = [0,0];
  var rep = prompt("Echelle ?\rwPerc,hPerc",wPerc+","+hPerc);
      rep = rep.split(",");
      wPerc = rep[0]*1;
      hPerc = rep[1]*1;
      cperc = (wPerc+hPerc)/2;
  var Rects = aSel[0].geometricBounds;
        doc.rulerOrigin = centre(Rects);

         for (var k = 0; k < aSel.length; k++) {
            aSel[k].resize(wPerc*100, wPerc*100, true, true, true, true, cperc*100, T);
         }

         doc.rulerOrigin = [0,0];
         doc.rulerOrigin = origin;
}
if (app.documents.length) test();
// -------
function centre(Bounds)
{return [Bounds[0]+(Bounds[2]-Bounds[0])/2,Bounds[3]+(Bounds[1]-Bounds[3])/2];}
// -------

René

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
Enthusiast ,
Dec 02, 2025 Dec 02, 2025

Thanks! Setting the ruler origin did not change the results.

To answer your question. The purpose of the function is to resize all selected art, to the width of a specific path. It has been helpful resize based on dielines maintain layering, and not have to clip everything into one group.

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
Community Expert ,
Dec 03, 2025 Dec 03, 2025

Sergey Osokin generously provides a script called "Resize to Size". You may give it a try.

 

Resize to Size

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
Enthusiast ,
Dec 03, 2025 Dec 03, 2025
LATEST

Tried it, works quite well. This assumes the items in the selection are grouped. What I'm proposing, is sizing all of a selection, paths etc, based on a specific shape. Determining a percentage for all based on a single path.

 

I really like what was done with the radio buttons and alignment. I tried to make a small selection like that before and kept getting text overlap.

 

Thanks for sharing!

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