Skip to main content
Inspiring
January 7, 2018
Question

How to make key object via jsx to perform "Align to Key Object"

  • January 7, 2018
  • 3 replies
  • 2189 views

Hi, Is there any way to make the object as a key object via script to perform "Align to key Object" in Illustrator. I need it urgently. Thanks in advance

This topic has been closed for replies.

3 replies

renél80416020
Inspiring
December 22, 2018

Salut !

Pour une sélection d'objets, alignement (left) sur un objet clé

// JavaScript Document for Illustrator

function test() {

  var docRef = app.activeDocument;

    if (!selection.length) return;

    var sel = selection;

    var  currObj, VBounds, pointText, dec = 15, rep;

    var groupText = docRef.groupItems.add();

    for(var i = 0; i < selection.length; i++) {

      currObj =selection;

      VBounds =currObj.visibleBounds;

      pointText = groupText.textFrames.pointText([(VBounds[0]+VBounds[2])/2,VBounds[3]-dec]);

      pointText.contents = i;

      pointText.paragraphs[0].justification = Justification.CENTER

    }

    redraw();

    rep = prompt("N° de l'objet clé",0);

    sortVertically(sel,rep);

      function sortVertically(items,rg) {

          for(var n = 0; n < items.length; n++) {

            if (n != rg) items.left = items[rg].left;

          }

      }

    groupText.remove();

}

if (app.documents.length) {test();}

de elleere

PS si plus de demande, me contacter par Mail

rcraighead
Legend
December 23, 2018

Je vous remercie! Ça marche. J'adore la fonction de numérotation.

Thank you, ALL, for the help.

Inspiring
January 9, 2018

Is der any way you can help out with writing script where we do not want to change position of one object. We can do this using position and coordinates

CarlosCanto
Community Expert
Community Expert
January 9, 2018

can you change stacking order? for example, you can designate your key object to be the top most object in a selection

Disposition_Dev
Legend
December 21, 2018

Carlos, can you expound on this? I'd like to make the bottom selected object the "Key Object" for alignment. How can I do that?


manually.

if you have an array of objects you'd like to align, you can get the last item in the array, then update the position of each remaining item in the list to match your desired alignment preferences.

var array = [items,to,be,aligned];

var bottomObject = array[array.length-1];

for(each item you want to align)

{

     item.position = [enter new, coordinates];

}

CarlosCanto
Community Expert
Community Expert
January 7, 2018

no, not possible sorry.