Copy link to clipboard
Copied
Hi! Can someone help me? I want to sort objects on airboard from bottom to top by rounded Y for simplify sorting process. Rounding will create virtual rows (different color on pic below) highest value goes first (Top object in the layer list). Then each row I want to sort by X, from right to the left (so high value goes first - revers order)
Here is example
Result of arranging objects in the layer should be (from top to down): 1,2,3,4,5,6 and etc
This is like sorting 2 dimensional array in revers order:
X,Y array
myobjlist= [[124,2],[23,2],[60,1],[150,1],[12,2],[20,0],[50,1],[40,0],[70,0]]
sorted(myobjlist)
will create next array
[[124, 2] [23, 2] [12, 2] [150, 1] [60, 1] [50, 1] [70, 0] [40, 0] [20, 0]]
Object with [124, 2]
coordinates will be first in layers list and
[20, 0] -
last
Example script that doing this but with some mistakes
// JavaScript Document for Illustrator
var dec = 20;
if (app.documents.length > 0) {
var docRef = app.activeDocument;
var selectedItems = selection;
var nbObjSelect = selectedItems.length;
if (nbObjSelect) {
var rep, iObj, newtop;
var TabTop = [];
rep = prompt("Tolérance ?", dec);
dec= rep*1;
for (var i = 0; i < nbObjSelect; i++) {
iObj = selectedItems;
TabTop.push([iObj.top,i])
}
TabTop.sort();
TabTop.reverse(); //alert(TabTop.join("\r"));
newtop = TabTop[0][0];
docRef.layers.add();
nbLayers = docRef.layers.length;
for(i = 0, k = nbLayers-1; i < nbObjSelect; i++) {
if (newtop > TabTop[0]-dec && newtop < TabTop[0]+dec) {
iObj = selectedItems[TabTop[1]];
iObj.move(docRef.layers[0],ElementPlacement.PLACEATEND);
docRef.layers[0].name = "Rang "+k;
}
else {
newtop = TabTop[0]; k++; i--;
docRef.layers.add();
}
}
var layerAct, nbObjLayer, n, nObj, j, jObj;
var TabLeft = [];
for(i = 0; i < k; i++) {
layerAct = docRef.layers;
nbObjLayer = layerAct.pageItems.length;
for(n = 0; n < nbObjLayer; n++) {
nObj = layerAct.pageItems
; TabLeft.push([nObj.left,nObj]);
}
TabLeft.sort(); //TabLeft.revers(); alert(TabLeft.join("\r"));
for(j = 0; j < nbObjLayer; j++) {
jObj = TabLeft
[1]; jObj.zOrder(ZOrderMethod.SENDTOBACK);
}
TabLeft = [];
}
}
else alert("Vous n'avez rien sélectionné !","De Elleere");
}
else alert("Pour l'exécution de ce sript un document doit être ouvert !","Script Alerte de Elleere !");
Thanks to renél80416020
Tolerance value is fine. But there is some problems:
see pic below
Bonjour Dever
J'ai essayé toutes les adresses mail que tu m'as transmises sans résultat.
Mon adresse est sous ma photo.
Dans le script, c'est juste la fonction sort() qui n'est pas adaptée.
René
Copy link to clipboard
Copied
Bonjour Dever
J'ai essayé toutes les adresses mail que tu m'as transmises sans résultat.
Mon adresse est sous ma photo.
Dans le script, c'est juste la fonction sort() qui n'est pas adaptée.
René
Copy link to clipboard
Copied
I have modified it little and it works! Thank you
Copy link to clipboard
Copied
Bonjour renél80416020
If I have other layer in document script freezes (Ai crushes)
I have added "put back to original Layer" function and removing all Rang layers
How to fix it to work only with selected layer in the document?
// JavaScript Document for Illustrator
// tab Top.js
// contitution de lignes du bas vers le haut et trie par ligne de la droite vers la gauche
var dec = 30; // Tolérance de position (top) pour appartenir à une ligne
var ognlayerName;
if (app.documents.length > 0) {
var docRef = app.activeDocument;
ognlayerName = new String(docRef.activeLayer.name);
//alert(ognlayerName);
var selectedItems = selection;
var nbObjSelect = selectedItems.length;
if (nbObjSelect) {
var rep, iObj, newtop;
var TabTop = [];
rep = prompt("Tolerance?", dec);
dec = rep * 1;
for (var i = 0; i < nbObjSelect; i++) {
iObj = selectedItems;
TabTop.push([iObj.top, i])
}
bsort(TabTop, 0, TabTop.length - 1);
//alert(TabTop.join("\r"));
TabTop.reverse();
//alert(TabTop.join("\r"));
newtop = TabTop[0][0];
docRef.layers.add();
nbLayers = docRef.layers.length;
for (i = 0, k = nbLayers - 1; i < nbObjSelect; i++) {
if (newtop > TabTop[0] - dec && newtop < TabTop[0] + dec) {
iObj = selectedItems[TabTop[1]];
iObj.move(docRef.layers[0], ElementPlacement.PLACEATEND);
docRef.layers[0].name = "Rang " + k;
} else {
newtop = TabTop[0];
k++;
i--;
docRef.layers.add();
}
}
var layerAct, nbObjLayer, n, nObj, j, jObj;
var TabLeft = [];
for (i = 0; i < k; i++) {
layerAct = docRef.layers;
nbObjLayer = layerAct.pageItems.length;
for (n = 0; n < nbObjLayer; n++) {
nObj = layerAct.pageItems
; TabLeft.push([nObj.left, nObj]);
}
bsort(TabLeft, 0, TabLeft.length - 1); //alert(TabLeft.join("\r"));
for (j = 0; j < nbObjLayer; j++) {
jObj = TabLeft
[1]; jObj.zOrder(ZOrderMethod.BRINGTOFRONT);
}
TabLeft = [];
}
count = 0;
if (docRef.pathItems.length > 0) {
thePaths = docRef.pathItems;
numPaths = thePaths.length;
for (i = 0; i < docRef.pathItems.length; i++) {
pathArt = docRef.pathItems;
if (pathArt.parent.typename != "CompoundPathItem") {
pathArt.selected = true;
count++;
}
}
}
//DESCRIPTION: move sorted to original layer
var docSelected = app.activeDocument.selection;
var topLayer = app.activeDocument.layers[ognlayerName];
//alert(topLayer);
//var topLayer = app.activeDocument.layers.add();
//topLayer.name = "Sorted Bleed";
for (s = 0; s < docSelected.length; s++) {
myPath = docSelected
;myPath.move(topLayer, ElementPlacement.PLACEATEND);
}
//DESCRIPTION: remove sorted Rang layers
var layersDeleted = 0;
var targetDocument = app.activeDocument;
var layerCount = targetDocument.layers.length;
// Loop through layers from the back, to preserve index
// of remaining layers when we remove one
for (var ii = layerCount - 1; ii >= 0; ii--) {
targetLayer = targetDocument.layers[ii];
var layerName = new String(targetLayer.name);
if (layerName.indexOf("Rang") == 0) {
targetDocument.layers[ii].remove();
layersDeleted++;
}
}
} else alert("You have not selected anything!", "Warning");
} else alert("For execution of this script a document must be opened! ", " Script Alert!");
//------
function bsort(Tab, debut, fin) { // sort an ascending order array from start to end
var i, k, buffer;
for (i = fin; i != 0; i--) {
for (k = debut; k < i; k++) {
if (Tab
[0] > Tab[k + 1][0]) { buffer = Tab
; Tab
= Tab[k + 1]; Tab[k + 1] = buffer;
}
}
}
}
//-------------------------------------------------------------
thanks in advance
Copy link to clipboard
Copied
Bonjour Dever,
J'aimerais connaître le processus de création des tracés et comment les tracés classés sont exploitée par la suite ?
cela peu aider pour trouver des solutions pour des cas plus complexes.
Bien ton script fonctionne, je donne ma version...
de René landry
elleere
PS essai de me joindre par mail.
Copy link to clipboard
Copied
your version works, but with two layers in document it will stuck.
PS
PM me your email PLEASE. I'm not seeing any contact information in your profile
Thanks in advance!
Copy link to clipboard
Copied
Bonjour dever,
Oui effectivement, je m'étais basé que sur ton exemple
Il te suffit de modifier la ligne 30 k =1 cela devrait te convenir.
for(i = 0, k = 1; i < nbObjSelect; i++) {
Pour l'adresse mail (passe le cuseur de la souris sur le portrait (René Landry)
Cordialement René
Copy link to clipboard
Copied
Bonjour, Rene
thanks, now works
PS
Only you are seeing detail info in your profile page
Copy link to clipboard
Copied
Bonjour Dever,
Moi j'ai çà ?
Copy link to clipboard
Copied
Dever schrieb
Only you are seeing detail info in your profile page
Dever is absolutly right.
This depends on your own privacy settings in your fora profile.
Standard setting is: only you see this private info.
Real name: only you can see
Email address: only you can see
For changing:
Click on the little arrow right beside your avatar (at the top on this page, near: search).
Choose: edit profile
Choose: the third register (privacy)
There are your privacy settings.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now