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.
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;
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();
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;
};
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;
Copy link to clipboard
Copied
Thank you Larry for your fast response!!
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();
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?
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)
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.
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
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.
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.
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")
}
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.
Copy link to clipboard
Copied
You're welcome
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
Copy link to clipboard
Copied
it fails to add color to this path but works well on the rectangle behind it, any suggestions?