• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Text variable to add swatch names to text box.

Explorer ,
Jul 14, 2022 Jul 14, 2022

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?

TOPICS
How to , Scripting

Views

851

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
community guidelines

correct answers 2 Correct answers

Community Expert , Jul 14, 2022 Jul 14, 2022

 

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;

 

Votes

Translate

Translate
Explorer , Jul 15, 2022 Jul 15, 2022

Duh. Sorry about that.

thank you so much! I think this will work perfectly!!!!

Votes

Translate

Translate
Community Expert ,
Jul 14, 2022 Jul 14, 2022

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. 

Votes

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
community guidelines
Community Expert ,
Jul 14, 2022 Jul 14, 2022

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?

Votes

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
community guidelines
Community Expert ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

Really useless, except in this use case I guess where you just want to find at least one instance. 

Votes

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
community guidelines
Community Expert ,
Jul 15, 2022 Jul 15, 2022

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:

 

220715-4-app.menuAction $ID FindNext with ID 18706.invoke().PNG

 

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 )

 

Votes

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
community guidelines