Copy link to clipboard
Copied
Hi everyone,
I'm trying to write a script that changes a swatch color of item 3 on page 1 only, but no luck. I'm getting this error "Object does not support hte property or method 'swatches'." Here's the code:
var doc= app.activeDocument;
var doc = doc.pages[0].pageItems.item(3).swatches.item("Turquoise RGB").remove("Purple RGB");
Can anyone help me?
Thanks,
Rogerio
Copy link to clipboard
Copied
You can change the fill color of the item with item.fillColor = app.activeDocument.swatches.itemByName("Purple RGB")
doc.swatches.itemByName("something").remove would delete the swatch from the document and replace all items colored by it by the passed argument in .remove
Copy link to clipboard
Copied
Hi @Rogerio5C09 , Also, a pageItem doesn’t have a swatches property. If the pageItem is something like a rectangle, you could set its fillColor— the 3rd page item would be pageItems[2] :
var doc= app.activeDocument;
var doc = doc.pages[0].pageItems[2].fillColor = "Turquoise RGB"
Copy link to clipboard
Copied
Not a scripted solution, but applying an Object Style to that element would allow one-point changes.
Copy link to clipboard
Copied
To put what @brian_p_dts said to your code. replace...
var doc = doc.pages[0].pageItems.item(3).swatches.item("Turquoise RGB").remove("Purple RGB");
with...
doc.pages.item(0).pageItems.item(3).fillColor = doc.swatches.itemByName("Turquoise RGB");
Copy link to clipboard
Copied
To put what @brian_p_dts said to your code. replace...
var doc = doc.pages[0].pageItems.item(3).swatches.item("Turquoise RGB").remove("Purple RGB");with...
doc.pages.item(0).pageItems.item(3).fillColor = doc.swatches.itemByName("Turquoise RGB");
By @John D Herzog
I think "pageItems.item(2).fillColor"?
Copy link to clipboard
Copied
I did. Fixing the other parts, I missed that one.
Copy link to clipboard
Copied
Hi everyone,
I'm trying to write a script that changes a swatch color of item 3 on page 1 only, [...]By @Rogerio5C09
But how do you know - or rather - how can you be sure that it will always be 3rd item?
And, as in your code you are referring to 1st page by [0] - same principle would be for the item - as per @rob day's code - [2] for 3rd item.
In JavaScript, 1st item have index "0".