Copy link to clipboard
Copied
How can I, with a Script, automatically adjust only the spacing between the grouped squares where the space is less than .022" space between them?
Top Line is the Sample art.
Loop 1 - Focus on the spacing between Shape 1 and 2 is fine so no adjustment is needed.
Loop 2 - Focus on the spacing between Shape 2 and 3 is adjusted to 0.022"
Loop 3 - Focus on the spacing between Shape 3 and 4 is fine so no adjustment is needed.
Loop 4 - Focus on the spacing between Shape 4 and 5 is adjusted to 0.022".
Thank you!
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
...
Copy link to clipboard
Copied
Edit: The preceding code was unnecessarily complicated.
// instructions: select path items to space out
var space = 0.022 * 72; // desired space between paths (inches)
var doc = app.activeDocument;
var paths = doc.pathItems;
// step 1: push the selected paths into an 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: translate the path the distance of "space" from the path before
for (var i = 1; i < array.length; i++) {
array[i].left = array[i - 1].left + array[i - 1].width + space;
}
Copy link to clipboard
Copied
Do you really need a script for this?
Do you have a very large number of files in which you need to match spacing in this way? Or do you just want to know the script syntax?
After all, the existing drag-click-click function is fast and good. Or is it not?
drag = select the items
click = select the base object
insert the value (if not already done) and
click = align
Done.
Copy link to clipboard
Copied
I'm sorry, I don't think I'm explaining myself properly. I'm not looking to have the shapes spaced equally distant.
I need the spacing to remain exactly the same unless that space is less than .022". So if the spacing between shapes is .075" , .015" , 1" .006" I need the spacing to change to .075" , .022" , 1" .022".
I hope that clarifies things.
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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é
Copy link to clipboard
Copied
@femkeblanco Good Morning Thanks for the assist! I am getting a "No Such Element" error when I run the script on this line
if (group.left - (paths["x" + j].left + paths["x" + j].width) < space) {
Copy link to clipboard
Copied
Selected items have to be path items (and not, for example, group items). Rene's script may work for other page items.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Les scripts proposés se basent sur les rectangles d'encombrement des objets sélectionnés.
Il est donc normal que le résultat soit différent de ce que vous souhaitez (désolé).
Vous en demandez beaucoup, cela me semble assez difficile à résoudre.
Copy link to clipboard
Copied
@renél80416020 The scripts you and @femkeblanco wrote solve about 95% of the situations I come across. Currently, the Scripts preserve the spacing if that spacing is equal to or greater than 0.022".
Would it be possible to add a way to preserve the spacing if shape space overlaps?
If possible Great! If not the help you two have given has been wonderful!!
Copy link to clipboard
Copied
Oui c'est possible.
je pense modifier la ligne
if (esp < space)
en
if (esp < space && esp >= 0)
non testé.
René