Skip to main content
Inspiring
February 5, 2026
Answered

script : an Illustrator error occurred: 1346458189 ('MRAP')

  • February 5, 2026
  • 1 reply
  • 23 views

Hello everyone,

to match whether swatch contains a spot color. I'm getting the following error. This error doesn't happen often, it only occurs occasionally. Could it be because I'm processing too many files, or the file processing is too fast? How can I avoid this? thanks


error: an Illustrator error occurred: 1346458189 ('MRAP')


var bordColor = ['color1', 'color2', 'color3', 'color4']; 

checkFrameSpotColor(bordColor);


function checkFrameSpotColor(bordColor) {
    var foundBorderColor = false;
    var swatchList = doc.swatches;
    if (!swatchList || swatchList.length <= 0) {
        throw new Error("Unable to obtain color swatches");
    }    
    var currentSwatch;
    var currentSwatchName;
    var isTargetName;
    for (var i = swatchList.length - 1; i >= 0; i--) {
        $.sleep(200);
        try {
            currentSwatch = swatchList[i];
            currentSwatchName = currentSwatch.name; // The error point is usually here.
            isTargetName = false;
            for (var j = 0; j < bordColor.length; j++) {
                if (currentSwatchName === bordColor[j]) {
                    isTargetName = true;
                    break;
                }
            }
            if (isTargetName) {
                if (currentSwatch.color && currentSwatch.color.typename == "SpotColor") {
                    foundBorderColor = true;
                    break;
                }
            }
        } catch (e) {
            continue; 
        }
    }

    if (!foundBorderColor) {
        throw new Error("Please confirm if the frame stroke color is a spot color.");
    }
}

    Correct answer CarlosCanto

    Instead of going through all swatches, why not search for them?

     

    var bordColor = ['color1', 'color2', 'color3', 'color4']; 

    checkFrameSpotColor(bordColor);


    function checkFrameSpotColor(bordColor) {
    var doc = app.activeDocument;
    var foundBorderColor = false;
    var currentSwatchName, foundBorderColor;

    for (var j = 0; j < bordColor.length; j++) {
    currentSwatchName = bordColor[j];

    try {
    foundBorderColor = doc.swatches.getByName(currentSwatchName);
    alert ("Swatch named '" + currentSwatchName + "' found in the document.");

    alert("Found swatch typename: " + foundBorderColor.color.typename);
    break;
    }
    catch (e) {
    alert ("Swatch named '" + currentSwatchName + "' not found in the document.");
    }
    }

    }

     

    1 reply

    CarlosCanto
    Community Expert
    CarlosCantoCommunity ExpertCorrect answer
    Community Expert
    February 5, 2026

    Instead of going through all swatches, why not search for them?

     

    var bordColor = ['color1', 'color2', 'color3', 'color4']; 

    checkFrameSpotColor(bordColor);


    function checkFrameSpotColor(bordColor) {
    var doc = app.activeDocument;
    var foundBorderColor = false;
    var currentSwatchName, foundBorderColor;

    for (var j = 0; j < bordColor.length; j++) {
    currentSwatchName = bordColor[j];

    try {
    foundBorderColor = doc.swatches.getByName(currentSwatchName);
    alert ("Swatch named '" + currentSwatchName + "' found in the document.");

    alert("Found swatch typename: " + foundBorderColor.color.typename);
    break;
    }
    catch (e) {
    alert ("Swatch named '" + currentSwatchName + "' not found in the document.");
    }
    }

    }

     

    rui huangAuthor
    Inspiring
    February 5, 2026

    “Instead of going through all swatches” is a good idea, thank you.