Illustrator Script to get the path item used fill color name
Hi guys,
Could any help me to get the illustrator image path item fill color used name through script.
Hi guys,
Could any help me to get the illustrator image path item fill color used name through script.
Hi Raghav,
I have merged your code and code shared by @pixxxelschubser which is written by @Silly-V to get the swatches name from Indesign when ai file is placed in the Indesign documnt.
#target indesign
#targetengine "session"
var illustratorImages = [];
var filePath
function ImageColors() {
var myDoc = app.activeDocument;
var mypages = myDoc.spreads;
if (mypages.length > 0) {
for (var k = 0; k < mypages.length; k++) {
var myPageItems = mypages[k].allGraphics;
for (var l = 0; l < myPageItems.length; l++) {
if (myPageItems[l].parentPage != null) {
if (myPageItems[l].itemLayer.visible == true && myPageItems[l].visible == true) {
if (myPageItems[l].itemLink.name.indexOf(".ai") != -1) {
var bt = new BridgeTalk();
bt.target = "illustrator";
var myScript = aiScript.toString() + "\r";
filePath = myPageItems[l].itemLink.filePath;
myScript += "aiScript(\"" + filePath + "\")";
bt.body = myScript;
bt.onResult = function (resObj) {
//get a string sent back from AI
alert("Illustrator sent this message back to InDesign. " + resObj.body.toString());
}
//error handler
bt.onError = function (inBT) { alert(inBT.body); };
//send to Illustrator
bt.send();
}
}
}
}
}
}
return filePath
}
ImageColors()
function aiScript(path) {
/*******************************************************************
Prototype for indexOf()
********************************************************************/
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement /*, fromIndex */) {
"use strict";
if (this == null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (len === 0) {
return -1;
}
var n = 0;
if (arguments.length > 0) {
n = Number(arguments[1]);
if (n != n) { // shortcut for verifying if its NaN
n = 0;
} else if (n != 0 && n != Infinity && n != -Infinity) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
}
if (n >= len) {
return -1;
}
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
for (; k < len; k++) {
if (k in t && t[k] === searchElement) {
return k;
}
}
return -1;
}
}
/*******************************************************************
********************************************************************/
var colorUsed = new Array();
var finalPath = path.replace(":", "/", "g");
var doc = app.open(new File(finalPath));
doc.selection = null;
var _pageItems = doc.pageItems;
for (var i = 0; i < _pageItems.length; i++) {
doc.selection = null;
_pageItems[i].selected = true;
var selectedSwatches = doc.swatches.getSelected();
if (selectedSwatches.length) {
if (colorUsed.indexOf(selectedSwatches[0].name) == -1)
colorUsed.push(selectedSwatches[0].name);
}
}
doc.close(SaveOptions.DONOTSAVECHANGES);
return colorUsed;
}
This will return all swatches name that is used in ai file that you have placed in the indesign document. Currently this script will return duplicate swatches name if it is used twice or more in ai file. I have attached the sample Indesign and AI file as well on which I have run the script. Keep both files at any location, and make sure you update the link in Indesign file as per your location of ai file on your machine.
Let us know how it works for you.
EDIT : Added handling of unique names using Array.indexOf()
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.