Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Resize item that works like transform tool

Engaged ,
Oct 23, 2024 Oct 23, 2024

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.

 

Screenshot_1.png

TOPICS
Scripting
759
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 23, 2024 Oct 23, 2024

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

Translate
Adobe
Community Expert ,
Oct 23, 2024 Oct 23, 2024

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 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 23, 2024 Oct 23, 2024

Hi @m1b This seems to work for simple objects, but not for masks. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2024 Oct 23, 2024

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 23, 2024 Oct 23, 2024
quoteA clipping group contains a path item that has a `clipping` property—that is the one to target.
By @m1b

Are you referring to what is called <Clipping Path> inside <Clip Group>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2024 Oct 23, 2024

@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;
                
            }

        }

    }

})();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 23, 2024 Oct 23, 2024

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


Screenshot_2.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2024 Oct 23, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 23, 2024 Oct 23, 2024
LATEST

@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);
})();

 

 

 

 

 

 

 

 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines