3 Replies Latest reply on Sep 4, 2009 2:22 PM by [Jongware]

    [JS] CS4 - Convert all spots to process

    Danny Noonan

      I have what is probably a very simple question. How do I get a script to convert any of the Swatches Spot colors to CMYK?

      Any help would be huge. . .

        • 1. Re: [JS] CS4 - Convert all spots to process
          [Jongware] Most Valuable Participant

          Simple -- you ask someone :-)

          for (c=0; c<app.activeDocument.colors.length; c++)
          if (app.activeDocument.colors[c].model == ColorModel.SPOT)
           app.activeDocument.colors[c].model = ColorModel.PROCESS;
          

          This javascript checks all colors in your document, and it only changes the ones that are defined as SPOT to process.

          Usually I would go for

           

          app.activeDocument.colors.everyItem().model = ColorModel.PROCESS;

           

          but it seems not every color has a model (??) or can be converted to Process (perhaps the built-ins Black,Paper, etc. mess things up).

          • 2. Re: [JS] CS4 - Convert all spots to process
            Danny Noonan Level 1

            Awesome, thanks Jongware. I was way off.

            I'm in the learning stage of writing JS. How do you know when to use "colors" instead of "swatches" or even "inks"?

             

            Thanks again Jongware, that makes my day...

            • 3. Re: [JS] CS4 - Convert all spots to process
              [Jongware] Most Valuable Participant

              How indeed.

              InDesign doesn't work with 'colors' by default; if you use a spot or process color, it gets added to the Swatch panel. Now, one way to reliably iterate over all swatch items is using 'everyItem' -- a very handy function, which I'm using more and more instead of looping over an object array. It's description is not that useful ("Returns every Xxx in the collection" -- how? what do you get?) so, usually I just try.

               

              It didn't work because the spot/process property is just found in "Color" (under the name "model") -- not in Swatches and Inks. At first I tried to sneak around this, using a try..catch (so InDesign picks up the error and continues on the next line) and then with 'hasOwnProperty('model'). Fortunately, you can loop over just the colors.

               

              It's just a matter of trying the first thing you come up with and reading the unavoidable error message very carefully :-)

               

              Are you by any chance working with a Windows machine? My own version of the Javascript help (found here) also displays parent/child relations in a graphic form, and that's quite often useful. (Windows, because for the Mac I only have it as HTML.)