Copy link to clipboard
Copied
hi
I need a script for 2 parts
Copy link to clipboard
Copied
Are you looking for help writing a script or are you looking for someone to write a script for you?
Copy link to clipboard
Copied
the second one - but I thougt many people need this and its alrady done 😞
Copy link to clipboard
Copied
So you don't need the script anymore?
That's fine. But if this script worked for you, could you please mark it as correct so that it may help someone searching for the same question in the future?
Copy link to clipboard
Copied
no, sorry, the script don't work.
Copy link to clipboard
Copied
What result did you get when you tried this script?
Copy link to clipboard
Copied
the swatch is renamed and has a new value
but all objects of the graphic lost the swatch
Copy link to clipboard
Copied
Oh yes.. I suppose it wouldn't have. You asked how to change the name and value of a swatch, not update the colors of any item that uses that color. It is a much much larger undertaking to update the colors in the document. You can't simply change a swatch, you actually have to loop the pageItems and check for the desired color and change the fillColor attribute to the new swatch.
Copy link to clipboard
Copied
function changeSwatch()
{
var docRef = app.activeDocument;
var swatches = docRef.swatches;
var theSwatch = swatches["colorname1"];
theSwatch.name = "colorname2";
var swatchColor = new RGBColor();
swatchColor.red = 0;
swatchColor.green = 80;
swatchColor.blue = 200;
theSwatch.color = swatchColor;
theSwatch.red = 0;
theSwatch.green = 80;
theSwatch.blue = 200;
}
changeSwatch();
Copy link to clipboard
Copied
if the colors were set as global, and objects painted with them, you could easily change the colors using the script provided.
Copy link to clipboard
Copied
when you use the UI to make the change, this is true. However if you use javascript to change the properties of a swatch, it is not applied globally to all objects that have that global swatch applied.
the only way to do this is to loop all the pageItems and change the fillColor property conditionally like so:
var docRef = app.activedocument
var newSwatch = new RGBColor();
newSwatch.red = 0;
newSwatch.green = 80;
newSwatch.blue = 200;
var oldSwatch = docRef.swatches["oldSwatch"];
var oldSwatchName = "oldSwatch";
var items = docRef.pageItems;
for(var a=0;a<items.length;a++)
{
if(items.fillColor.spot.name == oldSwatchName)
{
}
}
The problem with this is that if you have any groups or compound paths, this won't work. It's much more involved because you need recursive loops to dig to the bottom of each group and compound path to compare every pathItem to find out whether the color needs to be changed.
It's not impossible, but it is much more involved than you think.
Copy link to clipboard
Copied
… and some other problems remains:
You have no access to additional fill or stroke colors (which are added in the appereance palette).
And what is if the color isn't RGB ?
And what is with colors in symbols ?
And …
Copy link to clipboard
Copied
indeed.
it seems like this would be really easy if....
ADOBE WOULD FRIGGING GIVE JAVASCRIPT ACCESS TO THE MERGE SWATCHES FUNCTION!!!!!!!!
i hope you're listening, adobe.. though i know you're not.
Copy link to clipboard
Copied
… and a very long-cherished wish of many users: /* is this the correct wording in english? */
Shortcuts for scripts
and, and, and:
Copy link to clipboard
Copied
It's OK for global swatch, the problem is his swatch just not global I think.
And if for this purpose only, instead of script, using "recolor artwork" menu is more easy?
function changeSwatch() {
var theSwatch = activeDocument.swatches["colorname1"];
if (theSwatch.color.typename === 'SpotColor' ) {
theSwatch.name = "colorname2";
var swatchColor = new RGBColor();
swatchColor.red = 0;
swatchColor.green = 80;
swatchColor.blue = 200;
var s = theSwatch.color.spot;
s.color = swatchColor;
s.sportKind = SpotColorKind.SPOTRGB;
};
}
changeSwatch();
Copy link to clipboard
Copied
thanks to you all.
I have dissolved the problem with "actions".
I take colornames with an "_" at the end. at the end of the action I use a script to delete the "_".
so I can map 1000ends of motifs without one click.