Copier le lien dans le Presse-papiers
Copié
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
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)
...Copier le lien dans le Presse-papiers
Copié
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
Copier le lien dans le Presse-papiers
Copié
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
Copier le lien dans le Presse-papiers
Copié
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
Copier le lien dans le Presse-papiers
Copié
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.
Copier le lien dans le Presse-papiers
Copié
Hm! Doesn’t work here: 11.2.0.99, OS 10.9.5
Kai
Copier le lien dans le Presse-papiers
Copié
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.
Copier le lien dans le Presse-papiers
Copié
Thank you Ravindra
I have tried, but not work.
thank you so much.
regard
John
Copier le lien dans le Presse-papiers
Copié
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
Copier le lien dans le Presse-papiers
Copié
yes! not work.
John
Copier le lien dans le Presse-papiers
Copié
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
Copier le lien dans le Presse-papiers
Copié
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
Copier le lien dans le Presse-papiers
Copié
great!
thanks Kai
thank so much.
regard
John
Copier le lien dans le Presse-papiers
Copié
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
Trouvez plus d’idées, d’événements et de ressources dans la nouvelle communauté Adobe
Explorer maintenant