Skip to main content
JasonC75
Participant
October 26, 2016
Answered

Selecting white paths and deleting via script

  • October 26, 2016
  • 3 replies
  • 533 views

Hi Guys,

I am pretty new to JS scripting in Illustrator CC.

I currently have a script that does the following;

  • Loads a bitmap
  • Centers it
  • Performs a B/W image trace
  • 'Expands' the trace
  • and then saves the file as an AI file

This is working great. But I am wondering how I could add a step after the 'Expand' to select the white content and delete it. Leaving just the black area.

Any advice would be greatly appreciated.

Thanks in advance

Edited title to fit more with AI terminology

This topic has been closed for replies.
Correct answer pixxxelschubser

Hmm.

Do you really need a script?

You know the "Ignore White"-option in the trace dialog?

3 replies

JasonC75
JasonC75Author
Participant
October 26, 2016

Hi there. I most certainly do

I need to strip out the white paths in approximately 7000 traced files.

[edit]

Actually, I think I know what you are getting at.

I just adjusted the preset to ignore white and the script now works perfectly!

Thanks heaps! You are a gem

(Although, it would still be nice to know why all of the paths return [GrayColor] in the script)

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
October 26, 2016

Hmm.

Do you really need a script?

You know the "Ignore White"-option in the trace dialog?

JasonC75
JasonC75Author
Participant
October 26, 2016

I think I am pretty close.

var itemsLength=app.activeDocument.pathItems.length;

for(var i=0;i<itemsLength;i++)
{
var pathColor=app.activeDocument.pathItems.fillColor;
alert(pathColor);

// PSUEDO CODE
// If path is 'white'
// {
//   pathItem.remove();
// }
}

I can tell that there are five paths in my test file, which the script reports happily. But when I iterate through the paths they all report as being "[Gray Color]". But, the paths are either solid black or solid white.

Any advice would be much appreciated

pixxxelschubser
Community Expert
Community Expert
October 26, 2016

You're welcome.

And the full (scripting) answer:

With fillColor you get the color type. You can check this with replacing lin#3 and #4 in your code:

var Col=app.activeDocument.pathItems.fillColor.typename;

var pathColor=app.activeDocument.pathItems.fillColor.gray;

$.writeln(Col);

$.writeln(pathColor);

Furthermore:

If you want to remove elements than you should loop backward through your document. Otherwise the removing fails.

Have fun