Answered
Move paths to anchor points
Hi,
I want to move each one of selected paths to anchor points
From this

To this

It is possible via script?
This old script duplicates one selection to all anchors, I need something similar
Hi,
I want to move each one of selected paths to anchor points
From this

To this

It is possible via script?
This old script duplicates one selection to all anchors, I need something similar
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é

Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.