Alex Buisse
My feedback
3 results found
-
2 votes
An error occurred while saving the comment An error occurred while saving the comment
Alex Buisse
commented
Thank you Sergey. The issue here seems to be with manipulating the selection, specifically the line
app.activeDocument.selection = [item.obj];
If I remove that line, the script runs fine, though of course doesn't actually do the color replacement I am after. I have tried all sorts of shenanigans to get around the issue, even sending the instructions asynchronously through BridgeTalk, but keep hitting the issue.
I might downgrade to a 2025 version for now, just so I can keep working, as this script is essential to my work.
Edit: ok, I can confirm that the script works in 30.0 and breaks in 30.1/30.2.
An error occurred while saving the comment
Alex Buisse
commented
Yes, they are shifted here too, it must be from when I deleted a bunch of extraneous layers when exporting the test file. This doesn't seem to be linked to the issue at hand.
I first encountered the error message at the beginning of February, but I don't know where to check when Illustrator did its updates, sorry.
I am not entirely surprised that it would run correctly on a different architecture, since switching to CPU rendering has (at times) solved the issue (though not with this particular file). I am surprised it took so long for you, it usually runs in a couple of seconds at most when it does work.
An error occurred while saving the comment
Alex Buisse
commented
And I guess the attachment in the first comment was deleted. Here it is again.
An error occurred while saving the comment
Alex Buisse
commented
Ah sorry, it was the script that should be renamed to .txt. Here it is an attachment as well, in case that's easier.
An error occurred while saving the comment
Alex Buisse
commented
Here is the script in plain text, and as attachment in the next comment. The issue is with the last few lines.
var doc = app.activeDocument;
var routes = doc.layers["lines"].layers["routes"];
var numbers = doc.layers["lines"].layers["numbers"];function CMYKtoRGB (color) {
try {
var rgb = app.convertSampleColor(ImageColorSpace.CMYK, [Math.round(color.cyan), Math.round(color.magenta), Math.round(color.yellow), Math.round(color.black)], ImageColorSpace.RGB, ColorConvertPurpose.defaultpurpose);
var col = new RGBColor();
col.red = rgb[0];
col.green = rgb[1];
col.blue = rgb[2];
return col;
} catch (e) {alert("Wrong color: " + color)}
}// Calculate relative brightness per https://contrastchecker.online/color-relative-luminance-calculator
function WCAGBrightness (col) {
try {
var r2, r3, g2, g3, b2, b3;
r2 = col.red/255;
g2 = col.green/255;
b2 = col.blue/255
if (r2 <= 0.04045) {
r3 = r2/12.92;
} else {
r3 = Math.pow(((r2 + 0.055)/1.055), 2.4);
}
if (g2 <= 0.04045) {
g3 = g2/12.92;
} else {
g3 = Math.pow(((g2 + 0.055)/1.055), 2.4);
}
if (b2 <= 0.04045) {
b3 = b2/12.92;
} else {
b3 = Math.pow(((b2 + 0.055)/1.055), 2.4);
}
//alert("[" + String(r3) + ", " + String(g3) + ", " + String(b3) + "]");
return ((0.2126 * r3) + (0.7152 * g3) + (0.0722 * b3));
} catch (e) {alert("Wrong color: " + col)}
}// Looks in route list for ID and then stroke color
function findCol(targetID) {
for (var fk = 0; fk < routes.layers.length; fk++) {
for (var fi = 0; fi < routes.layers[fk].pageItems.length; fi++) {
var fname = routes.layers[fk].pageItems[fi].name;
var fids = fname.match("^([0-9]+): ");
if (fids != null) {
var fid = Number(fids[1]);
if (fid == targetID) { return routes.layers[fk].pageItems[fi].strokeColor; }
}
}
for (var fi = 0; fi < routes.layers[fk].layers.length; fi++) {
var fname = routes.layers[fk].layers[fi].name;
var fids = fname.match("^([0-9]+): ");
if (fids != null) {
var fid = Number(fids[1]);
if (fid == targetID) { return routes.layers[fk].layers[fi].pageItems[0].strokeColor; }
}
}
}
return null;
}// Pre-fetch all data before any selection manipulation
var itemsToProcess = [];
for (var n = 0; n < numbers.pageItems.length; n++) {
var obj = numbers.pageItems[n];
var id = Number(obj.contents);
var newCol = findCol(id);
if (newCol == null) { continue; }
var b = WCAGBrightness(CMYKtoRGB(newCol));
var col = new RGBColor();
if (b > 0.4) {
col.red = 0; col.green = 0; col.blue = 0;
} else {
col.red = 255; col.green = 255; col.blue = 255;
}
itemsToProcess.push({obj: obj, col: col, newCol: newCol});
}// Now apply all changes - document access only for selection trick
for (var i = 0; i < itemsToProcess.length; i++) {
var item = itemsToProcess[i];
item.obj.textRange.fillColor = item.col;
app.activeDocument.selection = [item.obj];
app.activeDocument.defaultFillColor = item.newCol;}
alert("All done!");
Alex Buisse
shared this idea
·
-
4 votes
Alex Buisse
shared this idea
·
-
2 votes
An error occurred while saving the comment
Alex Buisse
commented
I have the exact same issue with Illustrator 27.1.1 and macOS 13.1. I have some outdated Type 1 fonts which I am trying to replace, and as soon as I try to get a system font, the Find/Replace Font dialog keeps beachballing until I force quit the whole application.
Alex Buisse
supported this idea
·
Thank you for investigating. I also feel like it went from happening every now and then on 30.1, and being occasionally solved by switching to CPU preview, to happening on every file in 30.2 (and not happening at all in 30.0). The lack of consistent reproducibility makes it annoying to investigate indeed.
I will try upgrading to 30.2 again and checking your solution with the selection property.