Swatch name change script

This topic contains 6 replies, has 3 voices, and was last updated by  Kristy Fowles 3 weeks, 3 days ago.

  • 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

    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

    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

    • This reply was modified 3 weeks, 3 days ago by  Kristy Fowles. Reason: Additional info
  • #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>

    • This reply was modified 3 weeks, 3 days ago by  Kristy Fowles. Reason: Comment not required

You must be logged in to reply to this topic.