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

Remove all Pageitems with a specific Swatch as fillcolor

Community Beginner ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

Hi,

Im trying to write a script that removes all pageItems that has a specific Swatch as fillColor.

I almost succeed, the only problem is that the for-loop breaks after half of the items on the page is removed.

I really do not understand what Im doing wrong. Does anybody have any explanation?

Best regards

Anders

var doc = app.activeDocument;

var all = doc.pageItems;

var colorName = "myColor"; //Name of the swatch

color = doc.swatches.getByName ( colorName );

color = color.color ;

for (i = 0; i < all.length; i++)

{

    if (

eachPath.fillColor.cyan == color.cyan

    && eachPath.fillColor.magenta == color.magenta

    && eachPath.fillColor.yellow == color.yellow

    && eachPath.fillColor.black == color.black )

    {

all.remove();

    }

}

TOPICS
Scripting

Views

233

Translate

Translate

Report

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 ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

LATEST

Try using a reverse series. i.e. i=all.length-1; i =>0; i--

Votes

Translate

Translate

Report

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