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

Color applied object change color

New Here ,
Mar 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

I wrote this code

But I am getting the error Why?

var findC = [

"C=100 M=0 Y=0 K=0",

"C=0 M=0 Y=100 K=0"

]

changeC = [

"C=15 M=100 Y=100 K=0",

"C=75 M=5 Y=100 K=0"

]

var doc = app.activeDocument; 

app.findObjectPreferences = app.changeObjectPreferences = null; 

for(var i = 0; i < findC.length; ++i) {

  

  

app.findObjectPreferences.fillColor = app.activeDocument.swatches.itemByName(findC);

app.changeObjectPreferences.fillColor =app.activeDocument.swatches.itemByName(changeC);

app.changeObject(); 

      }

app.findObjectPreferences = app.changeObjectPreferences = null; 

TOPICS
Scripting

Views

332

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 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

Hi,

would you like to tell what "the" error is?
And what line is throwing this?

Thanks,

Uwe

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 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

Hm.

Your code is missing at least one comma and at semicolon.

FWIW: I think, findObjectPreferences is broken with InDesign scripting.

There is at least one fundamental bug.

If I apply a color like "C=100 M=0 Y=0 K=0" to the fill property in the UI,

app.findObjectPreferences.fillColor returns an error.

The equivalent of: $ID/kScriptErrNotApplicable

In my German InDesign: "Diese Eigenschaft ist im aktuellen Status nicht zutreffend."


Tested with CS6 8.1.0 on OSX 10.6.8.

What is your exact version of InDesign and OS ?

Regards,
Uwe

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
New Here ,
Mar 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

I use İndesing CS6 and in windows10

This error:

Invalid value for cluster property "fillColor". Expected Swatch, String or NothingEnum enumerator but received Color

Line text:

app.findObjectPreferences.fillColor = app.activeDocument.swatches.itemByName(findC);

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 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

Seems to be a bug with InDesign's scripting engine.

You have to search without using findObject .

Get all the pageItems of the document and evaluate them one after another.

Perhaps you could use the document.allPageItems array. Beware that this array would not include page items in non-active states of MultiStateObjects (MSOs).


Write the results to an array or change the fillColor while looping.

Beware of pageItems where fillColor perhaps throw an exception.

Like the ones anchored in overset text.

Regards,
Uwe

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
New Here ,
Mar 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

This my code its run but

rectangle don't

var myDoc = app.activeDocument;

var pi = myDoc.allPageItems;

for(j = 0; j < pi.length; ++j) {

it = pi;

if(it && it instanceof TextFrame){      //   &&   rectangle ??

for(var k=0; k<findC.length; k++)  {

if(it.fillColor.name == findC){

it.fillColor = changeC;

}

}

}

}

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 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

This works for me also on rectangles:

var findC = [ "C=100 M=0 Y=0 K=0", "C=0 M=0 Y=100 K=0"];

var changeC = [ "C=15 M=100 Y=100 K=0", "C=75 M=5 Y=100 K=0"];

var doc = app.activeDocument; 

var pi = doc.allPageItems;

for (var j = 0; j < pi.length; ++j) {

    var it = pi;

    if (it.isValid && it instanceof Rectangle) {      //   &&   rectangle ??

                for(var k=0; k<findC.length; k++)  {

                    var curFindColor = findC;

                    var curChangeColor = changeC;

                    if (it.fillColor.name == curFindColor) {

                        it.fillColor = curChangeColor;

                    }

            }

        }

}

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 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

LATEST

Hi together,

the first thing I would do is to resolve the individual pageItem:

var it = pi.getElements()[0];

FWIW: Items where fillColor throws an error are images in RGB or CMYK color model.

Also other type of graphics. So prepare for them. Or use a try/catch wrapper.

Regards,
Uwe

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