Skip to main content
Inspiring
August 7, 2017
Answered

Script to make selection 100% Black?

  • August 7, 2017
  • 3 replies
  • 1076 views

This script question is basic.  How would i go about making a script that makes the selection Solid Black?  I think i could do this in Indesign but I'm finding that illustrator is not the same in scritping

This topic has been closed for replies.
Correct answer Silly-V

It depends on what you have selected. For example you can have raster images, but they won't change color, or what if you had something with a fill and stroke , would you want both to be black?

Assuming you are just dealing with paths which have fills, you can apply the following snippet to give them the "Black" color of your document's swatches. The good thing is, your paths can be grouped or be compound paths, etc.

#target illustrator

function test(){

  var doc = app.activeDocument;

  doc.defaultFillColor = doc.swatches.getByName("Black").color;

};

test();

3 replies

cbishop01Author
Inspiring
August 8, 2017

Thanks both of you.  I used Silly-V's script (Slightly Modified) just because it was simpler to add the stroke as well.

#target illustrator

function test(){

    var doc = app.activeDocument;

        doc.defaultFillColor = doc.swatches.getByName("Black").color;

        doc.defaultStrokeColor = doc.swatches.getByName("Black").color;

};

test();

Silly-V
Silly-VCorrect answer
Legend
August 7, 2017

It depends on what you have selected. For example you can have raster images, but they won't change color, or what if you had something with a fill and stroke , would you want both to be black?

Assuming you are just dealing with paths which have fills, you can apply the following snippet to give them the "Black" color of your document's swatches. The good thing is, your paths can be grouped or be compound paths, etc.

#target illustrator

function test(){

  var doc = app.activeDocument;

  doc.defaultFillColor = doc.swatches.getByName("Black").color;

};

test();

cbishop01Author
Inspiring
August 8, 2017

Sorry i should have specified.  This is only for certain Guide marks such as "eyemarks/CropMarks" etc.. i have selected.  Both stroke and Fill. I really only need it for all the RICH BLACK marks i have on the documents.

Thanks to you both for replying.

Disposition_Dev
Legend
August 7, 2017

Depends upon what kind of object the selection is. For a simple pathItem, you can do this:

var docRef = app.activeDocument;

var blackColor = new CMYKColor();

blackColor.black = 100;

var sel = docRef.selection;

//assuming there's only one item selected

//if multiple items are selected, you just do this part in a loop

sel[0].fillColor = blackColor;

if you have groupItems you'll likely need some recursive functionality (unless you can rely on a consistent structure of the group, in which case you could target the underlying pathItems specifically, but this isn't very scalable and thus, a bad idea).

If you give more information about the file you're working with and the exact structure of the objects and what not, i can give a more specific answer.