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

Is there a way to color rasterItems with a spot color via scripting?

Enthusiast ,
Oct 03, 2018 Oct 03, 2018

Copy link to clipboard

Copied

I would like to color a grayscale raster image via scripting. Since it's not possible to simply reference via fillColor, I have to use colorize(). The problem with colorize however is it doesn't seem to take Spot colors and only CMYK and RGB swatches. With the following I can get it to colorize my grayscale image, but since it's CMYK and not a spot, the raster fill color shows blue but the object itself appears black. Is there away that I can apply a fill via scripting? Could I group it, apply a fill and expand the appearance? It appears adding a fill to a group and expanding in this manor will work if I can get it to script, and although I'd have to delete an added unfilled raster item, I'm looking for any viable workaround to color a raster image.

var aD = app.activeDocument;

var nC = new CMYKColor();

nC.cyan = 100;

nC.magenta = 0;

nC.yellow= 0;

nC.black = 0;

var nCo = aD.spots.add();

nCo.colorType = ColorModel.SPOT;

nCo.color = nC;

nCo.tint = 100;

var newSpotColor = new SpotColor();

newSpotColor.spot = nCo;

//aD.pageItems[0].filled = true;

aD.rasterItems[0].overprint = true;

aD.rasterItems[0].colorize(nCo.color); //Testing with color value, as newSpotColor doesn't seem accessible via colorize for a spot color

TOPICS
Scripting

Views

1.6K

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 , Oct 04, 2018 Oct 04, 2018

This works by using the setting of the document's defaultFillColor:

    var doc = app.activeDocument; 

    var p = doc.rasterItems[0];

    p.selected = true;

    doc.defaultFillColor = doc.swatches["test"].color;

This is a really confusing part of our scripting because while the defaultFillColor appears to work, it looks like it does so even though the "color" property of a spot-swatch is a [SpotColor] kind of color that contains a .spot property, and the tint - not the CMYK/RGB information. And yet

...

Votes

Translate

Translate
Adobe
Advocate ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

Salut !

// JavaScript Document

var aD = app.activeDocument;

var nC = new CMYKColor();

nC.cyan = 0;

nC.magenta = 100;

nC.yellow= 0;

nC.black = 0;

var nCo = aD.spots.add();

nCo.colorType = ColorModel.SPOT;

nCo.color = nC;

    /*var newSpotColor = new SpotColor();

        newSpotColor.spot = nCo;

        newSpotColor.tint = 10;

        aD.pathItems[0].fillColor =  newSpotColor;*/

var im = aD.rasterItems[0];

    im.colorize(nCo.color);

    im.opacity = 10; // for tint = 10

de elleere

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 ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

This works by using the setting of the document's defaultFillColor:

    var doc = app.activeDocument; 

    var p = doc.rasterItems[0];

    p.selected = true;

    doc.defaultFillColor = doc.swatches["test"].color;

This is a really confusing part of our scripting because while the defaultFillColor appears to work, it looks like it does so even though the "color" property of a spot-swatch is a [SpotColor] kind of color that contains a .spot property, and the tint - not the CMYK/RGB information. And yet it still works Ok.

The .colorize method of raster items though does not take a [SpotColor] argument, which seems to be a mistake of sorts. Why have a method that doesn't really colorize? Well, like you noted it does not work, when used with the only kind of argument it accepts - a process color - but only in the useless sense that a raster colored thus will simply look exactly the same except when you click on it, your document fill color will change to the process color you've assigned through that .colorize() method.

I wonder if this is a real problem and bug or if they just have some other super secret method to properly activate it.

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
Enthusiast ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

LATEST

Genius! Agreed that swatches and these settings are odd for spots. It looks like info is stored at many levels of objects, for example app.activeDocument.swatches["test"].color.spot.color, holds the CMYK value, and seems pretty convoluted vs the standard swatch. I forgot to mention the restriction for filling with a spot color only applies if there is transparency involved in a raster grayscale image. If there's a white fill any color can be used to fill. The downside to this is of course if the spot color swatch is deleted the raster images turn back to solid black, however this is similar behavior to what can happen with spot colors anyway if they're out of gamut and become desaturated when converting to CMYK.


Being that the default fill color changes with every fill, or shape selected, this may be the most straight forward method. This method also lets you fill multiple paths at the same time without having to loop through them!

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