Copy link to clipboard
Copied
Hello all,
I wonder if anyone could help me please!
I need an 'if' statement as below and can't seem to find it anywhere
if
a spot color called "test" exists
run code
I have some code which checks if the color "test" exists, but at the moment it still runs even if it's a process color which is incorrect. The code should only run if "test" is a spot.
Thank you in advance for reading
Copy link to clipboard
Copied
try this..
items= app.activeDocument.pageItems.everyItem().getElements();
for (i = 0; i < items.length; i++) {
if(items.fillColor.name == "test" || items.strokeColor.name == "test" ){
Copy link to clipboard
Copied
Thanks so much for your reply.
However this code runs even if "test" is a process color.
Is there a way to only run if "test" is strictly a spot color?
I admit I'm not sure if this is even possible!
Copy link to clipboard
Copied
something like this?
var myIndesignDoc = app.documents[0];
var mySwatch = myIndesignDoc.swatches;
var items= app.activeDocument.pageItems.everyItem().getElements();
var object = new Array();
object = mySwatch.everyItem().getElements();
for(i=object.length-1;i>=4;i--){
var swatchType = object.constructor.name
if(swatchType == "Color"){
if(mySwatch.model == ColorModel.SPOT){
for (j = 0; j < items.length; j++) {
if(items
.fillColor.name == "test" || items .strokeColor.name == "test" ){
Copy link to clipboard
Copied
if
a spot color called "test" exists
run code
Seems like you just want to check the document colors and not all of the page item fills & strokes? In that case it could be:
var c=app.activeDocument.colors;
for (var i = 0; i < c.length; i++){
if (c.model==ColorModel.SPOT && c.name=="test"){
alert("test Exists Run Code")
}
}
Copy link to clipboard
Copied
Hi Rob,
looping all colors is not necessary.
Just test for isValid and the value of property model:
var testColor = app.activeDocument.colors.itemByName("test");
if( testColor.isValid && testColor.model == ColorModel.SPOT )
{
doSomething();
}
else
{
doSomethingElse();
};
function doSomething()
{
alert("Color found.");
}
function doSomethingElse()
{
alert("Color not found.")
}
Regards,
Uwe
Copy link to clipboard
Copied
Thanks Uwe.