Skip to main content
denisep726548
Inspiring
July 14, 2022
Answered

Text variable to add swatch names to text box.

  • July 14, 2022
  • 4 replies
  • 3368 views

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?

This topic has been closed for replies.
Correct answer denisep726548

You need to have a text frame selected, like you had to do with your pageHeight/width script. 


Duh. Sorry about that.

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

4 replies

Community Expert
July 15, 2022

@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 )

 

brian_p_dts
Community Expert
Community Expert
July 14, 2022

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. 

Community Expert
July 14, 2022

I discovered that a while ago. Seems pretty useless to me. What's the point of returning a number? What does that number mean?

brian_p_dts
Community Expert
Community Expert
July 14, 2022

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

Community Expert
July 14, 2022

Hi @denisep726548 ,

why do you run that script from a Version 6.0 Scripts folder?

That would reset and restrict all scripting features to InDesign CS4 from about 14 years ago.

Do not do that with a recent version of InDesign and script code that is meant for that version.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

denisep726548
Inspiring
July 14, 2022

thanks

brian_p_dts
Community Expert
Community Expert
July 14, 2022

Can you describe a little more what you need. A list of all swatches in the doc? 

 

denisep726548
Inspiring
July 14, 2022

I actually would like to create a text box for a print proof file that lists things like the file name, any USED swatches in the document, trim size...that sort of thing.

And that text box would be in a slug area outside of the trim box.

brian_p_dts
Community Expert
Community Expert
July 15, 2022

So I have this one that adds the text to the box rather than having to create the text variable each time.

Is it possible to do it this way so I can just run the javascript each time I open a doc?

The text variable does not stay if I open a new doc

 

var doc = app.activeDocument;
var label = "";

with (doc.documentPreferences) {
label += "W x H: " + pageWidth + " x " + pageHeight;
}

var tf = app.selection[0];
tf.contents = label;


 

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;