Skip to main content
Known Participant
April 2, 2013
Answered

fill color using a script.

  • April 2, 2013
  • 1 reply
  • 23299 views

I'm trying to create a script in CS5 mac os10.6.8 that will change the fill color of selected pathItems. I need a simple script that will change a selected pathItem to cmyk values 2,3,15,0. I will then select this script and implement the action in a batch of 600 files.

I wish this process could be recorded as an action but when I record the action "add new swatch" I have to manually input the cmyk values, which will take forever for a batch of over 600 files.

This topic has been closed for replies.
Correct answer pixxxelschubser

It's really better, to work with swatches.

If you work without swatches, then try it e.g. like this:

var aDoc = app.activeDocument;

var col = new CMYKColor();

col.cyan = 100;

col.magenta = 0;

col.yellow = 0;

col.black = 0;

var FirstPath = aDoc.selection[0]; // a pathItem must be selected before running the script

//FirstPath.filled = true;

FirstPath.fillColor = col;

redraw();

1 reply

Known Participant
April 2, 2013

This is what I came up with by pulling from different sources but without any knowledge of javascript, it does not work at all

function colorDoc( file ) {

          var  col;

          col = cmykColor( 2, 3,15,0 );

          doc.pathItems.fillColor = col;

          };

Larry G. Schneider
Community Expert
Community Expert
April 2, 2013

This works in CS6.

var docRef = app.activeDocument;

var  col;

var col = new CMYKColor();

col.cyan = 2;

col.magenta = 3;

col.yellow = 15;

col.black = 0;

// Create the new swatch using the above color

var swatch = docRef.swatches.add();

swatch.color = col;

swatch.name = "col";

// Apply the swatch to a new path item

var pathRef = docRef.pathItems[0];

pathRef.filled = true;

pathRef.fillColor = swatch.color;

Known Participant
April 3, 2013

Thank you Larry for your fast response!!