Copy link to clipboard
Copied
I am trying to write simple script that reduces hight of selection (single object or many objects on different layers) by fixed parameter. In my case 6mm. The problem is that in result redictionis 2.117mm instead of expected 6mm. Do you have any clue why and how the proper code wshould look like?
var doc = app.activeDocument;
var sel = doc.selection;
for(var i = 0; i < sel.length; i++){
sel[i].height = sel[i].height - 6;
}
Hi @irek289170064v73, scripts use points for measurements by default. So you can do it like this:
var mm = 2.834645;
var doc = app.activeDocument;
var sel = doc.selection;
for (var i = 0; i < sel.length; i++) {
sel[i].height = sel[i].height - 6 * mm;
}
There are other ways, but I find this very simple and I prefer it in almost all cases.
- Mark
Perhaps you can use the ResiteToSize script for this and other tasks to change the absolute or relative size https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#resizetosize
Copy link to clipboard
Copied
Hi @irek289170064v73, scripts use points for measurements by default. So you can do it like this:
var mm = 2.834645;
var doc = app.activeDocument;
var sel = doc.selection;
for (var i = 0; i < sel.length; i++) {
sel[i].height = sel[i].height - 6 * mm;
}
There are other ways, but I find this very simple and I prefer it in almost all cases.
- Mark
Copy link to clipboard
Copied
I have been trying for 2 days to get GPT chat to help me, and despite my efforts, we couldn't. On the forum I got help in a few minutes. However, people are irreplaceable.
Thank you!
Copy link to clipboard
Copied
Perhaps you can use the ResiteToSize script for this and other tasks to change the absolute or relative size https://github.com/creold/illustrator-scripts/blob/master/md/Item.md#resizetosize
Copy link to clipboard
Copied
Thnak you. I am just trying to automet hight reduction dependin on the file name I work on. But it doesn't work properly.
Basing on the latest response my code is as below but. Transformation is not correct and it is not centered.
For me inportant is also that reduction should base on selection and its bounding box size, so the masked elements or pictures would have no influance on transformation.
var fileName = app.activeDocument.name;
var reduction = 0;
if (fileName.indexOf("1.14") !== -1 || fileName.indexOf("1,14") !== -1) {
reduction = 6;
} else if (fileName.indexOf("1.7") !== -1 || fileName.indexOf("1,7") !== -1) {
reduction = 10.2;
}
var mm = 2.834645;
var doc = app.activeDocument;
var sel = doc.selection;
for (var i = 0; i < sel.length; i++) {
var item = sel[i];
var bounds = item.geometricBounds;
var height = bounds[3] - bounds[1];
var newHeight = height - reduction;
var centerX = (bounds[0] + bounds[2])/2;
var centerY = (bounds[1] + bounds[3])/2 - reduction * mm / 2;
item.resize(100, (newHeight/height)*100, true, true, true, true);
item.position = [centerX, centerY];
}
Copy link to clipboard
Copied
You forgot to convert the newHeight variable to mm.
Transformation is not correct and it is not centered....reduction should base on selection and its bounding box size, so the masked elements or pictures would have no influance on transformation.
This is wrong. geometricBounds is defined incorrectly for the clipping group. So the transformation is not from the center of the mask shape, but from the center of all elements in the clipping group.
var doc = app.activeDocument;
var fileName = doc.name;
var sel = doc.selection;
var reduction = 0;
if (/1(,|\.)14/.test(fileName)) {
reduction = 6;
} else if (/1(,|\.)7/.test(fileName)) {
reduction = 10.2;
}
for (var i = 0; i < sel.length; i++) {
var item = sel[i];
var bounds = item.geometricBounds;
var height = bounds[3] - bounds[1];
var newHeight = height - mm2pt(reduction);
var coeff = (newHeight / height) * 100;
item.resize(100, coeff, true, true, true, true, 100, Transformation.CENTER);
}
// Convert mm to pt
function mm2pt(n) {
return n * 2.83464567;
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now