Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

InDesign Scripting

Community Beginner ,
Feb 05, 2019 Feb 05, 2019

Is there a way to use scripts to set the CMYK value of a color swatch? Say I have a swatch named "Color 1," can I use scripts to set the CMYK (or RGB) values for that swatch?

TOPICS
Scripting
879
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Feb 07, 2019 Feb 07, 2019

app.activeDocument.colors.item("Primary").colorValue = [0,51,160];

Found this to be the correct answer. Where "Primary" is the swatch name and [0,51,160] are the RGB values

Translate
Enthusiast ,
Feb 05, 2019 Feb 05, 2019

A color (swatch) has the following properties:

color value: RGB values in range 0-255, CMYK values from 0 to 100, or LAB L (values from 0 to 100), A (-128 to 127, and B(-128 to 127)

model: spot, process, registration, or mixedinkmodel

space (RGB, CMYK, LAB, or MixedInk

To create a swatch or change an existing swatch you can use the following with AppleScript:

set swatchName to "Blue"

tell application "Adobe InDesign CC 2019"

   set docRef to document 1

   tell docRef

      if not (exists swatch swatchName) then

         set myColor to make color with properties {name:swatchName, moodel:process, space:CMYK, color value:{100, 50, 0, 0}}

      else

         set myColor to swatch swatchName

         set properties of myColor to {moodel:process, space:CMYK, color value:{100, 50, 0, 0}}

      end if

      --to check that color was created correctly

      get properties of swatch swatchName

   end tell

end tell

Note that in the example above the document is creating the swatch. If the application creates the swatch (without tell/end tell to docRef) the color will be effective for all documents created thereafter.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2019 Feb 05, 2019

If you want to run the code on Windows environment you can try the following.

var color = app.documents[0].swatches.itemByName("Color1")

if(color.isValid)

{

     if(color.space == ColorSpace.CMYK)

          color.colorValue = [10,10,10,10] //Replace with the values you want

     else if(color.space == ColorSpace.RGB)

          color.colorValue = [23,12,23] //Replace with the values you want

}

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 07, 2019 Feb 07, 2019
LATEST

app.activeDocument.colors.item("Primary").colorValue = [0,51,160];

Found this to be the correct answer. Where "Primary" is the swatch name and [0,51,160] are the RGB values

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines