Highlighted

Indesign Script for get color name or values of illustrator images used in the document

Participant ,
Oct 19, 2020

Copy link to clipboard

Copied

Hi Folks,

 

I have indesign document with placed illustrator images, indesign strokes and indesign rectangle objects. I have pull the colors of strokes, texts and rectangle objects used in the pages of the document. Is this possible to pull the color of illustrator images placed in the pages of the document.

 

Adobe Community Professional
Correct answer by BarlaeDC | Adobe Community Professional

Hi,

 

Following up from my previous post here is a rough script that would list the spot colours per illustrator document. It is not very pretty the output is just IllustratorFileName, Spot Colour, Spot Colour 2, ,, IllustratorFileName2, Spot Colour 3, Spot Colour 4.

 

But it gives the idea of how to do it, and I have just used the code above provided by @rob day and wrapped it in a function that calls for each illustrator link.

 

 

//alert(checkSpots(app.activeDocument));  

// call a new function that wraps the function above
var spotsPerFile = checkSpotsPerFile ( );
alert ( spotsPerFile);


function checkSpotsPerFile (){
    var totalArray = [];
   // get all the links in the document 
    var links = app.activeDocument.links;
    for ( var j = 0 ; j < links.length; j++){
        var curLink = links[j];
        // check they are illustrator links
        if ( curLink.linkXmp.creator.indexOf("Illustrator") !== -1) {
            var newDoc = app.documents.add(false);
            newDoc.pages[0].place ( curLink.filePath);
            totalArray.push( curLink.name);
            totalArray.push ( checkSpots ( newDoc));
            newDoc.close(SaveOptions.NO);
        }
    }
    return totalArray;
}

/**
* Gets a list of spot colors from placed files 
* @Return an array of color names 
* 
*/
function checkSpots(d){
    var p=d.colors; 
    var darray = ["Black", "Cyan", "Magenta", "Yellow", "Paper", "Registration"]; 
    var placeSpots = [];
    for (var i = 0; i < p.length; i++){

        if (!checkItem(darray, p[i].name)) {
            var theName = p[i].name
            try {
                p[i].name = p[i].name + "!";
            }catch(e) {
                placeSpots.push(p[i].name)
                continue;
            }  
            p[i].name = theName
        } 
    }
    return placeSpots
}

/**
* Checks if an item is in an array
* @Param the array to check 
* @Param the item to look for 
* @Return true if the item is in the array 
* 
*/
function checkItem(a, obj) {
    for (var i = 0; i < a.length; i++) {
        if (a[i] === obj) {
            return true;
        }
    }
    return false;
}

 

 

Hope this helps

 

Malcolm

TOPICS
Scripting

Views

116

Likes

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

Indesign Script for get color name or values of illustrator images used in the document

Participant ,
Oct 19, 2020

Copy link to clipboard

Copied

Hi Folks,

 

I have indesign document with placed illustrator images, indesign strokes and indesign rectangle objects. I have pull the colors of strokes, texts and rectangle objects used in the pages of the document. Is this possible to pull the color of illustrator images placed in the pages of the document.

 

Adobe Community Professional
Correct answer by BarlaeDC | Adobe Community Professional

Hi,

 

Following up from my previous post here is a rough script that would list the spot colours per illustrator document. It is not very pretty the output is just IllustratorFileName, Spot Colour, Spot Colour 2, ,, IllustratorFileName2, Spot Colour 3, Spot Colour 4.

 

But it gives the idea of how to do it, and I have just used the code above provided by @rob day and wrapped it in a function that calls for each illustrator link.

 

 

//alert(checkSpots(app.activeDocument));  

// call a new function that wraps the function above
var spotsPerFile = checkSpotsPerFile ( );
alert ( spotsPerFile);


function checkSpotsPerFile (){
    var totalArray = [];
   // get all the links in the document 
    var links = app.activeDocument.links;
    for ( var j = 0 ; j < links.length; j++){
        var curLink = links[j];
        // check they are illustrator links
        if ( curLink.linkXmp.creator.indexOf("Illustrator") !== -1) {
            var newDoc = app.documents.add(false);
            newDoc.pages[0].place ( curLink.filePath);
            totalArray.push( curLink.name);
            totalArray.push ( checkSpots ( newDoc));
            newDoc.close(SaveOptions.NO);
        }
    }
    return totalArray;
}

/**
* Gets a list of spot colors from placed files 
* @Return an array of color names 
* 
*/
function checkSpots(d){
    var p=d.colors; 
    var darray = ["Black", "Cyan", "Magenta", "Yellow", "Paper", "Registration"]; 
    var placeSpots = [];
    for (var i = 0; i < p.length; i++){

        if (!checkItem(darray, p[i].name)) {
            var theName = p[i].name
            try {
                p[i].name = p[i].name + "!";
            }catch(e) {
                placeSpots.push(p[i].name)
                continue;
            }  
            p[i].name = theName
        } 
    }
    return placeSpots
}

/**
* Checks if an item is in an array
* @Param the array to check 
* @Param the item to look for 
* @Return true if the item is in the array 
* 
*/
function checkItem(a, obj) {
    for (var i = 0; i < a.length; i++) {
        if (a[i] === obj) {
            return true;
        }
    }
    return false;
}

 

 

Hope this helps

 

Malcolm

TOPICS
Scripting

Views

117

Likes

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
Oct 19, 2020 0
Adobe Community Professional ,
Oct 19, 2020

Copy link to clipboard

Copied

If the AI files are placed you can get spot colors, but not process colors.

Likes

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
Reply
Loading...
Oct 19, 2020 0
Participant ,
Oct 19, 2020

Copy link to clipboard

Copied

Yes Rob! all AI files in the spot colors. Is there any script available?

Likes

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
Reply
Loading...
Oct 19, 2020 0
Adobe Community Professional ,
Oct 19, 2020

Copy link to clipboard

Copied

If a spot color comes in with a placed file it can’t be deleted, so a script could get a list of colors that are coming in with placed files, but I don’t see a way to find which file it came with. There might be a way to open each file and check its spot colors but that wouldn’t be a simple script.

Likes

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
Reply
Loading...
Oct 19, 2020 0
Adobe Community Professional ,
Oct 19, 2020

Copy link to clipboard

Copied

This would get a list of all spot colors that are from placed files:

 

alert(checkSpots());  


/**
* Gets a list of spot colors from placed files 
* @Return an array of color names 
* 
*/
function checkSpots(){
    var p=app.activeDocument.colors; 
    var darray = ["Black", "Cyan", "Magenta", "Yellow", "Paper", "Registration"]; 
    var placeSpots = [];
    for (var i = 0; i < p.length; i++){

        if (!checkItem(darray, p[i].name)) {
            var theName = p[i].name
            try {
                p[i].name = p[i].name + "!";
            }catch(e) {
                placeSpots.push(p[i].name)
                continue;
            }  
            p[i].name = theName
        } 
    }
    return placeSpots
}

/**
* Checks if an item is in an array
* @Param the array to check 
* @Param the item to look for 
* @Return true if the item is in the array 
* 
*/
function checkItem(a, obj) {
    for (var i = 0; i < a.length; i++) {
        if (a[i] === obj) {
            return true;
        }
    }
    return false;
}


Likes

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
Reply
Loading...
Oct 19, 2020 3
Adobe Community Professional ,
Oct 19, 2020

Copy link to clipboard

Copied

Hi,

 

You might be able to elaborate on the above by creating a script that imports each image in to a new empty document and then run the above script, then you would know which image had which spot colours?

 

Regards

 

Malcolm

Likes

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
Reply
Loading...
Oct 19, 2020 3
Participant ,
Oct 20, 2020

Copy link to clipboard

Copied

Is this possible to achieve the requirement with Adobe Bridge Concepts?

Likes

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
Reply
Loading...
Oct 20, 2020 0
Adobe Community Professional ,
Oct 21, 2020

Copy link to clipboard

Copied

Hi,

 

Following up from my previous post here is a rough script that would list the spot colours per illustrator document. It is not very pretty the output is just IllustratorFileName, Spot Colour, Spot Colour 2, ,, IllustratorFileName2, Spot Colour 3, Spot Colour 4.

 

But it gives the idea of how to do it, and I have just used the code above provided by @rob day and wrapped it in a function that calls for each illustrator link.

 

 

//alert(checkSpots(app.activeDocument));  

// call a new function that wraps the function above
var spotsPerFile = checkSpotsPerFile ( );
alert ( spotsPerFile);


function checkSpotsPerFile (){
    var totalArray = [];
   // get all the links in the document 
    var links = app.activeDocument.links;
    for ( var j = 0 ; j < links.length; j++){
        var curLink = links[j];
        // check they are illustrator links
        if ( curLink.linkXmp.creator.indexOf("Illustrator") !== -1) {
            var newDoc = app.documents.add(false);
            newDoc.pages[0].place ( curLink.filePath);
            totalArray.push( curLink.name);
            totalArray.push ( checkSpots ( newDoc));
            newDoc.close(SaveOptions.NO);
        }
    }
    return totalArray;
}

/**
* Gets a list of spot colors from placed files 
* @Return an array of color names 
* 
*/
function checkSpots(d){
    var p=d.colors; 
    var darray = ["Black", "Cyan", "Magenta", "Yellow", "Paper", "Registration"]; 
    var placeSpots = [];
    for (var i = 0; i < p.length; i++){

        if (!checkItem(darray, p[i].name)) {
            var theName = p[i].name
            try {
                p[i].name = p[i].name + "!";
            }catch(e) {
                placeSpots.push(p[i].name)
                continue;
            }  
            p[i].name = theName
        } 
    }
    return placeSpots
}

/**
* Checks if an item is in an array
* @Param the array to check 
* @Param the item to look for 
* @Return true if the item is in the array 
* 
*/
function checkItem(a, obj) {
    for (var i = 0; i < a.length; i++) {
        if (a[i] === obj) {
            return true;
        }
    }
    return false;
}

 

 

Hope this helps

 

Malcolm

Likes

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
Reply
Loading...
Oct 21, 2020 1
Adobe Community Professional ,
Oct 21, 2020

Copy link to clipboard

Copied

If you mean using BridgeTalk to open the AI files and check the colors there, it would be possible, but @BarlaeDC’s method would be easier.

Likes

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
Reply
Loading...
Oct 21, 2020 1
Participant ,
Oct 21, 2020

Copy link to clipboard

Copied

Thanks Rob! As u said it not possible to pull the cmyk color from the image right? In case, if needed to pull the cmyk color from the image means how?

Likes

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
Reply
Loading...
Oct 21, 2020 0
Adobe Community Professional ,
Oct 21, 2020

Copy link to clipboard

Copied

Right, if the Color Type is process and not spot there would be no way of getting the values without opening the file in Illustrator—and even then, the script would have to check every fill and stroke in the placed AI file.

Likes

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
Reply
Loading...
Oct 21, 2020 0
Participant ,
Oct 23, 2020

Copy link to clipboard

Copied

Please share if any resource to open the image via Bridge Talk and pick the color. My requirement is to pull the color of cmyk images too..

Likes

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
Reply
Loading...
Oct 23, 2020 0
rob day LATEST
Adobe Community Professional ,
Oct 23, 2020

Copy link to clipboard

Copied

A 24-bit image could have millions of CMYK values, so I’m not sure how you would identify what colors to get.

 

BridgeTalk coding can be difficult, but here is an example where Photoshop is launched from InDesign with two parameters and a string variable sent from ID to PS, and then a message returned back to ID:

 

 

//InDesign as the script application
#target indesign
#targetengine "session" 

var str = "Hello"
runPhotoshop(true, "Message From Photoshop:");


/**
* A function to run in Photoshop 
* @Param a boolean example 
* @Param a string example 
* @Return void 
* 
*/
function runPhotoshop(isBoolean, theString){
    //open Photoshop and run psScript
    var bt = new BridgeTalk();  
    bt.target = "photoshop";  
    //the function string with a string variable and 2 parameters
    //Note a string parameter is '"+theString+"'
    //Other parameters are "+isBoolean+"
    
    bt.body = "var aString = '"+str+"'; var func = " + psScript.toString() + "func("+isBoolean+",'"+theString+"');";

    bt.onResult = function(resObj) { 
        
        alert("String returned to InDesign: " + resObj.body);
    }  
    bt.onError = function( inBT ) { alert(inBT.body); };  
    bt.send(8);  
      
    function psScript(isBoolean, theString) { 
        //PS code here
        //var doc = app.documents.add();
        app.bringToFront();
        alert(theString + "  Photoshop is Running  " + aString)
        $.writeln("1st Param= " + isBoolean); 
        $.writeln("2nd Param= " + theString);
        $.writeln("1st Var= " + aString);
        return "Done"
    }  
}

 

Likes

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
Reply
Loading...
Oct 23, 2020 2