Skip to main content
aiScripting
Inspiring
August 18, 2015
Answered

Setting Color and Overprint for a placed image (it is a Grayscaled image)

  • August 18, 2015
  • 2 replies
  • 1857 views

So I am trying to set the color of an image I have placed to a spot color then set it to overprint fill.

I have successfully created a rectangle and added these attributes to it. But I cant seam to get the same to work for a placed (Grayscale) image.

Here is some of my code:

#target illustrator-19

var doc = app.activeDocument;

var sel = doc.selection;

var aiDocWidth = doc.width;

var iPath = sel[0].file.path + "/";//Name;

var origImage = sel[0].file;

var origImageFile = File(origImage);

  if(origImageFile.copy(decodeURI (iPath) + "/W_" + origImageFile.name)){

                //iFile[0].remove();

                };

var wImageFile = File(iPath+ "/W_" + origImageFile.name);

var psScript  = 'app.displayDialogs = DialogModes.NO;';

        psScript += 'app.open(' + wImageFile.toSource() + ');';

        psScript += 'app.activeDocument.changeMode(ChangeMode.GRAYSCALE);'; 

        psScript += 'app.activeDocument.activeLayer.invert();';

        psScript += 'app.activeDocument.close( SaveOptions.SAVECHANGES );'; 

        psScript += 'app.displayDialogs = DialogModes.ALL;';

       

btMessaging('photoshop',psScript);

placeImage(wImageFile,origImage,sel[0]);

       

function btMessaging( targetApp, script ) { 

          var bt = new BridgeTalk(); 

          bt.target = targetApp; 

          bt.body = script; 

          bt.onResult = function( inBT ) { alert( 'Done…' ) }; 

          bt.onError = function( inBT ) { alert( 'OOPS! something went wrong! :(' ) }; 

          bt.send( 20 ); 

};

function placeImage(fName,origImage,sel){

   

            var aDoc = app.activeDocument;

           

            var aLayer = aDoc.activeLayer;

           

                    //Flood white Color

                var floodWhiteCMYK = new CMYKColor;

                floodWhiteCMYK.magenta = 100;

 

                    //White Color object

                var floodWhiteSPOT = aDoc.spots.add();

                floodWhiteSPOT.name = "WhiteSpot";

                floodWhiteSPOT.color = floodWhiteCMYK;

                floodWhiteSPOT.colorType = ColorModel.SPOT;

                    //create instance of this object

                var floodWhiteColorSPOT = new SpotColor();

                floodWhiteColorSPOT.spot = floodWhiteSPOT;

           

           var pImage = aLayer.placedItems.add (origImage.top,origImage.left);

            pImage.file = fName;

            pImage.name = "WhiteImage";

            pImage.selected = true;

            pImage.fillColor = floodWhiteColorSPOT;

            pImage.fillOverprint = true;

      

            var origI = sel;

            var x = origI.position[0] + (origI.width / 2);

            var y = origI.position[1] - (origI.height / 2);

           

            // move image

            pImage.position = [x - (pImage.width / 2),y + (pImage.height / 2)];

       };

This topic has been closed for replies.
Correct answer Ten A

PlacedItems don't have colorize property or methods, overprint property too.

However, we can set color by colorize method and set overprint property after convert to rasterItems using embed method.

Here is a little sample code:

var clr= new CMYKColor;

clr.cyan = 50;

clr.magenta = 50;

clr.yellow = 0;

clr.black = 0;

app.selection[0].embed(); //selection[0] must be placedItem

app.selection[0].rasterItems[0].overprint = true;

app.selection[0].rasterItems[0].colorize(clr);

2 replies

aiScripting
Inspiring
August 20, 2015

Ok, so now I've been playing with embedding the file but one issue I have is I want to embed the file do a few changes to it in AI (e.g. embed a pdf file and rasterize it) Then I want to take that image to PS, but how I was doing it before I was just passing PS a file location with the app.open(); command.

How would I get my embedded image to PS to do the Grayscale and invert the color?

Thanks in advance!

-Boyd

Ten A
Community Expert
Community Expert
August 20, 2015

Here is a sample solution:

app.selection[0].embed(); //selection[0] must be placedItem 

app.executeMenuCommand("Colors7"); //convert rasterItem to Grayscale

app.executeMenuCommand("Colors6"); //inverse images

aiScripting
Inspiring
August 20, 2015

This is coming a long really well! getting closer to what I want here.

I just need to take the selected group/clipped mess that it copied and gray-scaled and unclip it and un group it to get rid of all the clipping masks so when I color it it won't color the clipping paths too making it just a big square over the whole image.

Also where can I find a list of MenuCommand options that can be used with the "executeMenuCommand()"?

Thanks

-Boyd

Qwertyfly___
Legend
August 18, 2015

I'm going to guess that the placed image is raster and not vector.

should be a good guess due to the btMessaging to Photoshop.

I am fairly sure you can't make these settings to a raster image in illustrator.

if you can't achieve this manually then your not going to get it to work with a script.

but maybe I have not understood what you are trying to do.

Can you do this if you do it manually without a script?

aiScripting
Inspiring
August 19, 2015

Hello Qwertyfly!

Sorry I didn't clarify on the image type. in this case it is a .tif (yes raster images)

and yes I can do this manually, I am trying to duplicate what I have to do manually over and over, and just have the script do it.

So far I it will make the duplicate image and open it in PS and make it grayscale, then come back to AI and place the new gray scaled image ontop of the original.

I just need to set its fill color to my "WhiteSpot" swatch and set it to overprint.

I am guessing there is no easy way to do this or I would have figured it out.... hoping someone can help me come up with a work around.

Thanks!

-Boyd

Ten A
Community Expert
Ten ACommunity ExpertCorrect answer
Community Expert
August 19, 2015

PlacedItems don't have colorize property or methods, overprint property too.

However, we can set color by colorize method and set overprint property after convert to rasterItems using embed method.

Here is a little sample code:

var clr= new CMYKColor;

clr.cyan = 50;

clr.magenta = 50;

clr.yellow = 0;

clr.black = 0;

app.selection[0].embed(); //selection[0] must be placedItem

app.selection[0].rasterItems[0].overprint = true;

app.selection[0].rasterItems[0].colorize(clr);