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

Coloring a Font with a RGB etc. without adding the color to the document swatches.

Guru ,
Sep 21, 2011 Sep 21, 2011

Copy link to clipboard

Copied

Is there a way of coloring a font with a RGB, Lab or CMYK color without adding the color to the document swatches.

The only way I know is to add a color to the swatches or use one that already exists.

like

   app.selection[0].characters[0].fillColor=document.colors.add({colorValue: [255, 53, 160], space: ColorSpace.RGB});}

This has the undesired effect of cluttering up the swatches when using a lot of colors.

any ideas?

TOPICS
Scripting

Views

26.4K

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 1 Correct answer

Guru , Mar 19, 2014 Mar 19, 2014

Good Morning Uwe!

After 3am by me 2am by you

I had tried the link and it did download but I have cs5 cs6 and cc but not cs5.5 and all the scripts worked on them may because of the file conversion.

So it looks like the following summary is all correct

All documents new contain

Swatches (Black, Registration, Paper and None) the index order will be the order that the swatches appear in the swatches panel

And colors in an alphabetical index order

named color "A" first "Z" last and then the unnamed colors.

...

Votes

Translate

Translate
Mentor ,
Mar 20, 2014 Mar 20, 2014

Copy link to clipboard

Copied

Hi,

No need to capitalize, I did not provide it for public use - just to show the way (very rare)

Jarek

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 ,
Mar 20, 2014 Mar 20, 2014

Copy link to clipboard

Copied

@Jarek – to test your code, did you do the unthinkable?

( Removing all unnamed colors from app while no InDesign file was open )

I think, I can see what is happening here.

While no document is open, in the UI we can add a new unnamed color to app.colors, if we go to the Color Panel (not the Swatches Panel), define a color there.

Nothing more, nothing less. Phew…

That unnamed color will stick to the app.colors collection even after restarting InDesign app.

So even if a scripter was playing around and removed all unnamed colors, we have a way to fix this.

Of course, I did playing around and tested this 😉

Unless I do a reinstall of InDesign this new unnamed color will stick.

To make your script working, I think we should open the "Color" Panel beforehand:

app.panels.itemByName("$ID/kColor").visible = true;

ColorPanelOpen_NoDocumentOpen.png

Ok. So we can add an unnamed color through the Color Panel.

Could we do it while a document is open?

Yes. We can. No need to close all documents:

//Adding a fresh document:

app.documents.add();

//The following is also working on an already open document:

/*

IDs for the three different sub-menus of the "Color Panel": 

29188    Lab

29189    CMYK

29190    RGB

*/

//Make the Color Panel visible:

var myColorPanel = app.panels.itemByName("$ID/kColor").visible = true;

//Add a unnamed LAB color to the document.colors collection:

try{app.scriptMenuActions.itemByID(29188).invoke()}catch(e){$.writeln(e.message)};

for(x in app.documents[0].colors[-1]){

    $.writeln(x+"\t"+app.documents[0].colors[-1]);

    };

$.writeln("********************");

//Add a unnamed CMYK color to the document.colors collection:

try{app.scriptMenuActions.itemByID(29189).invoke()}catch(e){$.writeln(e.message)};

for(x in app.documents[0].colors[-1]){

    $.writeln(x+"\t"+app.documents[0].colors[-1]);

    };

$.writeln("********************");

//Add a unnamed RGB color to the document.colors collection:

try{app.scriptMenuActions.itemByID(29190).invoke()}catch(e){$.writeln(e.message)};

for(x in app.documents[0].colors[-1]){

    $.writeln(x+"\t"+app.documents[0].colors[-1]);

    };

$.writeln("********************");

/*

//RESULTS WITH A FRESH OPENED DOCUMENT:

model    1886548851

space    1665941826

colorValue    0,-0.49809998273849,-4.84829998016357

name   

id    207

label   

isValid    true

parent    [object Document]

index    15

properties    [object Object]

events    [object Events]

eventListeners    [object EventListeners]

isValid    true

********************

model    1886548851

space    1129142603

colorValue    100,100,0,100

name   

id    208

label   

isValid    true

parent    [object Document]

index    16

properties    [object Object]

events    [object Events]

eventListeners    [object EventListeners]

isValid    true

********************

model    1886548851

space    1666336578

colorValue    0,0,10.3275000303984

name   

id    209

label   

isValid    true

parent    [object Document]

index    17

properties    [object Object]

events    [object Events]

eventListeners    [object EventListeners]

isValid    true

********************

*/

Uwe

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 ,
Mar 20, 2014 Mar 20, 2014

Copy link to clipboard

Copied

Of course, the next step would be to access document.colors[-1] and change the colorValue to the desired one 🙂

Uwe

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 ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

After some years I have to come back to this old thread to add something.

In post # 22 I wrote:

An unnamed color  would  always be ColorModel.PROCESS.

Despite my attempts that cannot be changed…

That's still true, I think, but we could do a "named" color with model "spot" that will not make it to the Swatches panel ( if that's what we want ), because property "Visible" in an edited IDMS file can be changed from "true" to "false".

The visibility of a color is not necessarily dependent on a missing name for an added color by placing a snippet file.

Recently the question came up, if it is possible to add a hidden color:

Make a color hidden.

The answer would be "yes":

1. Add an unnamed color to the document

Note: A UI user could add that color to the Swatches panel.

It would be always convert to model PROCESS.

2. Add a named, but invisible color to the document by placing an edited IDMS snippet file.

Simply set a named color's "Visible" property to "false" in an IDMS snippet.

In editing the snippet all other properties like model, space or colorValue can be defined as you wish.

Note: A UI user would not be able to make the imported color visible in the Swatches panel.

The menu command is "Add unnamed colors" and not "Add invisible colors".

InvisibleSPOTcolor-imported-by-Snippet.png

Regards,
Uwe

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
LEGEND ,
Dec 09, 2011 Dec 09, 2011

Copy link to clipboard

Copied

Gosh I have no idea what prompted me to visit this thread again

... Here is a one-liner to set the color of a text selection to any RGB, Lab, or CMYK color without adding it to the Swatches list:

app.selection[0].fillColor.properties = {space:ColorSpace.RGB,colorValue:[255,255,0]};

Impressed? Well, if you try it you'll notice it won't work straight away. There Is A Catch! (Two of 'em, actually.)

.

.

.

.

.

(spoiler space)

.

.

.

.

.

Catch #1: You can only change the color of text if it already has an 'undefined' color!

Now usually, you'll find your text already comes with a swatch applied to it, even though it's simply "Black", and so you cannot use this trick. If you do want to use it, you have to change it first to the fillColor of a text that already has an undefined color applied to it; then you can change it to anything you want. But you cannot create a piece of text to act as model to begin with, using a script (well, other than Harbs' workaround with a temporary snippet file) -- a real Catch-22.

To get it to work, draw a new text frame somewhere on the pasteboard in your document and enter this text into it: "A Jongware Solution". (Use exactly this text.) Change the color to something random, using the Color panel. Use the Script Label panel to add a label to the text frame -- use "color placeholder". Then, just before the line that sets other text to any color, insert this:

app.selection[0].fillColor = app.activeDocument.textFrames.item("color placeholder").characters[0].fillColor;

At first glance, this appears to work, but I noticed The Weirdest Thing. If you apply this color to your newly selected text, you'll find it initially is set to the placeholder color. That's to be expected. The second line (the one at the top of this post) also works, as you will see the color change to the new settings.

However. Catch #2

Check what happens to the placeholder text ... It also changes its color! Curioser & curioser, if you used this trick a couple of times in the same document, you'll find that every item with the same color also changes! It's kinda like ... you have a swatch ... but not really ...

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
Guru ,
Dec 11, 2011 Dec 11, 2011

Copy link to clipboard

Copied

Thanks Jongware

I'm afraid I agree with the spoiler lines you put it

I think the catches are quite big,

Oh well, but as it happens I was also thinking of this post lately and thought of you because I had seen on another post that you wrote that one can use menu actions

So I know this is a cheat because my question was how to add color with no swatch but I think (based on Harbs and your replys) that its better to add and then remove the swatches and replace the removed swatches with unnamed ones.

But It's easier said than done

Please see the script below and see if you can correct the problem line

to run the script a letter ... which is colored with a swatch must be selected.

var myMenu = app.menuActions.item('$ID/Swatches_WinMenu');

myMenu.invoke();

var mySwatchRemoveMenuItem = app.menuActions.item('$ID/Delete Swatch...');

mySwatchRemoveMenuItem.invoke();

var makeUnnamedSwatch = app.menuActions.item('$ID/Unnamed Swatch');

// The above line is the problem line I don't know what to put instead of '$ID/Unnamed Swatch'

// to get it to choose replace with unnamed swatch as there dosn't seem to be a valid $ID for it.

makeUnnamedSwatch.invoke();

Once again

Thanks

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
LEGEND ,
Dec 11, 2011 Dec 11, 2011

Copy link to clipboard

Copied

I'm afraid it's not that straightforward. "Delete Swatch" is a menu option but "Replace with Unnamed Color" is not, so there is nothing to invoke.

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
Guru ,
Dec 11, 2011 Dec 11, 2011

Copy link to clipboard

Copied

Oh well again, I guess that sums it up.

Thanks

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 ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

Hi together,

update on some details.

 

With InDesign 2021 version 16 the developers added the new color mode HSB next to LAB, RGB and CMYK.

So my statement from 2014 is not true anymore:

 

/*
IDs for the four different sub-menus of the "Color Panel":  
29188    Lab
29189    CMYK
29190    RGB
*/

 

 

The old IDs invoke "different" sub-menus of the "Color Panel" and one ID was simply added:

 

/*
InDesign 2021 version 16 and above:

IDs for the three different sub-menus of the "Color Panel":
29188    HSB
29189    Lab
29190    CMYK
29191    RGB
*/

 

 

Regards,
Uwe Laubender
( Adobe Community Expert )

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 ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

LATEST
app.panels.itemByName("$ID/kColor").visible = true;

try
{
	
	/*
		InDesign 2021 version 16 and above:

		IDs for the four different sub-menus of the "Color Panel":
		29188    HSB
		29189    Lab
		29190    CMYK
		29191    RGB
	*/

	// RGB
	app.scriptMenuActions.itemByID( 29191 ).invoke()
	
}catch(e)
{
	$.writeln( "ERROR: " + e.number +", " + e.message )
};

 

Regards,
Uwe Laubender
( Adobe Community Expert )

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