Copy link to clipboard
Copied
Does anyone know how to create a text variable to add the swatch names to a text box to be used as part of a slug line for the document?
var doc = app.activeDocument;
var swatches = doc.swatches;
var i = swatches.length;
var s = "Swatches Used: ";
var a = [];
while (i-- && i > 3) {
app.findColorPreferences.findWhat = swatches[i];
if (doc.findColor() > 0) {
a.push(swatches[i].name);
}
}
a.sort();
s+= a.join(", ");
var label = "";
with (doc.documentPreferences) {
label += "W x H: " + pageWidth + " x " + pageHeight + "; " + s;
}
var tf = app.selection[0];
tf.contents = label;
Duh. Sorry about that.
thank you so much! I think this will work perfectly!!!!
Copy link to clipboard
Copied
Incidentally for scripters of the world, note that doc.findColor() returns a Number, not an array as with the other find operations. Today I learned.
Copy link to clipboard
Copied
I discovered that a while ago. Seems pretty useless to me. What's the point of returning a number? What does that number mean?
Copy link to clipboard
Copied
Really useless, except in this use case I guess where you just want to find at least one instance.
Copy link to clipboard
Copied
@Peter Kahrel said: "What does that number mean?"
Hi Peter,
after some tests with doc.findColor() it seems that the returned number is the number of found items.
Not very helpful. Initially I had hopes, that page items and texts were returned stored to an array. But I can already see in the DOM documentation, that only a number will be returned.
findColor() is very limited.
Only available with app and document.
Exactly like the GUI is showing this.
To collect the found items I tested a menuAction for "Find Next" with the internal name "$ID/Find Next" that returns two id numbers when done with app.menuActions.itemByName("$ID/Find Next").id : 18695 and 18706. Because Find/Change Colors was only introduced recently I tried the higher ID number when the Find/Change interface was showing a valid Find for a color.
/*
menuAction with name "$ID/Find Next" below.
Found two id numbers for this: 18695,18706
The one with 18706 seems to be the one for Find/Change Color
*/
app.menuActions.itemByID(18706).invoke();
/*
invoke()
provoked a reaction in the GUI.
Message: No item found.
*/
But it only provoked a message in the GUI that nothing could be found.
From my German InDesign 2022 on Windows 10:
Still, I'm looking for a way with menu actions to select a found item, so that I can collect the found items in an array…
The number of iterations to call for invoke() is clear. That's the number doc.findColor() or app.findColor() returns.
I have not much hope to be successful with this…
Regards,
Uwe Laubender
( Adobe Community Professional )