Does this do what you want?
// instructions: select path items
var space = 0.022 * 72; // minimum space between paths (inches)
var doc = app.activeDocument;
var paths = doc.pathItems;
// step 1: push selected paths into array to sort left to right
var array = [];
for (var i = 0; i < app.selection.length; i++) {
array.push(app.selection[i]);
}
array.sort(function (a, b) {return a.left - b.left});
// step 2: move paths into group
var group = doc.groupItems.add();
for (var i = 0; i < array.length; i++) {
// save path's name
var tag1 = array[i].tags.add();
tag1.name = "tag1";
tag1.value = array[i].name;
// rename path according to left to right order
array[i].name = "x" + i;
array[i].move(group, ElementPlacement.PLACEATBEGINNING);
}
// step 3: move paths out of group from left to right, & ,
// if distance between path-before-group & group < "space",
// translate group distance of "space" from path-before-group
for (var i = group.pathItems.length - 1, j = 0; i > -1; i--, j++) {
group.pathItems[i].move(group.parent, ElementPlacement.PLACEATEND);
if (group.left - (paths["x" + j].left + paths["x" + j].width) < space) {
group.left = paths["x" + j].left + paths["x" + j].width + space;
}
// rename path according to original name
paths["x" + j].name = paths["x" + j].tags["tag1"].value;
}
Bonjour à tous,
femkeblanco, il me semble pour reprendre ton idée...
// instructions: select path items
var space = .022 * 72; // minimum space between paths (inches)
function alignObj0(tabs,space) {
var esp;
tabs.sort(function (a, b) {return a.left - b.left});
for (var i = 1; i < tabs.length; i++) {
esp = tabs[i].left-tabs[i-1].left-tabs[i-1].width; // alert(esp);
if (esp < space) {
for (var j = i; j < tabs.length; j++) {
tabs[j].left += space-esp;
}
}
}
}
if (selection.length) {alignObj0(selection,space);}
René