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

Script to make selection 100% Black?

Advocate ,
Aug 07, 2017 Aug 07, 2017

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

807

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

correct answers 1 Correct answer

Valorous Hero , Aug 07, 2017 Aug 07, 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.defaultFi

...

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 07, 2017 Aug 07, 2017

Copy link to clipboard

Copied

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.

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
Valorous Hero ,
Aug 07, 2017 Aug 07, 2017

Copy link to clipboard

Copied

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();

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
Advocate ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

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.

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
Advocate ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

LATEST

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();

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