Swatch name change script
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Swatch name change script
Tagged: CC, colour, InDesign, swatch rename
- This topic has 9 replies, 3 voices, and was last updated 2 months ago by David Blatner.
-
AuthorPosts
-
-
December 8, 2015 at 7:13 am #80009Nilesh ParmarMember
I have loads of RGB colours in my swatches from time to time and then i use a script to convert RGB to CMYK which works fine, but, the names are still rgb in the swatch panel. To correct these with their values, i have to double click each one and check the box that says’Name with Colour Value’. Does anyone know of any script to batch this process? Any help would be appreciate it. Thanks in advance. Using Indesign CC 2014 (10.)
Nilesh
-
December 16, 2015 at 10:22 am #80243Keith GilbertParticipant
This should do it, Nilesh. Note that this script snippet assumes that all the swatches are CMYK already:
var myDoc = app.activeDocument;
var mySwatches = myDoc.swatches;
for (var s = mySwatches.length-1; s >= 0; s--) {
var mySwatch = myDoc.swatches[s];
var name = mySwatch.name;
if (name != ""){
try {
var myColorValueArray = mySwatch.colorValue;
mySwatch.name = "C="+Math.round(myColorValueArray[0])+" M="+Math.round(myColorValueArray[1])+" Y="+Math.round(myColorValueArray[2])+" K="+Math.round(myColorValueArray[3]);
}
catch(myerror) {
}
}
}
-
December 17, 2015 at 2:18 am #80255Nilesh ParmarMember
Thanks for that, I’m getting errors. My colour for testing to change was c22m30y20k0, i was expecting it to change to C=22 M=30 Y=20 K=0
The error code is this
Javascript Error!
Error Number:23
Error String: = does not have a valueEngine: main
File: /User (location)
Line:3
SourceL for (var s = mySwatches.length-1; s >:= 0; s –) {
Offending Text: =Hope you can help and merry christmas to you :)
-
December 17, 2015 at 5:48 am #80261Keith GilbertParticipant
Hi Nilesh: A couple of thoughts:
1. copy/pasting JavaScript code isn’t always reliable…sometimes special characters change during copy/paste to the forum, etc. You can download a zipped copy of the script here https://gilbertconsulting.filecamp.com/public/file/257r-5i208rjn and then unzip the script and install it.
2. This script is just a quick snippet. In other words, it doesn’t have any error checking built in. There might be some circumstances I haven’t thought of that would cause an error. Test the script on a simple, new file that contains just a couple of new swatches you’ve created. See if it works there, and then start testing it on more difficult files.
-
December 18, 2015 at 8:44 am #80293Nilesh ParmarMember
That worked great on a blank document for testing. Thank you so much for this. Appreciate it. I will test this throughly in January when i have a lot of files to process, so will let you know how that goes.
-
June 28, 2018 at 1:34 am #104617Kristy FowlesMember
Hi There
Just to piggy-back onto the swatch renaming issue..
I have a number of swatches I wish to bulk rename, but I only wish to rename part of them. Eg. I want to rename anything with the name “gradient” in the swatch name to now be “grad”, so, for example BackgroundGradient01 would become BackgroundGrad01, HeaderGradient01 would become HeaderGrad01. Doing this manually is making me cry. xDTo add to this, actual gradients shouldn’t have their name changed, only swatches which contain the name gradient, but aren’t actually a gradient themselves. :/
A script with the option to do “all” swatches would be useful for future however, however one that leaves actual gradients lone is what I need at this time.
Do any of you code gurus have any idea how to do this?
The documentation on Adobe InDesign JSX seems somewhat limited.Any help would be much appreciated,
Kristy -
June 28, 2018 at 1:38 am #104618Kristy FowlesMember
Additional comment added in error, seems there is only a reply and edit, but no delete option here. :?
<or I’ve just been manually renaming swatches for too long now and my observation skills are waning> -
December 4, 2020 at 8:40 am #14333245Alican OzturkParticipant
var myDoc = app.activeDocument;
var mySwatches = myDoc.colors;
for (var s = mySwatches.length-1; s >= 0; s–) {
var mySwatch = myDoc.swatches[s];
var name = mySwatch.name;
if (name != “”){
try {
var myColorValueArray = mySwatch.colorValue;
mySwatch.name = “C=”+Math.round(myColorValueArray[0])+” M=”+Math.round(myColorValueArray[1])+” Y=”+Math.round(myColorValueArray[2])+” K=”+Math.round(myColorValueArray[3]);
}
catch(myerror) {
}
}
} -
January 18, 2024 at 1:21 pm #14399065Rombout VersluijsMember
@Keith Gilbert,
This script makes no sense. Its using code which doesnt even exist. First its app.actoveDocument.swatches
Than when you get each color component value, you need to know what component this is. It seems like this is a copy/paste from a complete different language, this is not ExtendScript-
January 18, 2024 at 1:39 pm #14399067David BlatnerKeymaster
Not sure what you mean, Rombout. The script works well… once you correct the bad characters. For example, curly quotes must change to straight quotes. And (this is annoying) you need to change the “—” en dash character in line 3 to two normal dashes.
I will see if I can fix Keith’s formatting above.
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.