Copy link to clipboard
Copied
I wrote this code
But I am getting the error Why?
var findC = [
"C=100 M=0 Y=0 K=0",
"C=0 M=0 Y=100 K=0"
]
changeC = [
"C=15 M=100 Y=100 K=0",
"C=75 M=5 Y=100 K=0"
]
var doc = app.activeDocument;
app.findObjectPreferences = app.changeObjectPreferences = null;
for(var i = 0; i < findC.length; ++i) {
app.findObjectPreferences.fillColor = app.activeDocument.swatches.itemByName(findC);
app.changeObjectPreferences.fillColor =app.activeDocument.swatches.itemByName(changeC);
app.changeObject();
}
app.findObjectPreferences = app.changeObjectPreferences = null;
Copy link to clipboard
Copied
Hi,
would you like to tell what "the" error is?
And what line is throwing this?
Thanks,
Uwe
Copy link to clipboard
Copied
Hm.
Your code is missing at least one comma and at semicolon.
FWIW: I think, findObjectPreferences is broken with InDesign scripting.
There is at least one fundamental bug.
If I apply a color like "C=100 M=0 Y=0 K=0" to the fill property in the UI,
app.findObjectPreferences.fillColor returns an error.
The equivalent of: $ID/kScriptErrNotApplicable
In my German InDesign: "Diese Eigenschaft ist im aktuellen Status nicht zutreffend."
Tested with CS6 8.1.0 on OSX 10.6.8.
What is your exact version of InDesign and OS ?
Regards,
Uwe
Copy link to clipboard
Copied
I use Ä°ndesing CS6 and in windows10
This error:
Invalid value for cluster property "fillColor". Expected Swatch, String or NothingEnum enumerator but received Color
Line text:
app.findObjectPreferences.fillColor = app.activeDocument.swatches.itemByName(findC);
Copy link to clipboard
Copied
Seems to be a bug with InDesign's scripting engine.
You have to search without using findObject .
Get all the pageItems of the document and evaluate them one after another.
Perhaps you could use the document.allPageItems array. Beware that this array would not include page items in non-active states of MultiStateObjects (MSOs).
Write the results to an array or change the fillColor while looping.
Beware of pageItems where fillColor perhaps throw an exception.
Like the ones anchored in overset text.
Regards,
Uwe
Copy link to clipboard
Copied
This my code its run but
rectangle don't
var myDoc = app.activeDocument;
var pi = myDoc.allPageItems;
for(j = 0; j < pi.length; ++j) {
it = pi
if(it && it instanceof TextFrame){ // && rectangle ??
for(var k=0; k<findC.length; k++) {
if(it.fillColor.name == findC
it.fillColor = changeC
}
}
}
}
Copy link to clipboard
Copied
This works for me also on rectangles:
var findC = [ "C=100 M=0 Y=0 K=0", "C=0 M=0 Y=100 K=0"];
var changeC = [ "C=15 M=100 Y=100 K=0", "C=75 M=5 Y=100 K=0"];
var doc = app.activeDocument;
var pi = doc.allPageItems;
for (var j = 0; j < pi.length; ++j) {
var it = pi
if (it.isValid && it instanceof Rectangle) { // && rectangle ??
for(var k=0; k<findC.length; k++) {
var curFindColor = findC
var curChangeColor = changeC
if (it.fillColor.name == curFindColor) {
it.fillColor = curChangeColor;
}
}
}
}
Copy link to clipboard
Copied
Hi together,
the first thing I would do is to resolve the individual pageItem:
var it = pi
.getElements()[0];
FWIW: Items where fillColor throws an error are images in RGB or CMYK color model.
Also other type of graphics. So prepare for them. Or use a try/catch wrapper.
Regards,
Uwe