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

Change color of a particular item in the doc

Contributor ,
Mar 08, 2024 Mar 08, 2024

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

TOPICS
Scripting

Views

184

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 ,
Mar 08, 2024 Mar 08, 2024

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

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 ,
Mar 08, 2024 Mar 08, 2024

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"

 

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 ,
Mar 08, 2024 Mar 08, 2024

Copy link to clipboard

Copied

Not a scripted solution, but applying an Object Style to that element would allow one-point changes.


┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋

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
Contributor ,
Mar 08, 2024 Mar 08, 2024

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

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 ,
Mar 08, 2024 Mar 08, 2024

Copy link to clipboard

Copied

quote

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"?

 

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
Contributor ,
Mar 08, 2024 Mar 08, 2024

Copy link to clipboard

Copied

LATEST

I did. Fixing the other parts, I missed that one.

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 ,
Mar 08, 2024 Mar 08, 2024

Copy link to clipboard

Copied

quote

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".

 

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