Skip to main content
Known Participant
February 22, 2024
Question

Scaling objects along a direction

  • February 22, 2024
  • 1 reply
  • 433 views

I am looking to achieve this result with a group or many items. The scaling should happen along a direction and if possible radial too. The objects can be randomly arranged too. I need the scaling to follow from high to low.

 

This topic has been closed for replies.

1 reply

renél80416020
Inspiring
February 22, 2024

Bonjour,

Essayez cela.

 

// JavaScript Document for illustrator
// reduire via direction
// Auteur Landry René
 function main() {
  var item, pathes = [];
      extractPathes(selection,pathes);
        if (pathes.length == 0) {
          alert("Une sélection est obligatoire ?");
          return;
        }
  var pos = [];
      for (var h = 0; h < pathes.length; h++) {
        item = pathes[h];
          pos.push([item.top-item.height/2,pathes[h]])
        }
      pos.sort(function (a, b) { return a[0]-b[0]} )
  var nbr = 0;
  var top0 = pos[0][0];
        do {
           nbr++;
        } 
        while (pos[nbr][0] > top0-5 && pos[nbr][0]< top0+5)
                 
  var nbl = pos.length/nbr;
  var ecart = 100/(nbl+1);
      //alert( pos.join("\r"))         
  var r = 100-ecart; 
  var top0 = pos[nbr-1][0];
  
        for(var h = nbr, c = 0; h < pos.length; h++) {
            top = pos[h][0];
              if (pos[h][0] > top0+5) {
                  pos[h][1].resize(r,r);
                  c++;
              }
             if (c == nbr) {top0 = pos[h][0]; r -= ecart; c = 0;}   
        }
}       
main();
// --------
function extractPathes(s, tabs){
  for(var i = 0; i < s.length; i++){
    if(s[i].typename == "PathItem" && !s[i].guides && !s[i].clipping){
      tabs.push(s[i]);
    } else if(s[i].typename == "GroupItem"){
      // Cherche les objets de types pageItems dans ce groupe, recursivement
      extractPathes(s[i].pageItems, tabs);
    } else if(s[i].typename == "CompoundPathItem"){
      // Cherche les objets de type PathItem dans ce trace transparent, recursivement
      extractPathes(s[i].pathItems, tabs);
    }
  }
}
// --------

 

 

Kurt Gold
Community Expert
Community Expert
February 22, 2024

That works very well, René.

 

Thanks for sharing.