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

Deleting Things that arent black

Community Beginner ,
Aug 23, 2018 Aug 23, 2018

I have a script that needs to perform a variety of functions, and one part I am stuck on is getting the script to delete anything that's not black.  Everything else in the script seems to be doing what it needs to but heres the part that keeps getting messed up:

var myDoc=app.activeDocument;

app.executeMenuCommand ('selectall');

var sel = myDoc.Selection

for (var i = 0; i < sel.length; i++) {

    var item = sel.pathItems;

    if (item.fillColor.black = 100)

   {}

       else {app.executeMenuCommand('clear');}

}

so im wanting it to cycle through each path in the selection, identify if its fill is black and delete it if its not.

Any Thoughts?

Thanks!

TOPICS
Scripting
835
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
Adobe
Community Expert ,
Aug 24, 2018 Aug 24, 2018

This isn't isn't an inherently straightforward process because of the different objects you may have in your selection array.

Consider that fillColor is not a property of groupItem, compoundPathItem, or placedItem. You need to have some kind of check to make sure you're looking at something that actually has a fillColor property associated with it. And because of the potential complexities that come along with a virtually unlimited ability to nest items, you invariably need some recursion to properly traverse the layer structure to identify all of the black items or all of the items that are not black.

Another less involved option is to draw a temporary shape and fill it with the color that you want to keep (in this case, black).

then (assuming you're using CS6 or newer) you can use the executeMenuCommand() method to select same fill, like so:

var mySwatch = app.activeDocument.swatches["Black"];

var tmpBlock = app.activeDocument.pathItems.rectangle(0,0,10,10);

tmpBlock.fillColor = mySwatch.color;

//select everything that has a fill color that matches mySwatch

app.executeMenuCommand("Find Fill Color menu item");

//select inverse to get everything that is NOT filled with black.

app.executeMenuCommand("Inverse menu item");

//remove the selected artwork.

for(var x= app.activeDocument.selection.length-1;x>=0;x--)

{

     app.activeDocument.selection.remove();

}

tmpBlock.remove();

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
Advocate ,
Aug 25, 2018 Aug 25, 2018

Salut William,

IL manque tmpBlock.selected;

LR

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 ,
Aug 27, 2018 Aug 27, 2018

good call. thanks!

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
Advocate ,
Aug 28, 2018 Aug 28, 2018

Salut !

Puisque tu as écrit  (var item = sel.pathItems😉 je suppose que tu veux examiner les objets de type PathItem.

Je corrige strictement ce que tu proposes sans rien ajouter pour que ça fontionne.

Remarque : Color.black --> "CMYKColor" sinon résultat "undefined"

//-----------------------------------

var myDoc=app.activeDocument;

var sel = myDoc.pathItems; // A collection of PathItem objects (myDoc)

  for (var i = sel.length-1; i >= 0; i--) {

    var item = sel;

    if (item.fillColor.typename == "CMYKColor") {

         if (item.fillColor.black == 100) {

            alert('myDoc.pathItems['+i+'] black = 100')

         }

      else {item.remove();}

   }

}

//------------------------------------

de LR

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 Beginner ,
Aug 28, 2018 Aug 28, 2018

Thank you both for taking a look at this.  I have not had a chance to play with either solution just yet, probably wont be able to get to it until later this week.  However I was using the selection as the templates use some things for screen printing that are CMYK registration colors.  I have the script lock those layers and then select the layers it needs.

Do you think that your method using "sel mydoc.pathitems" will see and grab things that are hiding in the locked layers?

Merci!

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 ,
Aug 29, 2018 Aug 29, 2018
LATEST

You cannot access items of a locked layer with myDoc.selection. that's the main reason for having a locked property.

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