Skip to main content
Inspiring
June 8, 2026
Answered

loadColorSettings breaks script in newer version of illustrator (29+)

  • June 8, 2026
  • 1 reply
  • 47 views

My script starts with changing the color settings in a file using loadColorSettings. Immediately after that, it starts processing the file. In version 28, the script works fine. Starting from ver 29 (also tried with 30, same issue), the script breaks after loadColorSettings. app.activeDocument becomes empty and i get the error “There is no document”. What could be causing this?

try {
var Lvis =[];
var LP=-1;
var $doc = app.activeDocument;
var dot = $doc.name.lastIndexOf('.');
var newName= $doc.name.substring(0, dot);
bpc_Color_Settings= new File(Folder.userData+"/Adobe/Color/Settings/ISO%20Coated%20v2%20(ECI)-sRGB_bpc.csf");
tmp_Color_Settings = new File(Folder.userData+"/Adobe/Color/Settings/ISO%20Coated%20v2%20(ECI)-sRGB.csf");
if(bpc_Color_Settings.exists) loadColorSettings(bpc_Color_Settings);
else alert_w("Color Setting for BPC not found!","Error");

//The below loop does not start, because app.activeDocument is empty = "there is no document" error
for (j = 0; j < app.activeDocument.layers.length; j++)
//more code happening here
}

catch(e) {
alert_w(e.message,"Error");
// alert( e.message, "Script Alert", true);
}

 

Correct answer Mrprintalot

@jduncan I ran both codes in isolation and the error occured. But i found the solution. Resetting all preferences made the script work again. Not sure what exactly was the cause of this, but deleting the settings folder and re-applying all my custom settings and files again made the script work.

1 reply

jduncan
Community Expert
Community Expert
June 8, 2026

Hey, I just removed the non-essential stuff, the `$` from the start of the doc variable, and added `app` to the `loadColorSettings` method call and all works for me on Ai v30.5.1.

try {
var doc = app.activeDocument;

var colorSettingsFile = new File(
Folder.userData + "/Adobe/Color/Settings/ISO Coated v2 (ECI)-sRGB.csf"
);

var bpc_Color_Settings = new File(
Folder.userData + "/Adobe/Color/Settings/ISO Coated v2 (ECI)-sRGB_bpc.csf"
);

if (bpc_Color_Settings.exists) {
colorSettingsFile = bpc_Color_Settings;
}

app.loadColorSettings(colorSettingsFile);

for (var j = 0; j < doc.layers.length; j++) {
$.writeln(doc.layers[j].name);
}
} catch (e) {
$.writeln(e);
}

For what it’s worth, I would probably wrap this entire thing in a custom function like below.

function loadBpcColorProfile() {
if (!app.documents.length) {
alert("No active document.");
return;
}

var doc = app.activeDocument;

var defaultColorSettings = new File(
Folder.userData + "/Adobe/Color/Settings/ISO%20Coated%20v2%20(ECI)-sRGB.csf"
);

var bpcColorSettings = new File(
Folder.userData + "/Adobe/Color/Settings/ISO%20Coated%20v2%20(ECI)-sRGB_bpc.csf"
);

var colorSettingsFile = bpcColorSettings.exists
? bpcColorSettings
: defaultColorSettings;

if (!colorSettingsFile.exists) {
alert("Color settings file not found:\n" + colorSettingsFile.fsName);
return;
}

app.loadColorSettings(colorSettingsFile);

for (var i = 0; i < doc.layers.length; i++) {
var layer = doc.layers[i];

// Do something with each layer here
$.writeln(layer.name);
}
}

Try these out and let me know if they work for you? Cheers!

Inspiring
June 9, 2026

Thanks! In both the cases, i still get the same error, “there is no document”. I also tried re-obtaining the app.document variable, but it also did not work.

jduncan
Community Expert
Community Expert
June 9, 2026

Did you run the code I sent by itself (in isolation) or did you run it along with other code? I assume this is just part of a larger script. If you run it in isolation there really is nothing that should cause you to loose reference to the active document. If there is more code that you can share, drop it here and we’ll have a look.