Skip to main content
This topic has been closed for replies.
Correct answer renél80416020

Bonjour,

/*Duplicates each element of the group placed in the foreground
to center them on selected points within paths or isolated points.
Duplicates each element of the group placed in the foreground on each of the selected points*/

// JavaScript Document
/* Duplique chaque élément du groupe placé au premier plan
   pour les centrer sur les points sélectionnés appartenant à des tracés ou des points isolés.*/
function main(){
  var doc = activeDocument;
  var s = selection;
    if (s.length < 2) return;
  var gr = s[0]; // Groupe premier plan
      if (gr.typename != "GroupItem") return;
  var nbObj = gr.pageItems.length,
      paths = [];
      extractPathes(s.slice(1), paths, 0);
  var pts, tgt_point, vb;

    for(var i = 0, k = 0; i < paths.length; i++){
      pts = paths[i].pathPoints;
        for(var j = 0; j < pts.length; j++) {
          if(isSelected(pts[j])) {
            if (nbObj == k) break;
              tgt_item = gr.pageItems[k];
              vb = tgt_item.visibleBounds;
              tgt_point = [(vb[0]+vb[2])/2,(vb[1]+vb[3])/2];
              tgt_item.duplicate(paths[i],ElementPlacement.PLACEBEFORE).translate(
                  pts[j].anchor[0]-tgt_point[0],
                  pts[j].anchor[1]-tgt_point[1]);
              k++;
            }
        }
    }
}
// -------
function isSelected(pt){return pt.selected == PathPointSelection.ANCHORPOINT;}
// -------
function extractPathes(s,tabs,deb){
  for (var i = 0; i < s.length; i++){
    if(s[i].typename == "PathItem" && !s[i].guides && !s[i].clipping && i >= deb){
      tabs.push(s[i]);
    } else if(s[i].typename == "GroupItem"  && i >= deb){
      // Cherche les objets pageItems dans ce groupe, récursivement
      extractPathes(s[i].pageItems,tabs,0);
    } else if(s[i].typename == "CompoundPathItem" && i >= deb){
      // Cherche les objets de type PathItem dans ce tracé transparent, récursivement
      extractPathes(s[i].pathItems,tabs,0);
    }
  }
}
// -------
if (app.documents.length > 0) main();

René

4 replies

renél80416020
renél80416020Correct answer
Inspiring
November 11, 2022

Bonjour,

/*Duplicates each element of the group placed in the foreground
to center them on selected points within paths or isolated points.
Duplicates each element of the group placed in the foreground on each of the selected points*/

// JavaScript Document
/* Duplique chaque élément du groupe placé au premier plan
   pour les centrer sur les points sélectionnés appartenant à des tracés ou des points isolés.*/
function main(){
  var doc = activeDocument;
  var s = selection;
    if (s.length < 2) return;
  var gr = s[0]; // Groupe premier plan
      if (gr.typename != "GroupItem") return;
  var nbObj = gr.pageItems.length,
      paths = [];
      extractPathes(s.slice(1), paths, 0);
  var pts, tgt_point, vb;

    for(var i = 0, k = 0; i < paths.length; i++){
      pts = paths[i].pathPoints;
        for(var j = 0; j < pts.length; j++) {
          if(isSelected(pts[j])) {
            if (nbObj == k) break;
              tgt_item = gr.pageItems[k];
              vb = tgt_item.visibleBounds;
              tgt_point = [(vb[0]+vb[2])/2,(vb[1]+vb[3])/2];
              tgt_item.duplicate(paths[i],ElementPlacement.PLACEBEFORE).translate(
                  pts[j].anchor[0]-tgt_point[0],
                  pts[j].anchor[1]-tgt_point[1]);
              k++;
            }
        }
    }
}
// -------
function isSelected(pt){return pt.selected == PathPointSelection.ANCHORPOINT;}
// -------
function extractPathes(s,tabs,deb){
  for (var i = 0; i < s.length; i++){
    if(s[i].typename == "PathItem" && !s[i].guides && !s[i].clipping && i >= deb){
      tabs.push(s[i]);
    } else if(s[i].typename == "GroupItem"  && i >= deb){
      // Cherche les objets pageItems dans ce groupe, récursivement
      extractPathes(s[i].pageItems,tabs,0);
    } else if(s[i].typename == "CompoundPathItem" && i >= deb){
      // Cherche les objets de type PathItem dans ce tracé transparent, récursivement
      extractPathes(s[i].pathItems,tabs,0);
    }
  }
}
// -------
if (app.documents.length > 0) main();

René

siomospAuthor
Inspiring
November 12, 2022

Hello @femkeblanco, thank you for the script, it's working great !!!!

Thanks a lot!

femkeblanco
Legend
November 12, 2022

I'm happy to take the credit, but it was @renél80416020's script. 

femkeblanco
Legend
November 10, 2022

Another unclear thing is whether the OP really means to move "paths" and not textframe characters. 

siomospAuthor
Inspiring
November 12, 2022

Hi, the path is outlined text, not textframe characters.
Thank you!

Sergey Osokin
Inspiring
November 10, 2022

If you draw single points as markers for object positions, the script is easier to write. 

Another script variant is to draw a path with anchor points, place it at the bottom or at the top of the selection, and place the other objects along the points of this key path. 

femkeblanco
Legend
November 10, 2022

It should be possible.  Are the crosses in the middle of the banners points or paths?  Can you show the fully expanded layers panel?  

siomospAuthor
Inspiring
November 12, 2022

Hello!

The crosses are paths