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

Swatch to unnamed Swatch

Enthusiast ,
Dec 28, 2018 Dec 28, 2018

Hi All,

Is it possible to convert all the swatches to unnamed swatch?

var mySwatches = app.activeDocument.swatches;

for (s = mySwatches.length-1; s >= 4; s--) {

    mySwatches.remove();   //Need to change this line.

    }

After that as per my request will invoke the All Unnamed Colors.

app.menuActions.itemByName("$ID/Add All Unnamed Colors").invoke(); 

Screen Shot 2018-12-28 at 3.48.45 PM.png

Thanks in Advance

TOPICS
Scripting
1.3K
Translate
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 ,
Dec 28, 2018 Dec 28, 2018

Have a look at the discussion in the following thread, it will lead you to a solution for your problem

Re: [JS] delete swatch without replacing

-Manan

Translate
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 ,
Dec 28, 2018 Dec 28, 2018

While the link mentioned above will help you delete a swatch and replace with an unnamed swatch. What i want to understand is the end goal you are trying to achieve. I see you will

  • Delete swatches by replace it with unnmamed swatch
  • Then again add them using the "Add All Unnamed Colors"

So the end result will have the same no. of Swatches(in some cases) as the start, with the only change being that the swatches that could be deleted are renamed to their Color Values

Unless i am missing something why not straightaway rename the Swatch with the color names rather than going through the process of deleting and then adding.

In your case you might end up with some more swatches w.r.t. to some unnamed colors used in the document being added to Swatch panel. While in my proposed solution you would have the same number of Swatches before and after the process. If you want to add the unnamed colors used in the doc you can call the menu option once in my proposed solution as well.

-Manan

Translate
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 ,
Dec 28, 2018 Dec 28, 2018

Hi together,

just one detail when you add all unnamed colors:

InDesign will always round values to integers when creating names.

By renaming colors you can be more precise and avoid false duplicates where the word Copy-n will be added.

Regards,
Uwe

Translate
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 ,
Dec 28, 2018 Dec 28, 2018

Thanks for adding these details Laubender​, i did check what you mentioned. In light of this i think renaming the swatches would be a better option with more control, unless the OP has something to add that we might be missing.

-Manan

Translate
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 29, 2018 Dec 29, 2018

A "+" for the unnamed swatches is that they can keep the swatch panel clean for frequently used swatches.

Case 1:

You have a long document and frequently use 3 swatches but on one page use 50 which you don't plan one using again.

Case 2:

You have a really lot of 1 off colors, performance will be severely affected because the swatch panel needs to be maintained. 

Translate
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 ,
Dec 30, 2018 Dec 30, 2018

Hi Trevor,

All valid and useful points mentioned by you and Uwe.

However the OP is planning to convert the swatches to unnamed swatches and then use "Add All Unnamed Colors" thus re adding them to the swatch. Which prompted the question as to what was the gain in this workflow, instead of just renaming the swatches with color values.

-Manan

Translate
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 ,
Dec 31, 2018 Dec 31, 2018

Perhaps there is no gain and the OP only knew of one (less than ideal) method to get to the desired goal?

Translate
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 ,
Dec 31, 2018 Dec 31, 2018

Hi Stephen,

so we need some feedback from the OP.

Regards,
Uwe

Translate
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 01, 2019 Jan 01, 2019

Hi Uwe, yes agreed, feedback from the OP is often required.

Translate
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
Enthusiast ,
Jan 02, 2019 Jan 02, 2019

Hi Legends,

Thank you for your valuable feedback.

And sorry for the delayed response.

Request:

Find Hexa value for all swatches, for that am converting all swatches into RGB.

Problem faced:

If the swatches having the tint value, am not able to get the Hexa value.

Screen Shot 2019-01-02 at 5.00.09 PM.png

Screen Shot 2019-01-02 at 5.00.05 PM.png

For the tint swatch issue, am go through the below ways:

1. delete all swatches into unnamed swatch

2. Later, invoke the All Unnamed Colors

Below Code is developed so far,

1. Clean unused swatches

2. Convert all color to RGB

3. Invoke unnamed colors
4. RGB to Hexa value

5. TINT swatch (not able to find hexa value)

var myDoc = app.activeDocument;

//clean unused swatches

//convert cmyk to rgb

app.activeDocument.colors.everyItem().properties = {

    space: ColorSpace.RGB

};

//add all unnamed color to swatches

app.menuActions.itemByName("$ID/Add All Unnamed Colors").invoke(); 

var mySwatches = myDoc.swatches;

if (mySwatches.length > 4) {

    for (s = 4; s < mySwatches.length; s++) {

        var _swatchName = mySwatches.name + "";

        //--------------Start convert rgb to hex--------------

        var _mySwatchColorValue = mySwatches.colorValue;

        var _R = _mySwatchColorValue[0];

        var _G = _mySwatchColorValue[1];

        var _B = _mySwatchColorValue[2];

        var myHex = rgbToHex(_R, _G, _B);

        //alert(myHex);

    }

}

function rgbToHex(red, green, blue) {

    var rgb = blue | (green << 8) | (red << 16);

    //alert("rgb: "  + rgb)

    return '#' + (0x1000000 + rgb).toString(16).slice(1)

}

Thanks

Translate
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 02, 2019 Jan 02, 2019
LATEST

Hi,

I don't have too much experience with colors and color conversions but i am still not clear about the workflow you are trying.

If the issue is getting Hex value of the color, i still don't understand the need to delete swatches and then adding unnamed colors to swatches. Can't this be done as follows

  • Convert all Swatches to RGB using something like the following code

for(var i = 0; i < app.activeDocument.swatches.length; i++)

     try{

          app.activeDocument.swatches.space = ColorSpace.RGB

     }catch(e){}

  • Now to obtain the hex value for each swatch, you already have the written the code in your sample.
  • For the issue with getting hex value for Swatches with tint, i don't think the hex value changes even after applying tint to a swatch(on InDesign UI i see that the RGB value does not change). Alternatively you could take out the new RGB values w.r.t the percentage of tint and then calculate the hex values.

Hope this helps

-Manan

Translate
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