Copy link to clipboard
Copied
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();
Thanks in Advance
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Perhaps there is no gain and the OP only knew of one (less than ideal) method to get to the desired goal?
Copy link to clipboard
Copied
Hi Stephen,
so we need some feedback from the OP.
Regards,
Uwe
Copy link to clipboard
Copied
Hi Uwe, yes agreed, feedback from the OP is often required.
Copy link to clipboard
Copied
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.
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
Copy link to clipboard
Copied
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
for(var i = 0; i < app.activeDocument.swatches.length; i++)
try{
app.activeDocument.swatches.space = ColorSpace.RGB
}catch(e){}
Hope this helps
-Manan
Find more inspiration, events, and resources on the new Adobe Community
Explore Now