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

fill color using a script.

Community Beginner ,
Apr 02, 2013 Apr 02, 2013

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

21.4K

Translate

Translate

Report

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 2 Correct answers

Community Expert , Apr 02, 2013 Apr 02, 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;

Votes

Translate

Translate
Community Expert , Apr 02, 2013 Apr 02, 2013

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();

Votes

Translate

Translate
Adobe
Community Beginner ,
Apr 02, 2013 Apr 02, 2013

Copy link to clipboard

Copied

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;

          };

Votes

Translate

Translate

Report

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 ,
Apr 02, 2013 Apr 02, 2013

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

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 ,
Apr 02, 2013 Apr 02, 2013

Copy link to clipboard

Copied

Thank you Larry for your fast response!!

Votes

Translate

Translate

Report

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 ,
Apr 02, 2013 Apr 02, 2013

Copy link to clipboard

Copied

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();

Votes

Translate

Translate

Report

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 ,
Apr 02, 2013 Apr 02, 2013

Copy link to clipboard

Copied

Thank you pixxxel schubser this is correct as well too bad I can't mark them both.

One question, how would one work with swatches when automating large batches of files?

Votes

Translate

Translate

Report

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 ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

bornmodern wrote:

… it fails to add color to this path but works well on the rectangle behind it, any suggestions?

Is this path a compound path item?

Please, show us every screenshot with layerpalette.

For your example try this:

var aDoc = app.activeDocument;

var col = new CMYKColor();

col.cyan = 100;

col.magenta = 0;

col.yellow = 0;

col.black = 0;

var FirstPath = aDoc.compoundPathItems[0].pathItems[0];

//FirstPath.filled = true;

FirstPath.fillColor = col;

redraw();

-----------------------------

And the other question:

bornmodern wrote:

… how would one work with swatches when automating large batches of files?

To writing a script needs much more informations about your workflow and your files.

(Sorry for my bad english)

Votes

Translate

Translate

Report

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 ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

Yes!!! it works, but of course the pathItem has to be located in the frontmost position.

As for the overall procedure, the palette is multicolored the action set is constructed to select a compound pathItem that sets upon a rectangle pathItem. So this procedure is pretty tricky and it has to identify between complex and not complex. It will then take that compound pathItem and change the color to the given CMYK values.

I only need a script that will change the pathItem of a path object that has been selected,(already selected based on the action I'm running) the other manipulations I can achieve through actions.

Votes

Translate

Translate

Report

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 ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

Unfortunately, google.translate isn't helpful here.

Please say it step by step.

e.g.

The script should:

open a folder with ai-files

run an action names: myAction

(result of action: a compound path is selected)???

"that will change the pathItem of a path"??? //changing color???

…

//some other stuff

Votes

Translate

Translate

Report

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 ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

These are the steps

1) the path will be selected using an action script.

2) while the path is selected - (I need javascript to change the selected path to the CMYK values.)  <------the script I need

pretty simple.

Illustrator knows what object to assign the CMYK values to because the path will already be selected.

Votes

Translate

Translate

Report

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 ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

Your script works, but it is assigning the cmyk values based on position of the object. For example if any object is in front it will be assigned the CMYK values. I want the object that is already selected (it will be selected because of the action script) to be assigned those values. It shouldn't function based on position.

Votes

Translate

Translate

Report

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 ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

I don't understand?

You've got everything you need - except a switch:

if (aDoc.selection != 0 && aDoc.selection[0].typename == "CompoundPathItem") {

   

    // your code

   

    } else {

        alert ("No selection or no CompoundPathItem selected")

        }

Votes

Translate

Translate

Report

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 ,
Apr 04, 2013 Apr 04, 2013

Copy link to clipboard

Copied

Thank you for your willingness to help I really appreciate your effort, your script works for what I'm attempting.

Thanks again for your time.

Votes

Translate

Translate

Report

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 ,
Apr 04, 2013 Apr 04, 2013

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

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 ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

pixxxel schubser

it seems not to be working for compound shapes, is there something you can do? I'm using mac os10.6.8

Votes

Translate

Translate

Report

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 ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

it fails to add color to this path but works well on the rectangle behind it, any suggestions?

Screen shot 2013-04-03 at 10.33.56 AM.png

Votes

Translate

Translate

Report

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