• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Adjust spacing without adjusting other spacing

Engaged ,
Nov 14, 2022 Nov 14, 2022

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".

BryanPagenkopf_0-1668461261190.png

 




Thank you!

TOPICS
Scripting

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Nov 16, 2022 Nov 16, 2022

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 
...

Votes

Translate

Translate
Adobe
Guide ,
Nov 14, 2022 Nov 14, 2022

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;
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 14, 2022 Nov 14, 2022

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

align_space_between_00.png

 

click = select the base object

align_space_between_01.png

 

insert the value (if not already done) and

click = align

align_space_between_02.png

 

 

Done.

align_space_between_03.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 15, 2022 Nov 15, 2022

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 15, 2022 Nov 15, 2022

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;
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 16, 2022 Nov 16, 2022

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é

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 16, 2022 Nov 16, 2022

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) {

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 16, 2022 Nov 16, 2022

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 16, 2022 Nov 16, 2022

Copy link to clipboard

Copied

Both Options seem to work, however, I do have 2 edge cases that are generating more space than would be needed.
1. Where the Circle Meets the Star
2. The 3 Rhombus shapes
 

BryanPagenkopf_0-1668613125169.png


Thank you Again!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 16, 2022 Nov 16, 2022

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.

Capture.PNG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 16, 2022 Nov 16, 2022

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!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 16, 2022 Nov 16, 2022

Copy link to clipboard

Copied

LATEST

Oui c'est possible.

je pense modifier la ligne

if (esp < space)

en

if (esp < space && esp >= 0)

non testé.

René

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines