Copy link to clipboard
Copied
I am looking for a script to resize selected clipped groups (usually 3) to a specific dimension, 50X70 cm
I don't care for keeping the selected groups dimensions ratio
Can anybody help ?
(function() {
var w = 500; // Width, mm
var h = 700; // Height, mm
var pos = null;
for (var i = 0, len = selection.length; i < len; i++) {
var s = selection[i];
var m = null;
if (s.typename === 'GroupItem' && s.clipped) {
m = getMask(s.pageItems);
} else {
m = s;
}
// Get scale ration and resize
var rX = 100 * mm2px(w) / m.width;
var rY = 100 * mm2px(h) / m.height;
s.resize(
rX, // X
rY, // Y
true, // Change Positions
...
Copy link to clipboard
Copied
(function() {
var w = 500; // Width, mm
var h = 700; // Height, mm
var pos = null;
for (var i = 0, len = selection.length; i < len; i++) {
var s = selection[i];
var m = null;
if (s.typename === 'GroupItem' && s.clipped) {
m = getMask(s.pageItems);
} else {
m = s;
}
// Get scale ration and resize
var rX = 100 * mm2px(w) / m.width;
var rY = 100 * mm2px(h) / m.height;
s.resize(
rX, // X
rY, // Y
true, // Change Positions
true, // Change Fill Patterns
true, // Change Fill Gradients
true, // Change Stroke Pattern
100, // Stroke scale %
);
// Horizontal stack order from first selected object
if (i == 0) {
pos = m.position;
} else {
s.translate(pos[0] - m.position[0] + m.width, pos[1] - m.position[1]);
pos = m.position;
}
}
function getMask(arr) {
for (var i = 0, len = arr.length; i < len; i++) {
var p = arr[i];
if (p.typename === 'PathItem' && p.clipping) {
return p;
} else if (p.typename === 'CompoundPathItem' && p.pathItems.length && p.pathItems[0].clipping) {
return p;
}
}
}
function mm2px(n) {
return n * 2.83464567;
}
})();
Copy link to clipboard
Copied
Perfect!
Thank you, @Sergey Osokin
It is possible to distribute resized clip groups one next to the other ?
Copy link to clipboard
Copied
If I understand correctly, you need to make a stacked order? I updated the script code in a previous post.
Copy link to clipboard
Copied
Yes, this is what I was looking for, many thanks I leaned a lot about clipped groups!