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

How to define my color?

Contributor ,
Jun 14, 2016 Jun 14, 2016

Copy link to clipboard

Copied

Hi experts,

I have a script:

app.findObjectPreferences = null;

app.findObjectPreferences.fillColor = "MARKUP";

app.changeObjectPreferences.fillColor = "Black";

app.changeObject();

app.findObjectPreferences = null;

app.findObjectPreferences.strokeColor = "MARKUP";

app.changeObjectPreferences.strokeColor = "Black";

app.changeObject();

for find and change object color, but if the docs which has no such as color name in the swatch, the script will run into error, so, how can I define if no such as color, script continue? how can make the script as below working?

var myDoc = app.activeDocument;

myColor = myDoc.colors.name("MARKUP");

if (!cmyColor) continue;

app.findObjectPreferences = null;

app.findObjectPreferences.fillColor = myColor;

app.changeObjectPreferences.fillColor = "Black;

app.changeObject();

app.findObjectPreferences = null;

app.findObjectPreferences.strokeColor = myColor;

app.changeObjectPreferences.strokeColor = "Black";

app.changeObject();

thanks

Regard

John

TOPICS
Scripting

Views

1.0K

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

correct answers 1 Correct answer

Enthusiast , Jun 17, 2016 Jun 17, 2016

Here is an idea, that includes also the previous question "MARKUP, markup, MARK-UP, MARK_UP":

app.doScript(main, ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Replace Colors");

function main() {

var curDoc = app.activeDocument;

var allSwatches = curDoc.swatches;

var allPItems = curDoc.allPageItems;

var colorsToRemove = [];

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

  var curSwatch = allSwatches;

  var curSwatchName = curSwatch.name;

  var colorToFind = curSwatchName.search(/Mark[-_]?UP/i)

...

Votes

Translate

Translate
Contributor ,
Jun 14, 2016 Jun 14, 2016

Copy link to clipboard

Copied

Hi

you can fix some part of this script.

var myDoc = app.activeDocument; 

var myColor = myDoc.swatches.item("MARKUP");

if (!myColor.isValid){

  alert("NO SWATCH");

  exit();

}

now you can't exit if the document don't have 'MARKUP' swatch.

but this code wont work in my InDesign CC, I found same issue

[JS CS4] findObjectPreferences.fillColor error |Adobe Community https://forums.adobe.com/thread/583184

I very much regret to say I don't have any idea to solve this problem.

thank you

mg

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 ,
Jun 14, 2016 Jun 14, 2016

Copy link to clipboard

Copied

Thank you mg

so I changed it into like this:

var myDoc = app.activeDocument;

var myColor = myDoc.swatches.item("MARKUP");

if (!myColor.isValid){

alert("NO SWATCH");

exit();

}

app.findObjectPreferences = null;

app.findObjectPreferences.fillColor = myColor;

app.changeObjectPreferences.fillColor = "Black";

app.changeObject();

app.findObjectPreferences = null;

app.findObjectPreferences.strokeColor = myColor;

app.changeObjectPreferences.strokeColor = "Red";

app.changeObject();

but I got error.

How can I fix?

thanks

regard

John

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
Explorer ,
Jun 14, 2016 Jun 14, 2016

Copy link to clipboard

Copied

Hi John,

You can use try catch for this as follows..

try{

    app.findObjectPreferences = null; 

    app.findObjectPreferences.fillColor = "Markup1"; 

    app.changeObjectPreferences.fillColor = "Test"; 

    app.changeObject(); 

    }

   catch(err)

   {

        app.findObjectPreferences = null; 

        app.findObjectPreferences.strokeColor = "Markup"; 

        app.changeObjectPreferences.strokeColor = "Black"; 

        app.changeObject(); 

    }

Thanks and Regards

Ravindra

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 ,
Jun 15, 2016 Jun 15, 2016

Copy link to clipboard

Copied

Hi

I tested with following test-script on InDesign CS5/CC

CC partly works, CS5 not work for me.

findObjectPreferences.fillColor/strokeColor should be passed by `string`

var doc = app.activeDocument;

var c = doc.swatches.item("MARKUP");

  if (!c.isValid){

    alert("NO SWATCH");

    exit()

  }

 

// swatch index

var m = doc.swatches.itemByName("MARKUP").index;

var b = doc.swatches.item("Black").index;

$.writeln(app.version);

var props = ['strokeColor', 'fillColor'];

for (var i=0, len=props.length; i < len ; i++) {

  app.findObjectPreferences = NothingEnum.nothing;

  var prop = props;

 

  $.writeln(prop);

 

  // work for me in CC by string

  // not work in CS5 by string

  try {

    $.writeln(">> " + "MARKUP".constructor.name);

    app.findObjectPreferences[prop]   = "MARKUP";

    app.changeObjectPreferences[prop] = "Black";

    $.writeln("DONE!!");

  }

  catch(x_x){

    $.writeln([x_x.message,x_x.line,$.stack].join("\n"));

  }

  // not work by swatch index

  try {

    $.writeln(">> " + doc.swatches);

    $.writeln(">> " + doc.swatches.constructor.name);

    app.findObjectPreferences[prop] = doc.swatches;

    app.changeObjectPreferences[prop] = doc.swatches;

    $.writeln("DONE!!");

  }

  catch(x_x){

    $.writeln([x_x.message,x_x.line,$.stack].join("\n"));

  }

  // not work by swatch name

  try {

    $.writeln(">> " + doc.swatches.item("MARKUP"));

    $.writeln(">> " + doc.swatches.item("MARKUP").constructor.name);

    app.findObjectPreferences[prop] = doc.swatches.item("MARKUP");

    app.changeObjectPreferences[prop] = doc.swatches.item("Black");

    $.writeln("DONE!!");

  }

  catch(x_x){

    $.writeln([x_x.message,x_x.line,$.stack].join("\n"));

  }

  doc.changeObject();

};

thank you

mg.

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
Enthusiast ,
Jun 16, 2016 Jun 16, 2016

Copy link to clipboard

Copied

Hm! Doesn’t work here: 11.2.0.99, OS 10.9.5

Kai

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 ,
Jun 16, 2016 Jun 16, 2016

Copy link to clipboard

Copied

oh sorry!

tried again, doesn't work.

9.3.0.106

osx 10.9.5

I guess it worked after find object operating in GUI.

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 ,
Jun 15, 2016 Jun 15, 2016

Copy link to clipboard

Copied

Thank you Ravindra

I have tried, but not work.

thank you so much.

regard

John

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
Enthusiast ,
Jun 15, 2016 Jun 15, 2016

Copy link to clipboard

Copied

Does anybody get here a result?

app.findObjectPreferences.strokeColor = "Markup";

I tried it with swatch (not just the name) or color and get always an error!

It doesn’t also work, if I use the swatch by its index, instead of the name.

There were some posts in the forum about some bugs in CS 4/5, but it seems, that is broken in CC too?

Kai

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 ,
Jun 16, 2016 Jun 16, 2016

Copy link to clipboard

Copied

yes! not work.

John

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
Enthusiast ,
Jun 17, 2016 Jun 17, 2016

Copy link to clipboard

Copied

John, what’s the goal? Only "MARKUP" or, "Mark-up", "Mark_UP" … which kind of objects? Example!

If FC does’t work, loop through all objects and check, if your color = your Color.

Kai

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
Enthusiast ,
Jun 17, 2016 Jun 17, 2016

Copy link to clipboard

Copied

Here is an idea, that includes also the previous question "MARKUP, markup, MARK-UP, MARK_UP":

app.doScript(main, ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Replace Colors");

function main() {

var curDoc = app.activeDocument;

var allSwatches = curDoc.swatches;

var allPItems = curDoc.allPageItems;

var colorsToRemove = [];

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

  var curSwatch = allSwatches;

  var curSwatchName = curSwatch.name;

  var colorToFind = curSwatchName.search(/Mark[-_]?UP/i);

  if (colorToFind != -1) {

colorsToRemove.push(curSwatch.name);

  }

}

alert("Found color names:\r" + colorsToRemove.join("\r"));

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

  var curItem = allPItems;

  var fColorName = curItem.fillColor.name;

  var sColorName = curItem.strokeColor.name;

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

var curColorName = colorsToRemove;
if (fColorName == curColorName) {
  curItem.fillColor = "Black";
}
if (sColorName == curColorName) {
  curItem.strokeColor = "Black";

  }

}

}

btw: the syntax highlighting destroyed the code

Kai

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 ,
Jun 17, 2016 Jun 17, 2016

Copy link to clipboard

Copied

great!

thanks Kai

thank so much.

regard

John

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 10, 2023 Mar 10, 2023

Copy link to clipboard

Copied

LATEST

Hi all, I'm still seeing this bug in ID 18.2. I couldn't find the bug in uservoice, so I created one.

Please vote for it here.

- Mark

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