Skip to main content
StefanStehlik
Inspiring
Jan 28, 2023 8:50 PM UTC
Answered

Select clipping mask path (with script)

I want to select an object with a clipping mask with the selection tools (V). Then run the script that can select only the mask path, so that I can modify it. Then when I run the script again the selection is back to the previous state. How to write a script that does this. I would appreciate your help.

This topic is closed to new replies. Start a new post to keep the conversation going.
Kurt Gold
Kurt GoldCorrect answer
Community Expert
Jan 30, 2023 12:48 PM UTC

In case there is an urgent reason to first select the clipping group with the Selection tool (V), you may also just select and then isolate and edit it (by clicking the Isolate Mask button in the Properties panel, by right clicking on the clipping group and choosing the Isolate Selected Mask command, or by assigning and using a keyboard shortcut to enter Isolation mode (see Edit menu > Keyboard Shortcuts > Menu Commands > Other Object > Isolate Selected Object)).

 

I don't see a reason why a script would be necessary or more beneficial in that case.

 

5 replies

Kurt Gold
Community Expert
Kurt GoldCommunity ExpertCorrect answer
Community Expert
Jan 30, 2023 12:48 PM UTC

In case there is an urgent reason to first select the clipping group with the Selection tool (V), you may also just select and then isolate and edit it (by clicking the Isolate Mask button in the Properties panel, by right clicking on the clipping group and choosing the Isolate Selected Mask command, or by assigning and using a keyboard shortcut to enter Isolation mode (see Edit menu > Keyboard Shortcuts > Menu Commands > Other Object > Isolate Selected Object)).

 

I don't see a reason why a script would be necessary or more beneficial in that case.

 

Translate
femkeblanco
Legend
Jan 28, 2023 11:03 PM UTC
var target = app.selection[0];
if (target.typename == "PathItem" && 
    target.clipping == true) {
    exit(target)
    function exit(target) {
        if (target.parent.typename != "Layer") {
            exit(target.parent)
        } else {
            target.selected = true;
        }
    }
} else {
    var clippingPath;
    var items = target.pageItems;
    enter(items);
    if (clippingPath) {
        app.selection = null;
        clippingPath.selected = true;
    }
    function enter(items) {
        for (var i = items.length - 1; i > -1; i--) {
            if (items[i].typename == "GroupItem" ||
                items[i].typename == "CompoundPathItem") {
                enter(items[i].pageItems);
            } else if (items[i].typename == "PathItem" && 
                items[i].clipping == true) {
                clippingPath = items[i];
            }
        }
    }
}

(If there are >1 clipping mask in the selected item, the topmost clipping path will be selected.)

Translate
Kurt Gold
Community Expert
Community Expert
Jan 28, 2023 9:37 PM UTC

Do you really need a script to do that?

 

Wouldn't it be easier to assign a keyboard shortcut to the Object menu > Clipping Mask > Edit Mask command and just use this route?

 

Or directly selecting the clipping path with the Direct Selection tool or the Group Selection tool?

 

Translate
StefanStehlik
Inspiring
Jan 28, 2023 10:32 PM UTC

Hey when using the Edit Mask command, the objects inside the mask are selected, not the mask path. I would like to select the mask path and edit it with one keyboard shortcut.

Translate
Ton Frederiks
Community Expert
Community Expert
Jan 28, 2023 10:45 PM UTC

If you select the object with the clipping mask, you already select the mask.

All you need to do is switch to the Direct Selection tool (A) and click an anchor point to edit the mask.

Translate