Skip to main content
Participant
January 3, 2024
Question

Eliminating an element by spot color name

  • January 3, 2024
  • 1 reply
  • 239 views

Does anyone have a script that would locate an object by Spot Color name and delete it? Specifically, we have a customer that places a "Live" area box that I always have to delete. I would like to simply run an action that would delete it automatically so I don't have to search all the layers to find it.

This topic has been closed for replies.

1 reply

brian_p_dts
Community Expert
Community Expert
January 3, 2024

On mobile, but something like this?

 

var doc = app.activeDocument;

var apis = doc.allPageItems;

var i = apis.length;

while(i--) {

if (apis[i].filled && apis[i].fillColor.name == "SwatchName") { apis[i].remove(); }

}

 

Hopefully you can get your client to appreciate the value of putting nonprinting items on their own layer(s).

Participant
January 3, 2024

Yes....something like that. Only a stroke not a fill.

With some conversation with the client, we are hoping to get them to understand proper file creation. 

rob day
Community Expert
Community Expert
January 3, 2024

Hi @Joseph34576598wd3q , I’m getting an error with @brian_p_dts ’s code—I think apis[i].filled is a typo. This includes a dropdown dialog of document swatches with Brian’s code edited, and gets the page item‘s stroke color

 

var cs;
var d = app.dialogs.add({name:"Stroke Color", canCancel:true});
with(d){
    with(dialogColumns.add()){
        cs = dropdowns.add({stringList:app.activeDocument.swatches.everyItem().name, selectedIndex:0, minWidth:80});
    } 
    if(d.show()){
        cs = app.activeDocument.swatches.everyItem().getElements()[cs.selectedIndex];
        var apis = app.activeDocument.allPageItems;
        var i = apis.length;
        while(i--) {
            if (apis[i].strokeColor.name == cs.name) { apis[i].remove(); }
        }
        d.destroy();
    }
}