Copy link to clipboard
Copied
I'm looking for an example script that can resize a selected object based on a certain boundary (e.g. the top boundary). As I understand, there is a built-in function to set the scale, but it is not the same. Here is an example of the transformation I'm looking for.
And of course, the object can be a clipping mask containing objects that are larger in size than the selected "external" object.
Since you are not telling me exactly what you want, I have to follow along... Now it seems like you want to *scale* the whole group? If so, use the PageItem.resize method. Calculate the scale by dividing the new clipping mask height with the old and scale the GroupItem.
- Mark
Copy link to clipboard
Copied
Hi @andyf65867865, this can get to be a complex topic, depending on many factors. But for what you describe, this is enough:
item.height = 95;
- Mark
Copy link to clipboard
Copied
Hi @m1b This seems to work for simple objects, but not for masks.
Copy link to clipboard
Copied
It works the same for clipping masks but you have to be targeting the clipping mask, not the clipping group. A clipping group contains a path item that has a `clipping` propertyāthat is the one to target.
Or if you mean opacity mask then I dont know how to scale those because the scripting API does not provide much access, if any.
Copy link to clipboard
Copied
By @m1bA clipping group contains a path item that has a `clipping` propertyāthat is the one to target.
Are you referring to what is called <Clipping Path> inside <Clip Group>?
Copy link to clipboard
Copied
@andyf65867865, this would be a better way to explain it:
(function () {
var doc = app.activeDocument,
item = doc.selection[0];
if (item.clipped) {
// item is a clipping group
for (var i = 0; i < item.pathItems.length; i++) {
var child = item.pathItems[i];
if (child.clipping) {
// set height of the clipping mask path item
child.height = 95;
}
}
}
})();
Copy link to clipboard
Copied
it seems this is not the option, look for example
on the left a group with clipping mask (yelow item inside) - appliying the script do not affect the whole item (group)
on the right - a pure clipping mask (i.e. Clip Group) and in this case the script only affects the Clipping Path itself but not the content
Copy link to clipboard
Copied
Since you are not telling me exactly what you want, I have to follow along... Now it seems like you want to *scale* the whole group? If so, use the PageItem.resize method. Calculate the scale by dividing the new clipping mask height with the old and scale the GroupItem.
- Mark
Copy link to clipboard
Copied
@m1b it seems this works, but the item changes its position even though the transformation point specified
obviously, it calculates the "top" point relatively of clipping mask contents, but I think it's solvable. Thanks.
(function() {
var doc = app.activeDocument,
item = doc.selection[0];
item.resize(100, 90, true, false, false, false, 100,
Transformation.TOP);
})();
Find more inspiration, events, and resources on the new Adobe Community
Explore Now