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

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

Participant ,
Aug 18, 2015 Aug 18, 2015

Copy link to clipboard

Copied

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

       };

TOPICS
Scripting

Views

1.4K

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

Community Expert , Aug 18, 2015 Aug 18, 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);

Votes

Translate

Translate
Adobe
Guide ,
Aug 18, 2015 Aug 18, 2015

Copy link to clipboard

Copied

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?

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
Participant ,
Aug 18, 2015 Aug 18, 2015

Copy link to clipboard

Copied

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

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
Community Expert ,
Aug 18, 2015 Aug 18, 2015

Copy link to clipboard

Copied

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

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
Participant ,
Aug 19, 2015 Aug 19, 2015

Copy link to clipboard

Copied

Hey!

Thanks so much for your help here.

I am going to try to do something with this, because it actually might save me a step of creating a copy of the image to use for my white layer.

I plan to copy the placed image and past it ontop then embed that top image and use your example above to create my white image.

I will try to get it working today and post some code up for anyone else that is interested to see how this works out.

Thanks a million Ten A

-Boyd

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
Guide ,
Aug 18, 2015 Aug 18, 2015

Copy link to clipboard

Copied

there is no fillColor object associated with placedItem in javascript.

if you look in the databrowser of ESTK after your script has run, you can add the fillColor object etc.. but it does not affect anything anything

if I set the color manually it works in the doc, but if I then feed that item into a variable, the databrowser still does not show those properties.

the only way I can make this work is to record an action then play that action from your script.

run your script on a test file. (so you have the swatch in the swatch panel.

select the placed image.

then create an action and while recording apply the swatch, then set the overprint. (best to do it in that order)

then in your script replace the 2 lines that set fillColor and Overprint with:

doScript('ActionName','SetName');

ie.

doScript('ApplySpot','ScriptActions');

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
Guide ,
Aug 18, 2015 Aug 18, 2015

Copy link to clipboard

Copied

I did not think to embed. that may be simpler. especially if you need to have the script on many computers.

if you do need to run on many machines and keep the image as a placed item, let me know.

it is possible to have the script create the action, run it, then remove the action again.

but this is a bit more complex. not worth doing if you don't need 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
Participant ,
Aug 19, 2015 Aug 19, 2015

Copy link to clipboard

Copied

Hello there Qwertyfly,

Thanks so very much for your help on this! funny thing is I actually thought of this very thing last night and tried it and it worked.

But like you said there is the issue of having to have that action on every computer. We do plan to use this on several computers.

So I am going to explore a little with Ten A's embed thing and see how that goes.

Thanks again for your prompt help you're truly amazing!

-Boyd

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
Guide ,
Aug 19, 2015 Aug 19, 2015

Copy link to clipboard

Copied

embedding the image may be the best solution.

but it can also make the file size larger. especially if your dealing with large images.

if you would like me to help with a function to create an action on the fly let me know.

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
Participant ,
Aug 19, 2015 Aug 19, 2015

Copy link to clipboard

Copied

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

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
Community Expert ,
Aug 19, 2015 Aug 19, 2015

Copy link to clipboard

Copied

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

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
Participant ,
Aug 20, 2015 Aug 20, 2015

Copy link to clipboard

Copied

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

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
Guide ,
Aug 20, 2015 Aug 20, 2015

Copy link to clipboard

Copied

can you post the code you have so far.

I refer to this thread often:

[JS] CS6+ executeMenuCommand

I don't know of any official documentation

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
Participant ,
Aug 24, 2015 Aug 24, 2015

Copy link to clipboard

Copied

LATEST

Ok so here is the code I have been playing with:

var doc = app.activeDocument;

var sel = doc.selection;

    //Flood white Color

    var floodWhiteCMYK = new CMYKColor;

    floodWhiteCMYK.magenta = 100;

    var floodWhiteSPOT = doc.spots.add();

    floodWhiteSPOT.name = "WhiteSpot";

    floodWhiteSPOT.color = floodWhiteCMYK;

    floodWhiteSPOT.colorType = ColorModel.SPOT;

   

    var floodWhiteColorSPOT = new SpotColor();

    floodWhiteColorSPOT.spot = floodWhiteSPOT;

   

copy();

paste();

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

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

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

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