Swatch name change script

Viewing 8 reply threads
  • Author
    Posts
    • #80009

      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

    • #80243
      Keith Gilbert
      Participant

      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) {
      }
      }
      }

    • #80255

      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 value

      Engine: main
      File: /User (location)
      Line:3
      SourceL for (var s = mySwatches.length-1; s &gt:= 0; s –) {
      Offending Text: =

      Hope you can help and merry christmas to you :)

    • #80261
      Keith Gilbert
      Participant

      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.

    • #80293

      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.

    • #104617

      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. xD

      To 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

    • #104618

      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>

    • #14333245
      Alican Ozturk
      Participant

      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) {
      }
      }
      }

    • #14399065

      @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

      • #14399067
        David Blatner
        Keymaster

        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.

Viewing 8 reply threads
  • You must be logged in to reply to this topic.
>
Notice: We use cookies on our websites to give you a great online experience. If you keep browsing, we'll assume you're ok with this. For more information, see our privacy policy. By closing this banner, you agree to the use of cookies.I AGREENo