Skip to main content
Participating Frequently
July 13, 2023
Answered

PARM error with .jsx

  • July 13, 2023
  • 4 replies
  • 8078 views

Hi, I am getting "An Illustrator error occurred: 1346458189 ('PARM')" while executing script in illustrator. I am generating random collection of unique arts, the attached script is basically randomly picking between 6 different arts, then its picking if art should be color or gradient and every time its picking the next color from the list at the beginning, then its picking if background should be color or gradient and picking the order of the colors.

This topic has been closed for replies.
Correct answer m1b

Hi @A819434, I've tested your script (sorry I didn't notice you had already attached it) and I noticed a problem similar to the one you described. I believe the problem relates to memory management. Illustrator has always been a bit poor at this aspect of scripting, and its errors often aren't very helpful, but we can often work around the limitations by changing the structure of the script.

 

I've made an attempt at structural changes to your script designed to improve performance and memory usage. The big change I made was to open all the art files once, just keeping them open the whole time, and closing them at the end. I keep track of the documents (and their background layers and background rectangles) in the "docs" variable. I moved the color creation in a function called "getColors" just so I could put it to the end of the script because it was so long. I doubt this change has any bearing on performance. I also restructured the colors so you can more easily see the color breakdowns—this was just a style thing, not anything to do with performance. In general I sharpened up some of your references so you always know what you are referring to, and moved variables around a little to make scope clearer and avoid repetition. But the big thing is probably keeping the documents open the whole time. I also switch to outline mode which sometimes speeds things up a lot.

 

After these changes, the script ran until completion for me. Let me know how it goes for you.

- Mark

 

/**
 * Variation on user @A819434's script to
 * try to improve memory management.
 * @discussion https:// community.adobe.com/t5/illustrator-discussions/parm-error-with-jsx/m-p/13935106
 */
(function () {

    // store all colors in this object
    var colors = getColors();

    var artFiles = [
        'King',
        'Queen',
        'Rook',
        'Bishop',
        'Knight',
        'Pawn',
    ];

    var pathToArt = '~/Desktop/save as ai/';
    var pathToText = '~/Desktop/ChessText/';
    var pathToExport = '~/Desktop/ChessNFT/';

    // variablesStart
    var i = 1;
    var a = 2;
    var b = 728;
    var c = 1;
    // variablesEnd

    // open art files
    var doc,
        docs = {},
        backgroundLayer,
        backgroundRectangle;
    for (var i = 0; i < artFiles.length; i++) {
        doc = (app.open(File(pathToArt + artFiles[i] + '.ai')));
        backgroundLayer = doc.layers.add();
        // outline view might speed things up
        app.executeMenuCommand('preview');
        // add the background layer and rectangle
        backgroundLayer.name = "Background";
        backgroundLayer.color = colors['BackgroundLayer'];
        backgroundLayer.printable = false;
        backgroundLayer.zOrder(ZOrderMethod.SENDTOBACK);
        backgroundRectangle = backgroundLayer.pathItems.rectangle(0, 0, 1080, 1080);
        backgroundRectangle.stroked = false;

        // store the docs
        docs[artFiles[i]] = {
            doc: doc,
            backgroundLayer: backgroundLayer,
            backgroundRectangle: backgroundRectangle,
        };
    }

    for (var e = 0; e < 488; e++) {

        var name,
            type,
            // this will hold text to write to file
            text = [];

        var random_1 = Math.floor(Math.random() * 105); // 0-104_105
        if (random_1 < 5) { // 0-4_5
            name = 'King';
            type = 0;
        }
        else if (random_1 < 15) { // 5-14_10
            name = 'Queen';
            type = 0;
        }
        else if (random_1 < 30) { // 15-29_15
            name = 'Rook';
            type = 0;
        }
        else if (random_1 < 50) { // 30-49_20
            name = 'Bishop'
            type = 0;
        }
        else if (random_1 < 75) { // 50-74_25
            name = 'Knight'
            type = 1;
        }
        else if (random_1 < 105) { // 75-104_30
            name = 'Pawn'
            type = 0;
        }
        text.push(name);
        doc = docs[name].doc;
        backgroundLayer = docs[name].backgroundLayer;
        backgroundRectangle = docs[name].backgroundRectangle;

        if (i == 126 && b == 365 && a == 365) {
            alert("finished");
            return;
        }

        // colorStart
        var random_3 = Math.floor(Math.random() * 100); // 0-99_100
        if (random_3 < 25) { // 0-24_25
            if (i == 126) {
                var colorGradient = doc.gradients.add();
                // colorGradient.name = "GradientArt1";
                colorGradient.type = GradientType.LINEAR;
                colorGradient.gradientStops[0].color = colors['color_' + a];
                colorGradient.gradientStops[1].color = colors['color_' + b];
                var gradientColor = new GradientColor();
                gradientColor.gradient = colorGradient;
                for (var x = 0; x < doc.pathItems.length; x++) {
                    doc.pathItems[x].fillColor = gradientColor;
                }
                a++;
                b--;
                text.push('Gradient');
            }
            else {
                for (var x = 0; x < doc.pathItems.length; x++) {
                    doc.pathItems[x].fillColor = colors['color_' + i];
                }
                i++;
                text.push('Colour');
            }
        }
        else if (random_3 < 100) { // 25-99_75
            if (b == 365 && a == 365) {
                for (var x = 0; x < doc.pathItems.length; x++) {
                    doc.pathItems[x].fillColor = colors['color_' + i];
                }
                i++;
                text.push('Colour');
            }
            else {
                var colorGradient = app.activeDocument.gradients.add();
                // colorGradient.name = "GradientArt2";
                colorGradient.type = GradientType.LINEAR;
                colorGradient.gradientStops[0].color = colors['gradient_' + a];
                colorGradient.gradientStops[1].color = colors['gradient_' + b];
                var gradientColor = new GradientColor();
                gradientColor.gradient = colorGradient;
                for (var x = 0; x < doc.pathItems.length; x++) {
                    doc.pathItems[x].fillColor = gradientColor;
                }
                a++;
                b--;
                text.push('Gradient');
            }
        }
        if (type = 1 && doc.pathItems.length > 20) {
            doc.pathItems[0].filled = false;
            doc.pathItems[1].filled = false;
            doc.pathItems[2].filled = false;
            doc.pathItems[3].filled = false;
            doc.pathItems[4].filled = false;
            doc.pathItems[5].filled = false;
            doc.pathItems[6].filled = false;
            doc.pathItems[7].filled = false;
            doc.pathItems[8].filled = false;
            doc.pathItems[9].filled = false;
            type = 0;
        }
        type = 0;
        // colorEnd
        // backgroundStart
        var theGradient,
            backgroundColor;
        var colorRandom = Math.floor(Math.random() * 6); // 0-5_6
        var random_2 = Math.floor(Math.random() * 100); // 0-99_100
        if (random_2 < 10 && random_2 > -1) { // 0-9_10
            theGradient = doc.gradients.add();
            // theGradient.name = "Gradient_1";
            theGradient.type = GradientType.LINEAR;
            theGradient.gradientStops.add();
            theGradient.gradientStops[0].rampPoint = 0;
            theGradient.gradientStops[1].rampPoint = 50;
            theGradient.gradientStops[2].rampPoint = 100;
            if (colorRandom == 0) {
                theGradient.gradientStops[0].color = colors.red;
                theGradient.gradientStops[1].color = colors.green;
                theGradient.gradientStops[2].color = colors.blue;
            }
            else if (colorRandom == 1) {
                theGradient.gradientStops[0].color = colors.blue;
                theGradient.gradientStops[1].color = colors.red;
                theGradient.gradientStops[2].color = colors.green;
            }
            else if (colorRandom == 2) {
                theGradient.gradientStops[0].color = colors.green;
                theGradient.gradientStops[1].color = colors.blue;
                theGradient.gradientStops[2].color = colors.red;
            }
            else if (colorRandom == 3) {
                theGradient.gradientStops[0].color = colors.green;
                theGradient.gradientStops[1].color = colors.red;
                theGradient.gradientStops[2].color = colors.blue;
            }
            else if (colorRandom == 4) {
                theGradient.gradientStops[0].color = colors.blue;
                theGradient.gradientStops[1].color = colors.green;
                theGradient.gradientStops[2].color = colors.red;
            }
            else if (colorRandom == 5) {
                theGradient.gradientStops[0].color = colors.red;
                theGradient.gradientStops[1].color = colors.blue;
                theGradient.gradientStops[2].color = colors.green;
            }
            backgroundColor = new GradientColor();
            backgroundColor.gradient = theGradient;
            backgroundRectangle.fillColor = backgroundColor;
            text.push('RGB');
        }
        else if (random_2 < 40) { // 10-39_30
            theGradient = doc.gradients.add();
            // theGradient.name = "Gradient_2";
            theGradient.type = GradientType.LINEAR;
            theGradient.gradientStops.add();
            theGradient.gradientStops[0].rampPoint = 0;
            theGradient.gradientStops[1].rampPoint = 50;
            theGradient.gradientStops[2].rampPoint = 100;
            if (colorRandom == 0) {
                theGradient.gradientStops[0].color = colors.yellow;
                theGradient.gradientStops[1].color = colors.cyan;
                theGradient.gradientStops[2].color = colors.magenta;
            }
            else if (colorRandom == 1) {
                theGradient.gradientStops[0].color = colors.magenta;
                theGradient.gradientStops[1].color = colors.yellow;
                theGradient.gradientStops[2].color = colors.cyan;
            }
            else if (colorRandom == 2) {
                theGradient.gradientStops[0].color = colors.cyan;
                theGradient.gradientStops[1].color = colors.magenta;
                theGradient.gradientStops[2].color = colors.yellow;
            }
            else if (colorRandom == 3) {
                theGradient.gradientStops[0].color = colors.cyan;
                theGradient.gradientStops[1].color = colors.yellow;
                theGradient.gradientStops[2].color = colors.magenta;
            }
            else if (colorRandom == 4) {
                theGradient.gradientStops[0].color = colors.magenta;
                theGradient.gradientStops[1].color = colors.cyan;
                theGradient.gradientStops[2].color = colors.yellow;
            }
            else if (colorRandom == 5) {
                theGradient.gradientStops[0].color = colors.yellow;
                theGradient.gradientStops[1].color = colors.magenta;
                theGradient.gradientStops[2].color = colors.cyan;
            }
            backgroundColor = new GradientColor();
            backgroundColor.gradient = theGradient;
            backgroundRectangle.fillColor = backgroundColor;
            text.push('YCM');
        }
        else if (random_2 < 100) { // 40-99_60
            theGradient = doc.gradients.add();
            // theGradient.name = "Gradient_3";
            theGradient.type = GradientType.LINEAR;
            theGradient.gradientStops[0].rampPoint = 0;
            theGradient.gradientStops[1].rampPoint = 100;
            if (colorRandom == 0) {
                theGradient.gradientStops[0].color = colors.white;
                theGradient.gradientStops[1].color = colors.black;
            }
            else if (colorRandom == 1) {
                theGradient.gradientStops[0].color = colors.white;
                theGradient.gradientStops[1].color = colors.black;
            }
            else if (colorRandom == 2) {
                theGradient.gradientStops[0].color = colors.white;
                theGradient.gradientStops[1].color = colors.black;
            }
            else if (colorRandom == 3) {
                theGradient.gradientStops[0].color = colors.black;
                theGradient.gradientStops[1].color = colors.white;
            }
            else if (colorRandom == 4) {
                theGradient.gradientStops[0].color = colors.black;
                theGradient.gradientStops[1].color = colors.white;
            }
            else if (colorRandom == 5) {
                theGradient.gradientStops[0].color = colors.black;
                theGradient.gradientStops[1].color = colors.white;
            }
            backgroundColor = new GradientColor();
            backgroundColor.gradient = theGradient;
            backgroundRectangle.fillColor = backgroundColor;
            text.push('BW');
        }
        // backgroundEnd

        // make folders
        if (!Folder(pathToText).exists) Folder(pathToText).create();
        if (!Folder(pathToExport).exists) Folder(pathToExport).create();

        // textStart
        var textFile = new File(pathToText + c + '.txt');

        textFile.open("w", "TEXT", "????");
        textFile.encoding = "UTF-8"; // Encode

        textFile.write(text.join('\n'));

        textFile.close();
        // textEnd

        // exportStart
        AntiAliasingMethod.ARTOPTIMIZED = true;
        doc.exportFile(File(pathToExport + c + '.png'), ExportType.PNG24);
        c++;
        // exportEnd

        // alert("next");
        // $.writeln('e = ' + e);

    }

    // close art files
    for (var key in docs) {
        docs[key].doc.close(SaveOptions.DONOTSAVECHANGES);
    }

})();



function getColors() {

    var colors = {
        // colors1Start
        black: [0, 0, 0],
        white: [255, 255, 255],
        red: [255, 0, 0],
        green: [0, 255, 0],
        blue: [0, 0, 255],
        yellow: [255, 255, 0],
        cyan: [0, 255, 255],
        magenta: [255, 0, 255],
        // colors2Start
        color_1: [0, 0, 0],
        color_2: [0, 0, 64],
        color_3: [0, 0, 128],
        color_4: [0, 0, 192],
        color_5: [0, 0, 255],
        color_6: [0, 64, 0],
        color_7: [0, 64, 64],
        color_8: [0, 64, 128],
        color_9: [0, 64, 192],
        color_10: [0, 64, 255],
        color_11: [0, 128, 0],
        color_12: [0, 128, 64],
        color_13: [0, 128, 128],
        color_14: [0, 128, 192],
        color_15: [0, 128, 255],
        color_16: [0, 192, 0],
        color_17: [0, 192, 64],
        color_18: [0, 192, 128],
        color_19: [0, 192, 192],
        color_20: [0, 192, 255],
        color_21: [0, 255, 0],
        color_22: [0, 255, 64],
        color_23: [0, 255, 128],
        color_24: [0, 255, 192],
        color_25: [0, 255, 255],
        color_26: [64, 0, 0],
        color_27: [64, 0, 64],
        color_28: [64, 0, 128],
        color_29: [64, 0, 192],
        color_30: [64, 0, 255],
        color_31: [64, 64, 0],
        color_32: [64, 64, 64],
        color_33: [64, 64, 128],
        color_34: [64, 64, 192],
        color_35: [64, 64, 255],
        color_36: [64, 128, 0],
        color_37: [64, 128, 64],
        color_38: [64, 128, 128],
        color_39: [64, 128, 192],
        color_40: [64, 128, 255],
        color_41: [64, 192, 0],
        color_42: [64, 192, 64],
        color_43: [64, 192, 128],
        color_44: [64, 192, 192],
        color_45: [64, 192, 255],
        color_46: [64, 255, 0],
        color_47: [64, 255, 64],
        color_48: [64, 255, 128],
        color_49: [64, 255, 192],
        color_50: [64, 255, 255],
        color_51: [128, 0, 0],
        color_52: [128, 0, 64],
        color_53: [128, 0, 128],
        color_54: [128, 0, 192],
        color_55: [128, 0, 255],
        color_56: [128, 64, 0],
        color_57: [128, 64, 64],
        color_58: [128, 64, 128],
        color_59: [128, 64, 192],
        color_60: [128, 64, 255],
        color_61: [128, 128, 0],
        color_62: [128, 128, 64],
        color_63: [128, 128, 128],
        color_64: [128, 128, 192],
        color_65: [128, 128, 255],
        color_66: [128, 192, 0],
        color_67: [128, 192, 64],
        color_68: [128, 192, 128],
        color_69: [128, 192, 192],
        color_70: [128, 192, 255],
        color_71: [128, 255, 0],
        color_72: [128, 255, 64],
        color_73: [128, 255, 128],
        color_74: [128, 255, 192],
        color_75: [128, 255, 255],
        color_76: [192, 0, 0],
        color_77: [192, 0, 64],
        color_78: [192, 0, 128],
        color_79: [192, 0, 192],
        color_80: [192, 0, 255],
        color_81: [192, 64, 0],
        color_82: [192, 64, 64],
        color_83: [192, 64, 128],
        color_84: [192, 64, 192],
        color_85: [192, 64, 255],
        color_86: [192, 128, 0],
        color_87: [192, 128, 64],
        color_88: [192, 128, 128],
        color_89: [192, 128, 192],
        color_90: [192, 128, 255],
        color_91: [192, 192, 0],
        color_92: [192, 192, 64],
        color_93: [192, 192, 128],
        color_94: [192, 192, 192],
        color_95: [192, 192, 255],
        color_96: [192, 255, 0],
        color_97: [192, 255, 64],
        color_98: [192, 255, 128],
        color_99: [192, 255, 192],
        color_100: [192, 255, 255],
        color_101: [255, 0, 0],
        color_102: [255, 0, 64],
        color_103: [255, 0, 128],
        color_104: [255, 0, 192],
        color_105: [255, 0, 255],
        color_106: [255, 64, 0],
        color_107: [255, 64, 64],
        color_108: [255, 64, 128],
        color_109: [255, 64, 192],
        color_110: [255, 64, 255],
        color_111: [255, 128, 0],
        color_112: [255, 128, 64],
        color_113: [255, 128, 128],
        color_114: [255, 128, 192],
        color_115: [255, 128, 255],
        color_116: [255, 192, 0],
        color_117: [255, 192, 64],
        color_118: [255, 192, 128],
        color_119: [255, 192, 192],
        color_120: [255, 192, 255],
        color_121: [255, 255, 0],
        color_122: [255, 255, 64],
        color_123: [255, 255, 128],
        color_124: [255, 255, 192],
        color_125: [255, 255, 255],
        // colors3Start
        gradient_1: [0, 0, 0],
        gradient_2: [0, 0, 32],
        gradient_3: [0, 0, 64],
        gradient_4: [0, 0, 96],
        gradient_5: [0, 0, 128],
        gradient_6: [0, 0, 160],
        gradient_7: [0, 0, 192],
        gradient_8: [0, 0, 224],
        gradient_9: [0, 0, 255],
        gradient_10: [0, 32, 0],
        gradient_11: [0, 32, 32],
        gradient_12: [0, 32, 64],
        gradient_13: [0, 32, 96],
        gradient_14: [0, 32, 128],
        gradient_15: [0, 32, 160],
        gradient_16: [0, 32, 192],
        gradient_17: [0, 32, 224],
        gradient_18: [0, 32, 255],
        gradient_19: [0, 64, 0],
        gradient_20: [0, 64, 32],
        gradient_21: [0, 64, 64],
        gradient_22: [0, 64, 96],
        gradient_23: [0, 64, 128],
        gradient_24: [0, 64, 160],
        gradient_25: [0, 64, 192],
        gradient_26: [0, 64, 224],
        gradient_27: [0, 64, 255],
        gradient_28: [0, 96, 0],
        gradient_29: [0, 96, 32],
        gradient_30: [0, 96, 64],
        gradient_31: [0, 96, 96],
        gradient_32: [0, 96, 128],
        gradient_33: [0, 96, 160],
        gradient_34: [0, 96, 192],
        gradient_35: [0, 96, 224],
        gradient_36: [0, 96, 255],
        gradient_37: [0, 128, 0],
        gradient_38: [0, 128, 32],
        gradient_39: [0, 128, 64],
        gradient_40: [0, 128, 96],
        gradient_41: [0, 128, 128],
        gradient_42: [0, 128, 160],
        gradient_43: [0, 128, 192],
        gradient_44: [0, 128, 224],
        gradient_45: [0, 128, 255],
        gradient_46: [0, 160, 0],
        gradient_47: [0, 160, 32],
        gradient_48: [0, 160, 64],
        gradient_49: [0, 160, 96],
        gradient_50: [0, 160, 128],
        gradient_51: [0, 160, 160],
        gradient_52: [0, 160, 192],
        gradient_53: [0, 160, 224],
        gradient_54: [0, 160, 255],
        gradient_55: [0, 192, 0],
        gradient_56: [0, 192, 32],
        gradient_57: [0, 192, 64],
        gradient_58: [0, 192, 96],
        gradient_59: [0, 192, 128],
        gradient_60: [0, 192, 160],
        gradient_61: [0, 192, 192],
        gradient_62: [0, 192, 224],
        gradient_63: [0, 192, 255],
        gradient_64: [0, 224, 0],
        gradient_65: [0, 224, 32],
        gradient_66: [0, 224, 64],
        gradient_67: [0, 224, 96],
        gradient_68: [0, 224, 128],
        gradient_69: [0, 224, 160],
        gradient_70: [0, 224, 192],
        gradient_71: [0, 224, 224],
        gradient_72: [0, 224, 255],
        gradient_73: [0, 255, 0],
        gradient_74: [0, 255, 32],
        gradient_75: [0, 255, 64],
        gradient_76: [0, 255, 96],
        gradient_77: [0, 255, 128],
        gradient_78: [0, 255, 160],
        gradient_79: [0, 255, 192],
        gradient_80: [0, 255, 224],
        gradient_81: [0, 255, 255],
        gradient_82: [32, 0, 0],
        gradient_83: [32, 0, 32],
        gradient_84: [32, 0, 64],
        gradient_85: [32, 0, 96],
        gradient_86: [32, 0, 128],
        gradient_87: [32, 0, 160],
        gradient_88: [32, 0, 192],
        gradient_89: [32, 0, 224],
        gradient_90: [32, 0, 255],
        gradient_91: [32, 32, 0],
        gradient_92: [32, 32, 32],
        gradient_93: [32, 32, 64],
        gradient_94: [32, 32, 96],
        gradient_95: [32, 32, 128],
        gradient_96: [32, 32, 160],
        gradient_97: [32, 32, 192],
        gradient_98: [32, 32, 224],
        gradient_99: [32, 32, 255],
        gradient_100: [32, 64, 0],
        gradient_101: [32, 64, 32],
        gradient_102: [32, 64, 64],
        gradient_103: [32, 64, 96],
        gradient_104: [32, 64, 128],
        gradient_105: [32, 64, 160],
        gradient_106: [32, 64, 192],
        gradient_107: [32, 64, 224],
        gradient_108: [32, 64, 255],
        gradient_109: [32, 96, 0],
        gradient_110: [32, 96, 32],
        gradient_111: [32, 96, 64],
        gradient_112: [32, 96, 96],
        gradient_113: [32, 96, 128],
        gradient_114: [32, 96, 160],
        gradient_115: [32, 96, 192],
        gradient_116: [32, 96, 224],
        gradient_117: [32, 96, 255],
        gradient_118: [32, 128, 0],
        gradient_119: [32, 128, 32],
        gradient_120: [32, 128, 64],
        gradient_121: [32, 128, 96],
        gradient_122: [32, 128, 128],
        gradient_123: [32, 128, 160],
        gradient_124: [32, 128, 192],
        gradient_125: [32, 128, 224],
        gradient_126: [32, 128, 255],
        gradient_127: [32, 160, 0],
        gradient_128: [32, 160, 32],
        gradient_129: [32, 160, 64],
        gradient_130: [32, 160, 96],
        gradient_131: [32, 160, 128],
        gradient_132: [32, 160, 160],
        gradient_133: [32, 160, 192],
        gradient_134: [32, 160, 224],
        gradient_135: [0, 160, 255],
        gradient_136: [32, 192, 0],
        gradient_137: [32, 192, 32],
        gradient_138: [32, 192, 64],
        gradient_139: [32, 192, 96],
        gradient_140: [32, 192, 128],
        gradient_141: [32, 192, 160],
        gradient_142: [32, 192, 192],
        gradient_143: [32, 192, 224],
        gradient_144: [32, 192, 255],
        gradient_145: [32, 224, 0],
        gradient_146: [32, 224, 32],
        gradient_147: [32, 224, 64],
        gradient_148: [32, 224, 96],
        gradient_149: [32, 224, 128],
        gradient_150: [32, 224, 160],
        gradient_151: [32, 224, 192],
        gradient_152: [32, 224, 224],
        gradient_153: [32, 224, 255],
        gradient_154: [32, 255, 0],
        gradient_155: [32, 255, 32],
        gradient_156: [32, 255, 64],
        gradient_157: [32, 255, 96],
        gradient_158: [32, 255, 128],
        gradient_159: [32, 255, 160],
        gradient_160: [32, 255, 192],
        gradient_161: [32, 255, 224],
        gradient_162: [32, 255, 255],
        gradient_163: [64, 0, 0],
        gradient_164: [64, 0, 32],
        gradient_165: [64, 0, 64],
        gradient_166: [64, 0, 96],
        gradient_167: [64, 0, 128],
        gradient_168: [64, 0, 160],
        gradient_169: [64, 0, 192],
        gradient_170: [64, 0, 224],
        gradient_171: [64, 0, 255],
        gradient_172: [64, 32, 0],
        gradient_173: [64, 32, 32],
        gradient_174: [64, 32, 64],
        gradient_175: [64, 32, 96],
        gradient_176: [64, 32, 128],
        gradient_177: [64, 32, 160],
        gradient_178: [64, 32, 192],
        gradient_179: [64, 32, 224],
        gradient_180: [64, 32, 255],
        gradient_181: [64, 64, 0],
        gradient_182: [64, 64, 32],
        gradient_183: [64, 64, 64],
        gradient_184: [64, 64, 96],
        gradient_185: [64, 64, 128],
        gradient_186: [64, 64, 160],
        gradient_187: [64, 64, 192],
        gradient_188: [64, 64, 224],
        gradient_189: [64, 64, 255],
        gradient_190: [64, 96, 0],
        gradient_191: [64, 96, 32],
        gradient_192: [64, 96, 64],
        gradient_193: [64, 96, 96],
        gradient_194: [64, 96, 128],
        gradient_195: [64, 96, 160],
        gradient_196: [64, 96, 192],
        gradient_197: [64, 96, 224],
        gradient_198: [64, 96, 255],
        gradient_199: [64, 128, 0],
        gradient_200: [64, 128, 32],
        gradient_201: [64, 128, 64],
        gradient_202: [64, 128, 96],
        gradient_203: [64, 128, 128],
        gradient_204: [64, 128, 160],
        gradient_205: [64, 128, 192],
        gradient_206: [64, 128, 224],
        gradient_207: [64, 128, 255],
        gradient_208: [64, 160, 0],
        gradient_209: [64, 160, 32],
        gradient_210: [64, 160, 64],
        gradient_211: [64, 160, 96],
        gradient_212: [64, 160, 128],
        gradient_213: [64, 160, 160],
        gradient_214: [64, 160, 192],
        gradient_215: [64, 160, 224],
        gradient_216: [64, 160, 255],
        gradient_217: [64, 192, 0],
        gradient_218: [64, 192, 32],
        gradient_219: [64, 192, 64],
        gradient_220: [64, 192, 96],
        gradient_221: [64, 192, 128],
        gradient_222: [64, 192, 160],
        gradient_223: [64, 192, 192],
        gradient_224: [64, 192, 224],
        gradient_225: [64, 192, 255],
        gradient_226: [64, 224, 0],
        gradient_227: [64, 224, 32],
        gradient_228: [64, 224, 64],
        gradient_229: [64, 224, 96],
        gradient_230: [64, 224, 128],
        gradient_231: [64, 224, 160],
        gradient_232: [64, 224, 192],
        gradient_233: [64, 224, 224],
        gradient_234: [64, 224, 255],
        gradient_235: [64, 255, 0],
        gradient_236: [64, 255, 32],
        gradient_237: [64, 255, 64],
        gradient_238: [64, 255, 96],
        gradient_239: [64, 255, 128],
        gradient_240: [64, 255, 160],
        gradient_241: [64, 255, 192],
        gradient_242: [64, 255, 224],
        gradient_243: [64, 255, 255],
        gradient_244: [96, 0, 0],
        gradient_245: [96, 0, 32],
        gradient_246: [96, 0, 64],
        gradient_247: [96, 0, 96],
        gradient_248: [96, 0, 128],
        gradient_249: [96, 0, 160],
        gradient_250: [96, 0, 192],
        gradient_251: [96, 0, 224],
        gradient_252: [96, 0, 255],
        gradient_253: [96, 32, 0],
        gradient_254: [96, 32, 32],
        gradient_255: [96, 32, 64],
        gradient_256: [96, 32, 96],
        gradient_257: [96, 32, 128],
        gradient_258: [96, 32, 160],
        gradient_259: [96, 32, 192],
        gradient_260: [96, 32, 224],
        gradient_261: [96, 32, 255],
        gradient_262: [96, 64, 0],
        gradient_263: [96, 64, 32],
        gradient_264: [96, 64, 64],
        gradient_265: [96, 64, 96],
        gradient_266: [96, 64, 128],
        gradient_267: [96, 64, 160],
        gradient_268: [96, 64, 192],
        gradient_269: [96, 64, 224],
        gradient_270: [96, 64, 255],
        gradient_271: [96, 96, 0],
        gradient_272: [96, 96, 32],
        gradient_273: [96, 96, 64],
        gradient_274: [96, 96, 96],
        gradient_275: [96, 96, 128],
        gradient_276: [96, 96, 160],
        gradient_277: [96, 96, 192],
        gradient_278: [96, 96, 224],
        gradient_279: [96, 96, 255],
        gradient_280: [96, 128, 0],
        gradient_281: [96, 128, 32],
        gradient_282: [96, 128, 64],
        gradient_283: [96, 128, 96],
        gradient_284: [96, 128, 128],
        gradient_285: [96, 128, 160],
        gradient_286: [96, 128, 192],
        gradient_287: [96, 128, 224],
        gradient_288: [96, 128, 255],
        gradient_289: [96, 160, 0],
        gradient_290: [96, 160, 32],
        gradient_291: [96, 160, 64],
        gradient_292: [96, 160, 96],
        gradient_293: [96, 160, 128],
        gradient_294: [96, 160, 160],
        gradient_295: [96, 160, 192],
        gradient_296: [96, 160, 224],
        gradient_297: [96, 160, 255],
        gradient_298: [96, 192, 0],
        gradient_299: [96, 192, 32],
        gradient_300: [96, 192, 64],
        gradient_301: [96, 192, 96],
        gradient_302: [96, 192, 128],
        gradient_303: [96, 192, 160],
        gradient_304: [96, 192, 192],
        gradient_305: [96, 192, 224],
        gradient_306: [96, 192, 255],
        gradient_307: [96, 224, 0],
        gradient_308: [96, 224, 32],
        gradient_309: [96, 224, 64],
        gradient_310: [96, 224, 96],
        gradient_311: [96, 224, 128],
        gradient_312: [96, 224, 160],
        gradient_313: [96, 224, 192],
        gradient_314: [96, 224, 224],
        gradient_315: [96, 224, 255],
        gradient_316: [96, 255, 0],
        gradient_317: [96, 255, 32],
        gradient_318: [96, 255, 64],
        gradient_319: [96, 255, 96],
        gradient_320: [96, 255, 128],
        gradient_321: [96, 255, 160],
        gradient_322: [96, 255, 192],
        gradient_323: [96, 255, 224],
        gradient_324: [96, 255, 255],
        gradient_325: [128, 0, 0],
        gradient_326: [128, 0, 32],
        gradient_327: [128, 0, 64],
        gradient_328: [128, 0, 96],
        gradient_329: [128, 0, 128],
        gradient_330: [128, 0, 160],
        gradient_331: [128, 0, 192],
        gradient_332: [128, 0, 224],
        gradient_333: [128, 0, 255],
        gradient_334: [128, 32, 0],
        gradient_335: [128, 32, 32],
        gradient_336: [128, 32, 64],
        gradient_337: [128, 32, 96],
        gradient_338: [128, 32, 128],
        gradient_339: [128, 32, 160],
        gradient_340: [128, 32, 192],
        gradient_341: [128, 32, 224],
        gradient_342: [128, 32, 255],
        gradient_343: [128, 64, 0],
        gradient_344: [128, 64, 32],
        gradient_345: [128, 64, 64],
        gradient_346: [128, 64, 96],
        gradient_347: [128, 64, 128],
        gradient_348: [128, 64, 160],
        gradient_349: [128, 64, 192],
        gradient_350: [128, 64, 224],
        gradient_351: [128, 64, 255],
        gradient_352: [128, 96, 0],
        gradient_353: [128, 96, 32],
        gradient_354: [128, 96, 64],
        gradient_355: [128, 96, 96],
        gradient_356: [128, 96, 128],
        gradient_357: [128, 96, 160],
        gradient_358: [128, 96, 192],
        gradient_359: [128, 96, 224],
        gradient_360: [128, 96, 255],
        gradient_361: [128, 128, 0],
        gradient_362: [128, 128, 32],
        gradient_363: [128, 128, 64],
        gradient_364: [128, 128, 96],
        gradient_365: [128, 128, 128],
        gradient_366: [128, 128, 160],
        gradient_367: [128, 128, 192],
        gradient_368: [128, 128, 224],
        gradient_369: [128, 128, 255],
        gradient_370: [128, 160, 0],
        gradient_371: [128, 160, 32],
        gradient_372: [128, 160, 64],
        gradient_373: [128, 160, 96],
        gradient_374: [128, 160, 128],
        gradient_375: [128, 160, 160],
        gradient_376: [128, 160, 192],
        gradient_377: [128, 160, 224],
        gradient_378: [128, 160, 255],
        gradient_379: [128, 192, 0],
        gradient_380: [128, 192, 32],
        gradient_381: [128, 192, 64],
        gradient_382: [128, 192, 96],
        gradient_383: [128, 192, 128],
        gradient_384: [128, 192, 160],
        gradient_385: [128, 192, 192],
        gradient_386: [128, 192, 224],
        gradient_387: [128, 192, 255],
        gradient_388: [128, 224, 0],
        gradient_389: [128, 224, 32],
        gradient_390: [128, 224, 64],
        gradient_391: [128, 224, 96],
        gradient_392: [128, 224, 128],
        gradient_393: [128, 224, 160],
        gradient_394: [128, 224, 192],
        gradient_395: [128, 224, 224],
        gradient_396: [128, 224, 255],
        gradient_397: [128, 255, 0],
        gradient_398: [128, 255, 32],
        gradient_399: [128, 255, 64],
        gradient_400: [128, 255, 96],
        gradient_401: [128, 255, 128],
        gradient_402: [128, 255, 160],
        gradient_403: [128, 255, 192],
        gradient_404: [128, 255, 224],
        gradient_405: [128, 255, 255],
        gradient_406: [160, 0, 0],
        gradient_407: [160, 0, 32],
        gradient_408: [160, 0, 64],
        gradient_409: [160, 0, 96],
        gradient_410: [160, 0, 128],
        gradient_411: [160, 0, 160],
        gradient_412: [160, 0, 192],
        gradient_413: [160, 0, 224],
        gradient_414: [160, 0, 255],
        gradient_415: [160, 32, 0],
        gradient_416: [160, 32, 32],
        gradient_417: [160, 32, 64],
        gradient_418: [160, 32, 96],
        gradient_419: [160, 32, 128],
        gradient_420: [160, 32, 160],
        gradient_421: [160, 32, 192],
        gradient_422: [160, 32, 224],
        gradient_423: [160, 32, 255],
        gradient_424: [160, 64, 0],
        gradient_425: [160, 64, 32],
        gradient_426: [160, 64, 64],
        gradient_427: [160, 64, 96],
        gradient_428: [160, 64, 128],
        gradient_429: [160, 64, 160],
        gradient_430: [160, 64, 192],
        gradient_431: [160, 64, 224],
        gradient_432: [160, 64, 255],
        gradient_433: [160, 96, 0],
        gradient_434: [160, 96, 32],
        gradient_435: [160, 96, 64],
        gradient_436: [160, 96, 96],
        gradient_437: [160, 96, 128],
        gradient_438: [160, 96, 160],
        gradient_439: [160, 96, 192],
        gradient_440: [160, 96, 224],
        gradient_441: [160, 96, 255],
        gradient_442: [160, 128, 0],
        gradient_443: [160, 128, 32],
        gradient_444: [160, 128, 64],
        gradient_445: [160, 128, 96],
        gradient_446: [160, 128, 128],
        gradient_447: [160, 128, 160],
        gradient_448: [160, 128, 192],
        gradient_449: [160, 128, 224],
        gradient_450: [160, 128, 255],
        gradient_451: [160, 160, 0],
        gradient_452: [160, 160, 32],
        gradient_453: [160, 160, 64],
        gradient_454: [160, 160, 96],
        gradient_455: [160, 160, 128],
        gradient_456: [160, 160, 160],
        gradient_457: [160, 160, 192],
        gradient_458: [160, 160, 224],
        gradient_459: [160, 160, 255],
        gradient_460: [160, 192, 0],
        gradient_461: [160, 192, 32],
        gradient_462: [160, 192, 64],
        gradient_463: [160, 192, 96],
        gradient_464: [160, 192, 128],
        gradient_465: [160, 192, 160],
        gradient_466: [160, 192, 192],
        gradient_467: [160, 192, 224],
        gradient_468: [160, 192, 255],
        gradient_469: [160, 224, 0],
        gradient_470: [160, 224, 32],
        gradient_471: [160, 224, 64],
        gradient_472: [160, 224, 96],
        gradient_473: [160, 224, 128],
        gradient_474: [160, 224, 160],
        gradient_475: [160, 224, 192],
        gradient_476: [160, 224, 224],
        gradient_477: [160, 224, 255],
        gradient_478: [160, 255, 0],
        gradient_479: [160, 255, 32],
        gradient_480: [160, 255, 64],
        gradient_481: [160, 255, 96],
        gradient_482: [160, 255, 128],
        gradient_483: [160, 255, 160],
        gradient_484: [160, 255, 192],
        gradient_485: [160, 255, 224],
        gradient_486: [160, 255, 255],
        gradient_487: [192, 0, 0],
        gradient_488: [192, 0, 32],
        gradient_489: [192, 0, 64],
        gradient_490: [192, 0, 96],
        gradient_491: [192, 0, 128],
        gradient_492: [192, 0, 160],
        gradient_493: [192, 0, 192],
        gradient_494: [192, 0, 224],
        gradient_495: [192, 0, 255],
        gradient_496: [192, 32, 0],
        gradient_497: [192, 32, 32],
        gradient_498: [192, 32, 64],
        gradient_499: [192, 32, 96],
        gradient_500: [192, 32, 128],
        gradient_501: [192, 32, 160],
        gradient_502: [192, 32, 192],
        gradient_503: [192, 32, 224],
        gradient_504: [192, 32, 255],
        gradient_505: [192, 64, 0],
        gradient_506: [192, 64, 32],
        gradient_507: [192, 64, 64],
        gradient_508: [192, 64, 96],
        gradient_509: [192, 64, 128],
        gradient_510: [192, 64, 160],
        gradient_511: [192, 64, 192],
        gradient_512: [192, 64, 224],
        gradient_513: [192, 64, 255],
        gradient_514: [192, 96, 0],
        gradient_515: [192, 96, 32],
        gradient_516: [192, 96, 64],
        gradient_517: [192, 96, 96],
        gradient_518: [192, 96, 128],
        gradient_519: [192, 96, 160],
        gradient_520: [192, 96, 192],
        gradient_521: [192, 96, 224],
        gradient_522: [192, 96, 255],
        gradient_523: [192, 128, 0],
        gradient_524: [192, 128, 32],
        gradient_525: [192, 128, 64],
        gradient_526: [192, 128, 96],
        gradient_527: [192, 128, 128],
        gradient_528: [192, 128, 160],
        gradient_529: [192, 128, 192],
        gradient_530: [192, 128, 224],
        gradient_531: [192, 128, 255],
        gradient_532: [192, 160, 0],
        gradient_533: [192, 160, 32],
        gradient_534: [192, 160, 64],
        gradient_535: [192, 160, 96],
        gradient_536: [192, 160, 128],
        gradient_537: [192, 160, 160],
        gradient_538: [192, 160, 192],
        gradient_539: [192, 160, 224],
        gradient_540: [192, 160, 255],
        gradient_541: [192, 192, 0],
        gradient_542: [192, 192, 32],
        gradient_543: [192, 192, 64],
        gradient_544: [192, 192, 96],
        gradient_545: [192, 192, 128],
        gradient_546: [192, 192, 160],
        gradient_547: [192, 192, 192],
        gradient_548: [192, 192, 224],
        gradient_549: [192, 192, 255],
        gradient_550: [192, 224, 0],
        gradient_551: [192, 224, 32],
        gradient_552: [192, 224, 64],
        gradient_553: [192, 224, 96],
        gradient_554: [192, 224, 128],
        gradient_555: [192, 224, 160],
        gradient_556: [192, 224, 192],
        gradient_557: [192, 224, 224],
        gradient_558: [192, 224, 255],
        gradient_559: [192, 255, 0],
        gradient_560: [192, 255, 32],
        gradient_561: [192, 255, 64],
        gradient_562: [192, 255, 96],
        gradient_563: [192, 255, 128],
        gradient_564: [192, 255, 160],
        gradient_565: [192, 255, 192],
        gradient_566: [192, 255, 224],
        gradient_567: [192, 255, 255],
        gradient_568: [224, 0, 0],
        gradient_569: [224, 0, 32],
        gradient_570: [224, 0, 64],
        gradient_571: [224, 0, 96],
        gradient_572: [224, 0, 128],
        gradient_573: [224, 0, 160],
        gradient_574: [224, 0, 192],
        gradient_575: [224, 0, 224],
        gradient_576: [224, 0, 255],
        gradient_577: [224, 32, 0],
        gradient_578: [224, 32, 32],
        gradient_579: [224, 32, 64],
        gradient_580: [224, 32, 96],
        gradient_581: [224, 32, 128],
        gradient_582: [224, 32, 160],
        gradient_583: [224, 32, 192],
        gradient_584: [224, 32, 224],
        gradient_585: [224, 32, 255],
        gradient_586: [224, 64, 0],
        gradient_587: [224, 64, 32],
        gradient_588: [224, 64, 64],
        gradient_589: [224, 64, 96],
        gradient_590: [224, 64, 128],
        gradient_591: [224, 64, 160],
        gradient_592: [224, 64, 192],
        gradient_593: [224, 64, 224],
        gradient_594: [224, 64, 255],
        gradient_595: [224, 96, 0],
        gradient_596: [224, 96, 32],
        gradient_597: [224, 96, 64],
        gradient_598: [224, 96, 96],
        gradient_599: [224, 96, 128],
        gradient_600: [224, 96, 160],
        gradient_601: [224, 96, 192],
        gradient_602: [224, 96, 224],
        gradient_603: [224, 96, 255],
        gradient_604: [224, 128, 0],
        gradient_605: [224, 128, 32],
        gradient_606: [224, 128, 64],
        gradient_607: [224, 128, 96],
        gradient_608: [224, 128, 128],
        gradient_609: [224, 128, 160],
        gradient_610: [224, 128, 192],
        gradient_611: [224, 128, 224],
        gradient_612: [224, 128, 255],
        gradient_613: [224, 160, 0],
        gradient_614: [224, 160, 32],
        gradient_615: [224, 160, 64],
        gradient_616: [224, 160, 96],
        gradient_617: [224, 160, 128],
        gradient_618: [224, 160, 160],
        gradient_619: [224, 160, 192],
        gradient_620: [224, 160, 224],
        gradient_621: [224, 160, 255],
        gradient_622: [224, 192, 0],
        gradient_623: [224, 192, 32],
        gradient_624: [224, 192, 64],
        gradient_625: [224, 192, 96],
        gradient_626: [224, 192, 128],
        gradient_627: [224, 192, 160],
        gradient_628: [224, 192, 192],
        gradient_629: [224, 192, 224],
        gradient_630: [224, 192, 255],
        gradient_631: [224, 224, 0],
        gradient_632: [224, 224, 32],
        gradient_633: [224, 224, 64],
        gradient_634: [224, 224, 96],
        gradient_635: [224, 224, 128],
        gradient_636: [224, 224, 160],
        gradient_637: [224, 224, 192],
        gradient_638: [224, 224, 224],
        gradient_639: [224, 224, 255],
        gradient_640: [224, 255, 0],
        gradient_641: [224, 255, 32],
        gradient_642: [224, 255, 64],
        gradient_643: [224, 255, 96],
        gradient_644: [224, 255, 128],
        gradient_645: [224, 255, 160],
        gradient_646: [224, 255, 192],
        gradient_647: [224, 255, 224],
        gradient_648: [224, 255, 255],
        gradient_649: [255, 0, 0],
        gradient_650: [255, 0, 32],
        gradient_651: [255, 0, 64],
        gradient_652: [255, 0, 96],
        gradient_653: [255, 0, 128],
        gradient_654: [255, 0, 160],
        gradient_655: [255, 0, 192],
        gradient_656: [255, 0, 224],
        gradient_657: [255, 0, 255],
        gradient_658: [255, 32, 0],
        gradient_659: [255, 32, 32],
        gradient_660: [255, 32, 64],
        gradient_661: [255, 32, 96],
        gradient_662: [255, 32, 128],
        gradient_663: [255, 32, 160],
        gradient_664: [255, 32, 192],
        gradient_665: [255, 32, 224],
        gradient_666: [255, 32, 255],
        gradient_667: [255, 64, 0],
        gradient_668: [255, 64, 32],
        gradient_669: [255, 64, 64],
        gradient_670: [255, 64, 96],
        gradient_671: [255, 64, 128],
        gradient_672: [255, 64, 160],
        gradient_673: [255, 64, 192],
        gradient_674: [255, 64, 224],
        gradient_675: [255, 64, 255],
        gradient_676: [255, 96, 0],
        gradient_677: [255, 96, 32],
        gradient_678: [255, 96, 64],
        gradient_679: [255, 96, 96],
        gradient_680: [255, 96, 128],
        gradient_681: [255, 96, 160],
        gradient_682: [255, 96, 192],
        gradient_683: [255, 96, 224],
        gradient_684: [255, 96, 255],
        gradient_685: [255, 128, 0],
        gradient_686: [255, 128, 32],
        gradient_687: [255, 128, 64],
        gradient_688: [255, 128, 96],
        gradient_689: [255, 128, 128],
        gradient_690: [255, 128, 160],
        gradient_691: [255, 128, 192],
        gradient_692: [255, 128, 224],
        gradient_693: [255, 128, 255],
        gradient_694: [255, 160, 0],
        gradient_695: [255, 160, 32],
        gradient_696: [255, 160, 64],
        gradient_697: [255, 160, 96],
        gradient_698: [255, 160, 128],
        gradient_699: [255, 160, 160],
        gradient_700: [255, 160, 192],
        gradient_701: [255, 160, 224],
        gradient_702: [255, 160, 255],
        gradient_703: [255, 192, 0],
        gradient_704: [255, 192, 32],
        gradient_705: [255, 192, 64],
        gradient_706: [255, 192, 96],
        gradient_707: [255, 192, 128],
        gradient_708: [255, 192, 160],
        gradient_709: [255, 192, 192],
        gradient_710: [255, 192, 224],
        gradient_711: [255, 192, 255],
        gradient_712: [255, 224, 0],
        gradient_713: [255, 224, 32],
        gradient_714: [255, 224, 64],
        gradient_715: [255, 224, 96],
        gradient_716: [255, 224, 128],
        gradient_717: [255, 224, 160],
        gradient_718: [255, 224, 192],
        gradient_719: [255, 224, 224],
        gradient_720: [255, 224, 255],
        gradient_721: [255, 255, 0],
        gradient_722: [255, 255, 32],
        gradient_723: [255, 255, 64],
        gradient_724: [255, 255, 96],
        gradient_725: [255, 255, 128],
        gradient_726: [255, 255, 160],
        gradient_727: [255, 255, 192],
        gradient_728: [255, 255, 224],
        gradient_729: [255, 255, 255],
        // other colors
        BackgroundLayer: [0, 0, 0],
    };

    // make the RGB colors from the values
    for (var key in colors) {
        var c = new RGBColor();
        c.red = colors[key][0];
        c.green = colors[key][1];
        c.blue = colors[key][2];
        colors[key] = c;
    }

    return colors;

};

 

4 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
July 14, 2023

Hi @A819434, I've tested your script (sorry I didn't notice you had already attached it) and I noticed a problem similar to the one you described. I believe the problem relates to memory management. Illustrator has always been a bit poor at this aspect of scripting, and its errors often aren't very helpful, but we can often work around the limitations by changing the structure of the script.

 

I've made an attempt at structural changes to your script designed to improve performance and memory usage. The big change I made was to open all the art files once, just keeping them open the whole time, and closing them at the end. I keep track of the documents (and their background layers and background rectangles) in the "docs" variable. I moved the color creation in a function called "getColors" just so I could put it to the end of the script because it was so long. I doubt this change has any bearing on performance. I also restructured the colors so you can more easily see the color breakdowns—this was just a style thing, not anything to do with performance. In general I sharpened up some of your references so you always know what you are referring to, and moved variables around a little to make scope clearer and avoid repetition. But the big thing is probably keeping the documents open the whole time. I also switch to outline mode which sometimes speeds things up a lot.

 

After these changes, the script ran until completion for me. Let me know how it goes for you.

- Mark

 

/**
 * Variation on user @A819434's script to
 * try to improve memory management.
 * @discussion https:// community.adobe.com/t5/illustrator-discussions/parm-error-with-jsx/m-p/13935106
 */
(function () {

    // store all colors in this object
    var colors = getColors();

    var artFiles = [
        'King',
        'Queen',
        'Rook',
        'Bishop',
        'Knight',
        'Pawn',
    ];

    var pathToArt = '~/Desktop/save as ai/';
    var pathToText = '~/Desktop/ChessText/';
    var pathToExport = '~/Desktop/ChessNFT/';

    // variablesStart
    var i = 1;
    var a = 2;
    var b = 728;
    var c = 1;
    // variablesEnd

    // open art files
    var doc,
        docs = {},
        backgroundLayer,
        backgroundRectangle;
    for (var i = 0; i < artFiles.length; i++) {
        doc = (app.open(File(pathToArt + artFiles[i] + '.ai')));
        backgroundLayer = doc.layers.add();
        // outline view might speed things up
        app.executeMenuCommand('preview');
        // add the background layer and rectangle
        backgroundLayer.name = "Background";
        backgroundLayer.color = colors['BackgroundLayer'];
        backgroundLayer.printable = false;
        backgroundLayer.zOrder(ZOrderMethod.SENDTOBACK);
        backgroundRectangle = backgroundLayer.pathItems.rectangle(0, 0, 1080, 1080);
        backgroundRectangle.stroked = false;

        // store the docs
        docs[artFiles[i]] = {
            doc: doc,
            backgroundLayer: backgroundLayer,
            backgroundRectangle: backgroundRectangle,
        };
    }

    for (var e = 0; e < 488; e++) {

        var name,
            type,
            // this will hold text to write to file
            text = [];

        var random_1 = Math.floor(Math.random() * 105); // 0-104_105
        if (random_1 < 5) { // 0-4_5
            name = 'King';
            type = 0;
        }
        else if (random_1 < 15) { // 5-14_10
            name = 'Queen';
            type = 0;
        }
        else if (random_1 < 30) { // 15-29_15
            name = 'Rook';
            type = 0;
        }
        else if (random_1 < 50) { // 30-49_20
            name = 'Bishop'
            type = 0;
        }
        else if (random_1 < 75) { // 50-74_25
            name = 'Knight'
            type = 1;
        }
        else if (random_1 < 105) { // 75-104_30
            name = 'Pawn'
            type = 0;
        }
        text.push(name);
        doc = docs[name].doc;
        backgroundLayer = docs[name].backgroundLayer;
        backgroundRectangle = docs[name].backgroundRectangle;

        if (i == 126 && b == 365 && a == 365) {
            alert("finished");
            return;
        }

        // colorStart
        var random_3 = Math.floor(Math.random() * 100); // 0-99_100
        if (random_3 < 25) { // 0-24_25
            if (i == 126) {
                var colorGradient = doc.gradients.add();
                // colorGradient.name = "GradientArt1";
                colorGradient.type = GradientType.LINEAR;
                colorGradient.gradientStops[0].color = colors['color_' + a];
                colorGradient.gradientStops[1].color = colors['color_' + b];
                var gradientColor = new GradientColor();
                gradientColor.gradient = colorGradient;
                for (var x = 0; x < doc.pathItems.length; x++) {
                    doc.pathItems[x].fillColor = gradientColor;
                }
                a++;
                b--;
                text.push('Gradient');
            }
            else {
                for (var x = 0; x < doc.pathItems.length; x++) {
                    doc.pathItems[x].fillColor = colors['color_' + i];
                }
                i++;
                text.push('Colour');
            }
        }
        else if (random_3 < 100) { // 25-99_75
            if (b == 365 && a == 365) {
                for (var x = 0; x < doc.pathItems.length; x++) {
                    doc.pathItems[x].fillColor = colors['color_' + i];
                }
                i++;
                text.push('Colour');
            }
            else {
                var colorGradient = app.activeDocument.gradients.add();
                // colorGradient.name = "GradientArt2";
                colorGradient.type = GradientType.LINEAR;
                colorGradient.gradientStops[0].color = colors['gradient_' + a];
                colorGradient.gradientStops[1].color = colors['gradient_' + b];
                var gradientColor = new GradientColor();
                gradientColor.gradient = colorGradient;
                for (var x = 0; x < doc.pathItems.length; x++) {
                    doc.pathItems[x].fillColor = gradientColor;
                }
                a++;
                b--;
                text.push('Gradient');
            }
        }
        if (type = 1 && doc.pathItems.length > 20) {
            doc.pathItems[0].filled = false;
            doc.pathItems[1].filled = false;
            doc.pathItems[2].filled = false;
            doc.pathItems[3].filled = false;
            doc.pathItems[4].filled = false;
            doc.pathItems[5].filled = false;
            doc.pathItems[6].filled = false;
            doc.pathItems[7].filled = false;
            doc.pathItems[8].filled = false;
            doc.pathItems[9].filled = false;
            type = 0;
        }
        type = 0;
        // colorEnd
        // backgroundStart
        var theGradient,
            backgroundColor;
        var colorRandom = Math.floor(Math.random() * 6); // 0-5_6
        var random_2 = Math.floor(Math.random() * 100); // 0-99_100
        if (random_2 < 10 && random_2 > -1) { // 0-9_10
            theGradient = doc.gradients.add();
            // theGradient.name = "Gradient_1";
            theGradient.type = GradientType.LINEAR;
            theGradient.gradientStops.add();
            theGradient.gradientStops[0].rampPoint = 0;
            theGradient.gradientStops[1].rampPoint = 50;
            theGradient.gradientStops[2].rampPoint = 100;
            if (colorRandom == 0) {
                theGradient.gradientStops[0].color = colors.red;
                theGradient.gradientStops[1].color = colors.green;
                theGradient.gradientStops[2].color = colors.blue;
            }
            else if (colorRandom == 1) {
                theGradient.gradientStops[0].color = colors.blue;
                theGradient.gradientStops[1].color = colors.red;
                theGradient.gradientStops[2].color = colors.green;
            }
            else if (colorRandom == 2) {
                theGradient.gradientStops[0].color = colors.green;
                theGradient.gradientStops[1].color = colors.blue;
                theGradient.gradientStops[2].color = colors.red;
            }
            else if (colorRandom == 3) {
                theGradient.gradientStops[0].color = colors.green;
                theGradient.gradientStops[1].color = colors.red;
                theGradient.gradientStops[2].color = colors.blue;
            }
            else if (colorRandom == 4) {
                theGradient.gradientStops[0].color = colors.blue;
                theGradient.gradientStops[1].color = colors.green;
                theGradient.gradientStops[2].color = colors.red;
            }
            else if (colorRandom == 5) {
                theGradient.gradientStops[0].color = colors.red;
                theGradient.gradientStops[1].color = colors.blue;
                theGradient.gradientStops[2].color = colors.green;
            }
            backgroundColor = new GradientColor();
            backgroundColor.gradient = theGradient;
            backgroundRectangle.fillColor = backgroundColor;
            text.push('RGB');
        }
        else if (random_2 < 40) { // 10-39_30
            theGradient = doc.gradients.add();
            // theGradient.name = "Gradient_2";
            theGradient.type = GradientType.LINEAR;
            theGradient.gradientStops.add();
            theGradient.gradientStops[0].rampPoint = 0;
            theGradient.gradientStops[1].rampPoint = 50;
            theGradient.gradientStops[2].rampPoint = 100;
            if (colorRandom == 0) {
                theGradient.gradientStops[0].color = colors.yellow;
                theGradient.gradientStops[1].color = colors.cyan;
                theGradient.gradientStops[2].color = colors.magenta;
            }
            else if (colorRandom == 1) {
                theGradient.gradientStops[0].color = colors.magenta;
                theGradient.gradientStops[1].color = colors.yellow;
                theGradient.gradientStops[2].color = colors.cyan;
            }
            else if (colorRandom == 2) {
                theGradient.gradientStops[0].color = colors.cyan;
                theGradient.gradientStops[1].color = colors.magenta;
                theGradient.gradientStops[2].color = colors.yellow;
            }
            else if (colorRandom == 3) {
                theGradient.gradientStops[0].color = colors.cyan;
                theGradient.gradientStops[1].color = colors.yellow;
                theGradient.gradientStops[2].color = colors.magenta;
            }
            else if (colorRandom == 4) {
                theGradient.gradientStops[0].color = colors.magenta;
                theGradient.gradientStops[1].color = colors.cyan;
                theGradient.gradientStops[2].color = colors.yellow;
            }
            else if (colorRandom == 5) {
                theGradient.gradientStops[0].color = colors.yellow;
                theGradient.gradientStops[1].color = colors.magenta;
                theGradient.gradientStops[2].color = colors.cyan;
            }
            backgroundColor = new GradientColor();
            backgroundColor.gradient = theGradient;
            backgroundRectangle.fillColor = backgroundColor;
            text.push('YCM');
        }
        else if (random_2 < 100) { // 40-99_60
            theGradient = doc.gradients.add();
            // theGradient.name = "Gradient_3";
            theGradient.type = GradientType.LINEAR;
            theGradient.gradientStops[0].rampPoint = 0;
            theGradient.gradientStops[1].rampPoint = 100;
            if (colorRandom == 0) {
                theGradient.gradientStops[0].color = colors.white;
                theGradient.gradientStops[1].color = colors.black;
            }
            else if (colorRandom == 1) {
                theGradient.gradientStops[0].color = colors.white;
                theGradient.gradientStops[1].color = colors.black;
            }
            else if (colorRandom == 2) {
                theGradient.gradientStops[0].color = colors.white;
                theGradient.gradientStops[1].color = colors.black;
            }
            else if (colorRandom == 3) {
                theGradient.gradientStops[0].color = colors.black;
                theGradient.gradientStops[1].color = colors.white;
            }
            else if (colorRandom == 4) {
                theGradient.gradientStops[0].color = colors.black;
                theGradient.gradientStops[1].color = colors.white;
            }
            else if (colorRandom == 5) {
                theGradient.gradientStops[0].color = colors.black;
                theGradient.gradientStops[1].color = colors.white;
            }
            backgroundColor = new GradientColor();
            backgroundColor.gradient = theGradient;
            backgroundRectangle.fillColor = backgroundColor;
            text.push('BW');
        }
        // backgroundEnd

        // make folders
        if (!Folder(pathToText).exists) Folder(pathToText).create();
        if (!Folder(pathToExport).exists) Folder(pathToExport).create();

        // textStart
        var textFile = new File(pathToText + c + '.txt');

        textFile.open("w", "TEXT", "????");
        textFile.encoding = "UTF-8"; // Encode

        textFile.write(text.join('\n'));

        textFile.close();
        // textEnd

        // exportStart
        AntiAliasingMethod.ARTOPTIMIZED = true;
        doc.exportFile(File(pathToExport + c + '.png'), ExportType.PNG24);
        c++;
        // exportEnd

        // alert("next");
        // $.writeln('e = ' + e);

    }

    // close art files
    for (var key in docs) {
        docs[key].doc.close(SaveOptions.DONOTSAVECHANGES);
    }

})();



function getColors() {

    var colors = {
        // colors1Start
        black: [0, 0, 0],
        white: [255, 255, 255],
        red: [255, 0, 0],
        green: [0, 255, 0],
        blue: [0, 0, 255],
        yellow: [255, 255, 0],
        cyan: [0, 255, 255],
        magenta: [255, 0, 255],
        // colors2Start
        color_1: [0, 0, 0],
        color_2: [0, 0, 64],
        color_3: [0, 0, 128],
        color_4: [0, 0, 192],
        color_5: [0, 0, 255],
        color_6: [0, 64, 0],
        color_7: [0, 64, 64],
        color_8: [0, 64, 128],
        color_9: [0, 64, 192],
        color_10: [0, 64, 255],
        color_11: [0, 128, 0],
        color_12: [0, 128, 64],
        color_13: [0, 128, 128],
        color_14: [0, 128, 192],
        color_15: [0, 128, 255],
        color_16: [0, 192, 0],
        color_17: [0, 192, 64],
        color_18: [0, 192, 128],
        color_19: [0, 192, 192],
        color_20: [0, 192, 255],
        color_21: [0, 255, 0],
        color_22: [0, 255, 64],
        color_23: [0, 255, 128],
        color_24: [0, 255, 192],
        color_25: [0, 255, 255],
        color_26: [64, 0, 0],
        color_27: [64, 0, 64],
        color_28: [64, 0, 128],
        color_29: [64, 0, 192],
        color_30: [64, 0, 255],
        color_31: [64, 64, 0],
        color_32: [64, 64, 64],
        color_33: [64, 64, 128],
        color_34: [64, 64, 192],
        color_35: [64, 64, 255],
        color_36: [64, 128, 0],
        color_37: [64, 128, 64],
        color_38: [64, 128, 128],
        color_39: [64, 128, 192],
        color_40: [64, 128, 255],
        color_41: [64, 192, 0],
        color_42: [64, 192, 64],
        color_43: [64, 192, 128],
        color_44: [64, 192, 192],
        color_45: [64, 192, 255],
        color_46: [64, 255, 0],
        color_47: [64, 255, 64],
        color_48: [64, 255, 128],
        color_49: [64, 255, 192],
        color_50: [64, 255, 255],
        color_51: [128, 0, 0],
        color_52: [128, 0, 64],
        color_53: [128, 0, 128],
        color_54: [128, 0, 192],
        color_55: [128, 0, 255],
        color_56: [128, 64, 0],
        color_57: [128, 64, 64],
        color_58: [128, 64, 128],
        color_59: [128, 64, 192],
        color_60: [128, 64, 255],
        color_61: [128, 128, 0],
        color_62: [128, 128, 64],
        color_63: [128, 128, 128],
        color_64: [128, 128, 192],
        color_65: [128, 128, 255],
        color_66: [128, 192, 0],
        color_67: [128, 192, 64],
        color_68: [128, 192, 128],
        color_69: [128, 192, 192],
        color_70: [128, 192, 255],
        color_71: [128, 255, 0],
        color_72: [128, 255, 64],
        color_73: [128, 255, 128],
        color_74: [128, 255, 192],
        color_75: [128, 255, 255],
        color_76: [192, 0, 0],
        color_77: [192, 0, 64],
        color_78: [192, 0, 128],
        color_79: [192, 0, 192],
        color_80: [192, 0, 255],
        color_81: [192, 64, 0],
        color_82: [192, 64, 64],
        color_83: [192, 64, 128],
        color_84: [192, 64, 192],
        color_85: [192, 64, 255],
        color_86: [192, 128, 0],
        color_87: [192, 128, 64],
        color_88: [192, 128, 128],
        color_89: [192, 128, 192],
        color_90: [192, 128, 255],
        color_91: [192, 192, 0],
        color_92: [192, 192, 64],
        color_93: [192, 192, 128],
        color_94: [192, 192, 192],
        color_95: [192, 192, 255],
        color_96: [192, 255, 0],
        color_97: [192, 255, 64],
        color_98: [192, 255, 128],
        color_99: [192, 255, 192],
        color_100: [192, 255, 255],
        color_101: [255, 0, 0],
        color_102: [255, 0, 64],
        color_103: [255, 0, 128],
        color_104: [255, 0, 192],
        color_105: [255, 0, 255],
        color_106: [255, 64, 0],
        color_107: [255, 64, 64],
        color_108: [255, 64, 128],
        color_109: [255, 64, 192],
        color_110: [255, 64, 255],
        color_111: [255, 128, 0],
        color_112: [255, 128, 64],
        color_113: [255, 128, 128],
        color_114: [255, 128, 192],
        color_115: [255, 128, 255],
        color_116: [255, 192, 0],
        color_117: [255, 192, 64],
        color_118: [255, 192, 128],
        color_119: [255, 192, 192],
        color_120: [255, 192, 255],
        color_121: [255, 255, 0],
        color_122: [255, 255, 64],
        color_123: [255, 255, 128],
        color_124: [255, 255, 192],
        color_125: [255, 255, 255],
        // colors3Start
        gradient_1: [0, 0, 0],
        gradient_2: [0, 0, 32],
        gradient_3: [0, 0, 64],
        gradient_4: [0, 0, 96],
        gradient_5: [0, 0, 128],
        gradient_6: [0, 0, 160],
        gradient_7: [0, 0, 192],
        gradient_8: [0, 0, 224],
        gradient_9: [0, 0, 255],
        gradient_10: [0, 32, 0],
        gradient_11: [0, 32, 32],
        gradient_12: [0, 32, 64],
        gradient_13: [0, 32, 96],
        gradient_14: [0, 32, 128],
        gradient_15: [0, 32, 160],
        gradient_16: [0, 32, 192],
        gradient_17: [0, 32, 224],
        gradient_18: [0, 32, 255],
        gradient_19: [0, 64, 0],
        gradient_20: [0, 64, 32],
        gradient_21: [0, 64, 64],
        gradient_22: [0, 64, 96],
        gradient_23: [0, 64, 128],
        gradient_24: [0, 64, 160],
        gradient_25: [0, 64, 192],
        gradient_26: [0, 64, 224],
        gradient_27: [0, 64, 255],
        gradient_28: [0, 96, 0],
        gradient_29: [0, 96, 32],
        gradient_30: [0, 96, 64],
        gradient_31: [0, 96, 96],
        gradient_32: [0, 96, 128],
        gradient_33: [0, 96, 160],
        gradient_34: [0, 96, 192],
        gradient_35: [0, 96, 224],
        gradient_36: [0, 96, 255],
        gradient_37: [0, 128, 0],
        gradient_38: [0, 128, 32],
        gradient_39: [0, 128, 64],
        gradient_40: [0, 128, 96],
        gradient_41: [0, 128, 128],
        gradient_42: [0, 128, 160],
        gradient_43: [0, 128, 192],
        gradient_44: [0, 128, 224],
        gradient_45: [0, 128, 255],
        gradient_46: [0, 160, 0],
        gradient_47: [0, 160, 32],
        gradient_48: [0, 160, 64],
        gradient_49: [0, 160, 96],
        gradient_50: [0, 160, 128],
        gradient_51: [0, 160, 160],
        gradient_52: [0, 160, 192],
        gradient_53: [0, 160, 224],
        gradient_54: [0, 160, 255],
        gradient_55: [0, 192, 0],
        gradient_56: [0, 192, 32],
        gradient_57: [0, 192, 64],
        gradient_58: [0, 192, 96],
        gradient_59: [0, 192, 128],
        gradient_60: [0, 192, 160],
        gradient_61: [0, 192, 192],
        gradient_62: [0, 192, 224],
        gradient_63: [0, 192, 255],
        gradient_64: [0, 224, 0],
        gradient_65: [0, 224, 32],
        gradient_66: [0, 224, 64],
        gradient_67: [0, 224, 96],
        gradient_68: [0, 224, 128],
        gradient_69: [0, 224, 160],
        gradient_70: [0, 224, 192],
        gradient_71: [0, 224, 224],
        gradient_72: [0, 224, 255],
        gradient_73: [0, 255, 0],
        gradient_74: [0, 255, 32],
        gradient_75: [0, 255, 64],
        gradient_76: [0, 255, 96],
        gradient_77: [0, 255, 128],
        gradient_78: [0, 255, 160],
        gradient_79: [0, 255, 192],
        gradient_80: [0, 255, 224],
        gradient_81: [0, 255, 255],
        gradient_82: [32, 0, 0],
        gradient_83: [32, 0, 32],
        gradient_84: [32, 0, 64],
        gradient_85: [32, 0, 96],
        gradient_86: [32, 0, 128],
        gradient_87: [32, 0, 160],
        gradient_88: [32, 0, 192],
        gradient_89: [32, 0, 224],
        gradient_90: [32, 0, 255],
        gradient_91: [32, 32, 0],
        gradient_92: [32, 32, 32],
        gradient_93: [32, 32, 64],
        gradient_94: [32, 32, 96],
        gradient_95: [32, 32, 128],
        gradient_96: [32, 32, 160],
        gradient_97: [32, 32, 192],
        gradient_98: [32, 32, 224],
        gradient_99: [32, 32, 255],
        gradient_100: [32, 64, 0],
        gradient_101: [32, 64, 32],
        gradient_102: [32, 64, 64],
        gradient_103: [32, 64, 96],
        gradient_104: [32, 64, 128],
        gradient_105: [32, 64, 160],
        gradient_106: [32, 64, 192],
        gradient_107: [32, 64, 224],
        gradient_108: [32, 64, 255],
        gradient_109: [32, 96, 0],
        gradient_110: [32, 96, 32],
        gradient_111: [32, 96, 64],
        gradient_112: [32, 96, 96],
        gradient_113: [32, 96, 128],
        gradient_114: [32, 96, 160],
        gradient_115: [32, 96, 192],
        gradient_116: [32, 96, 224],
        gradient_117: [32, 96, 255],
        gradient_118: [32, 128, 0],
        gradient_119: [32, 128, 32],
        gradient_120: [32, 128, 64],
        gradient_121: [32, 128, 96],
        gradient_122: [32, 128, 128],
        gradient_123: [32, 128, 160],
        gradient_124: [32, 128, 192],
        gradient_125: [32, 128, 224],
        gradient_126: [32, 128, 255],
        gradient_127: [32, 160, 0],
        gradient_128: [32, 160, 32],
        gradient_129: [32, 160, 64],
        gradient_130: [32, 160, 96],
        gradient_131: [32, 160, 128],
        gradient_132: [32, 160, 160],
        gradient_133: [32, 160, 192],
        gradient_134: [32, 160, 224],
        gradient_135: [0, 160, 255],
        gradient_136: [32, 192, 0],
        gradient_137: [32, 192, 32],
        gradient_138: [32, 192, 64],
        gradient_139: [32, 192, 96],
        gradient_140: [32, 192, 128],
        gradient_141: [32, 192, 160],
        gradient_142: [32, 192, 192],
        gradient_143: [32, 192, 224],
        gradient_144: [32, 192, 255],
        gradient_145: [32, 224, 0],
        gradient_146: [32, 224, 32],
        gradient_147: [32, 224, 64],
        gradient_148: [32, 224, 96],
        gradient_149: [32, 224, 128],
        gradient_150: [32, 224, 160],
        gradient_151: [32, 224, 192],
        gradient_152: [32, 224, 224],
        gradient_153: [32, 224, 255],
        gradient_154: [32, 255, 0],
        gradient_155: [32, 255, 32],
        gradient_156: [32, 255, 64],
        gradient_157: [32, 255, 96],
        gradient_158: [32, 255, 128],
        gradient_159: [32, 255, 160],
        gradient_160: [32, 255, 192],
        gradient_161: [32, 255, 224],
        gradient_162: [32, 255, 255],
        gradient_163: [64, 0, 0],
        gradient_164: [64, 0, 32],
        gradient_165: [64, 0, 64],
        gradient_166: [64, 0, 96],
        gradient_167: [64, 0, 128],
        gradient_168: [64, 0, 160],
        gradient_169: [64, 0, 192],
        gradient_170: [64, 0, 224],
        gradient_171: [64, 0, 255],
        gradient_172: [64, 32, 0],
        gradient_173: [64, 32, 32],
        gradient_174: [64, 32, 64],
        gradient_175: [64, 32, 96],
        gradient_176: [64, 32, 128],
        gradient_177: [64, 32, 160],
        gradient_178: [64, 32, 192],
        gradient_179: [64, 32, 224],
        gradient_180: [64, 32, 255],
        gradient_181: [64, 64, 0],
        gradient_182: [64, 64, 32],
        gradient_183: [64, 64, 64],
        gradient_184: [64, 64, 96],
        gradient_185: [64, 64, 128],
        gradient_186: [64, 64, 160],
        gradient_187: [64, 64, 192],
        gradient_188: [64, 64, 224],
        gradient_189: [64, 64, 255],
        gradient_190: [64, 96, 0],
        gradient_191: [64, 96, 32],
        gradient_192: [64, 96, 64],
        gradient_193: [64, 96, 96],
        gradient_194: [64, 96, 128],
        gradient_195: [64, 96, 160],
        gradient_196: [64, 96, 192],
        gradient_197: [64, 96, 224],
        gradient_198: [64, 96, 255],
        gradient_199: [64, 128, 0],
        gradient_200: [64, 128, 32],
        gradient_201: [64, 128, 64],
        gradient_202: [64, 128, 96],
        gradient_203: [64, 128, 128],
        gradient_204: [64, 128, 160],
        gradient_205: [64, 128, 192],
        gradient_206: [64, 128, 224],
        gradient_207: [64, 128, 255],
        gradient_208: [64, 160, 0],
        gradient_209: [64, 160, 32],
        gradient_210: [64, 160, 64],
        gradient_211: [64, 160, 96],
        gradient_212: [64, 160, 128],
        gradient_213: [64, 160, 160],
        gradient_214: [64, 160, 192],
        gradient_215: [64, 160, 224],
        gradient_216: [64, 160, 255],
        gradient_217: [64, 192, 0],
        gradient_218: [64, 192, 32],
        gradient_219: [64, 192, 64],
        gradient_220: [64, 192, 96],
        gradient_221: [64, 192, 128],
        gradient_222: [64, 192, 160],
        gradient_223: [64, 192, 192],
        gradient_224: [64, 192, 224],
        gradient_225: [64, 192, 255],
        gradient_226: [64, 224, 0],
        gradient_227: [64, 224, 32],
        gradient_228: [64, 224, 64],
        gradient_229: [64, 224, 96],
        gradient_230: [64, 224, 128],
        gradient_231: [64, 224, 160],
        gradient_232: [64, 224, 192],
        gradient_233: [64, 224, 224],
        gradient_234: [64, 224, 255],
        gradient_235: [64, 255, 0],
        gradient_236: [64, 255, 32],
        gradient_237: [64, 255, 64],
        gradient_238: [64, 255, 96],
        gradient_239: [64, 255, 128],
        gradient_240: [64, 255, 160],
        gradient_241: [64, 255, 192],
        gradient_242: [64, 255, 224],
        gradient_243: [64, 255, 255],
        gradient_244: [96, 0, 0],
        gradient_245: [96, 0, 32],
        gradient_246: [96, 0, 64],
        gradient_247: [96, 0, 96],
        gradient_248: [96, 0, 128],
        gradient_249: [96, 0, 160],
        gradient_250: [96, 0, 192],
        gradient_251: [96, 0, 224],
        gradient_252: [96, 0, 255],
        gradient_253: [96, 32, 0],
        gradient_254: [96, 32, 32],
        gradient_255: [96, 32, 64],
        gradient_256: [96, 32, 96],
        gradient_257: [96, 32, 128],
        gradient_258: [96, 32, 160],
        gradient_259: [96, 32, 192],
        gradient_260: [96, 32, 224],
        gradient_261: [96, 32, 255],
        gradient_262: [96, 64, 0],
        gradient_263: [96, 64, 32],
        gradient_264: [96, 64, 64],
        gradient_265: [96, 64, 96],
        gradient_266: [96, 64, 128],
        gradient_267: [96, 64, 160],
        gradient_268: [96, 64, 192],
        gradient_269: [96, 64, 224],
        gradient_270: [96, 64, 255],
        gradient_271: [96, 96, 0],
        gradient_272: [96, 96, 32],
        gradient_273: [96, 96, 64],
        gradient_274: [96, 96, 96],
        gradient_275: [96, 96, 128],
        gradient_276: [96, 96, 160],
        gradient_277: [96, 96, 192],
        gradient_278: [96, 96, 224],
        gradient_279: [96, 96, 255],
        gradient_280: [96, 128, 0],
        gradient_281: [96, 128, 32],
        gradient_282: [96, 128, 64],
        gradient_283: [96, 128, 96],
        gradient_284: [96, 128, 128],
        gradient_285: [96, 128, 160],
        gradient_286: [96, 128, 192],
        gradient_287: [96, 128, 224],
        gradient_288: [96, 128, 255],
        gradient_289: [96, 160, 0],
        gradient_290: [96, 160, 32],
        gradient_291: [96, 160, 64],
        gradient_292: [96, 160, 96],
        gradient_293: [96, 160, 128],
        gradient_294: [96, 160, 160],
        gradient_295: [96, 160, 192],
        gradient_296: [96, 160, 224],
        gradient_297: [96, 160, 255],
        gradient_298: [96, 192, 0],
        gradient_299: [96, 192, 32],
        gradient_300: [96, 192, 64],
        gradient_301: [96, 192, 96],
        gradient_302: [96, 192, 128],
        gradient_303: [96, 192, 160],
        gradient_304: [96, 192, 192],
        gradient_305: [96, 192, 224],
        gradient_306: [96, 192, 255],
        gradient_307: [96, 224, 0],
        gradient_308: [96, 224, 32],
        gradient_309: [96, 224, 64],
        gradient_310: [96, 224, 96],
        gradient_311: [96, 224, 128],
        gradient_312: [96, 224, 160],
        gradient_313: [96, 224, 192],
        gradient_314: [96, 224, 224],
        gradient_315: [96, 224, 255],
        gradient_316: [96, 255, 0],
        gradient_317: [96, 255, 32],
        gradient_318: [96, 255, 64],
        gradient_319: [96, 255, 96],
        gradient_320: [96, 255, 128],
        gradient_321: [96, 255, 160],
        gradient_322: [96, 255, 192],
        gradient_323: [96, 255, 224],
        gradient_324: [96, 255, 255],
        gradient_325: [128, 0, 0],
        gradient_326: [128, 0, 32],
        gradient_327: [128, 0, 64],
        gradient_328: [128, 0, 96],
        gradient_329: [128, 0, 128],
        gradient_330: [128, 0, 160],
        gradient_331: [128, 0, 192],
        gradient_332: [128, 0, 224],
        gradient_333: [128, 0, 255],
        gradient_334: [128, 32, 0],
        gradient_335: [128, 32, 32],
        gradient_336: [128, 32, 64],
        gradient_337: [128, 32, 96],
        gradient_338: [128, 32, 128],
        gradient_339: [128, 32, 160],
        gradient_340: [128, 32, 192],
        gradient_341: [128, 32, 224],
        gradient_342: [128, 32, 255],
        gradient_343: [128, 64, 0],
        gradient_344: [128, 64, 32],
        gradient_345: [128, 64, 64],
        gradient_346: [128, 64, 96],
        gradient_347: [128, 64, 128],
        gradient_348: [128, 64, 160],
        gradient_349: [128, 64, 192],
        gradient_350: [128, 64, 224],
        gradient_351: [128, 64, 255],
        gradient_352: [128, 96, 0],
        gradient_353: [128, 96, 32],
        gradient_354: [128, 96, 64],
        gradient_355: [128, 96, 96],
        gradient_356: [128, 96, 128],
        gradient_357: [128, 96, 160],
        gradient_358: [128, 96, 192],
        gradient_359: [128, 96, 224],
        gradient_360: [128, 96, 255],
        gradient_361: [128, 128, 0],
        gradient_362: [128, 128, 32],
        gradient_363: [128, 128, 64],
        gradient_364: [128, 128, 96],
        gradient_365: [128, 128, 128],
        gradient_366: [128, 128, 160],
        gradient_367: [128, 128, 192],
        gradient_368: [128, 128, 224],
        gradient_369: [128, 128, 255],
        gradient_370: [128, 160, 0],
        gradient_371: [128, 160, 32],
        gradient_372: [128, 160, 64],
        gradient_373: [128, 160, 96],
        gradient_374: [128, 160, 128],
        gradient_375: [128, 160, 160],
        gradient_376: [128, 160, 192],
        gradient_377: [128, 160, 224],
        gradient_378: [128, 160, 255],
        gradient_379: [128, 192, 0],
        gradient_380: [128, 192, 32],
        gradient_381: [128, 192, 64],
        gradient_382: [128, 192, 96],
        gradient_383: [128, 192, 128],
        gradient_384: [128, 192, 160],
        gradient_385: [128, 192, 192],
        gradient_386: [128, 192, 224],
        gradient_387: [128, 192, 255],
        gradient_388: [128, 224, 0],
        gradient_389: [128, 224, 32],
        gradient_390: [128, 224, 64],
        gradient_391: [128, 224, 96],
        gradient_392: [128, 224, 128],
        gradient_393: [128, 224, 160],
        gradient_394: [128, 224, 192],
        gradient_395: [128, 224, 224],
        gradient_396: [128, 224, 255],
        gradient_397: [128, 255, 0],
        gradient_398: [128, 255, 32],
        gradient_399: [128, 255, 64],
        gradient_400: [128, 255, 96],
        gradient_401: [128, 255, 128],
        gradient_402: [128, 255, 160],
        gradient_403: [128, 255, 192],
        gradient_404: [128, 255, 224],
        gradient_405: [128, 255, 255],
        gradient_406: [160, 0, 0],
        gradient_407: [160, 0, 32],
        gradient_408: [160, 0, 64],
        gradient_409: [160, 0, 96],
        gradient_410: [160, 0, 128],
        gradient_411: [160, 0, 160],
        gradient_412: [160, 0, 192],
        gradient_413: [160, 0, 224],
        gradient_414: [160, 0, 255],
        gradient_415: [160, 32, 0],
        gradient_416: [160, 32, 32],
        gradient_417: [160, 32, 64],
        gradient_418: [160, 32, 96],
        gradient_419: [160, 32, 128],
        gradient_420: [160, 32, 160],
        gradient_421: [160, 32, 192],
        gradient_422: [160, 32, 224],
        gradient_423: [160, 32, 255],
        gradient_424: [160, 64, 0],
        gradient_425: [160, 64, 32],
        gradient_426: [160, 64, 64],
        gradient_427: [160, 64, 96],
        gradient_428: [160, 64, 128],
        gradient_429: [160, 64, 160],
        gradient_430: [160, 64, 192],
        gradient_431: [160, 64, 224],
        gradient_432: [160, 64, 255],
        gradient_433: [160, 96, 0],
        gradient_434: [160, 96, 32],
        gradient_435: [160, 96, 64],
        gradient_436: [160, 96, 96],
        gradient_437: [160, 96, 128],
        gradient_438: [160, 96, 160],
        gradient_439: [160, 96, 192],
        gradient_440: [160, 96, 224],
        gradient_441: [160, 96, 255],
        gradient_442: [160, 128, 0],
        gradient_443: [160, 128, 32],
        gradient_444: [160, 128, 64],
        gradient_445: [160, 128, 96],
        gradient_446: [160, 128, 128],
        gradient_447: [160, 128, 160],
        gradient_448: [160, 128, 192],
        gradient_449: [160, 128, 224],
        gradient_450: [160, 128, 255],
        gradient_451: [160, 160, 0],
        gradient_452: [160, 160, 32],
        gradient_453: [160, 160, 64],
        gradient_454: [160, 160, 96],
        gradient_455: [160, 160, 128],
        gradient_456: [160, 160, 160],
        gradient_457: [160, 160, 192],
        gradient_458: [160, 160, 224],
        gradient_459: [160, 160, 255],
        gradient_460: [160, 192, 0],
        gradient_461: [160, 192, 32],
        gradient_462: [160, 192, 64],
        gradient_463: [160, 192, 96],
        gradient_464: [160, 192, 128],
        gradient_465: [160, 192, 160],
        gradient_466: [160, 192, 192],
        gradient_467: [160, 192, 224],
        gradient_468: [160, 192, 255],
        gradient_469: [160, 224, 0],
        gradient_470: [160, 224, 32],
        gradient_471: [160, 224, 64],
        gradient_472: [160, 224, 96],
        gradient_473: [160, 224, 128],
        gradient_474: [160, 224, 160],
        gradient_475: [160, 224, 192],
        gradient_476: [160, 224, 224],
        gradient_477: [160, 224, 255],
        gradient_478: [160, 255, 0],
        gradient_479: [160, 255, 32],
        gradient_480: [160, 255, 64],
        gradient_481: [160, 255, 96],
        gradient_482: [160, 255, 128],
        gradient_483: [160, 255, 160],
        gradient_484: [160, 255, 192],
        gradient_485: [160, 255, 224],
        gradient_486: [160, 255, 255],
        gradient_487: [192, 0, 0],
        gradient_488: [192, 0, 32],
        gradient_489: [192, 0, 64],
        gradient_490: [192, 0, 96],
        gradient_491: [192, 0, 128],
        gradient_492: [192, 0, 160],
        gradient_493: [192, 0, 192],
        gradient_494: [192, 0, 224],
        gradient_495: [192, 0, 255],
        gradient_496: [192, 32, 0],
        gradient_497: [192, 32, 32],
        gradient_498: [192, 32, 64],
        gradient_499: [192, 32, 96],
        gradient_500: [192, 32, 128],
        gradient_501: [192, 32, 160],
        gradient_502: [192, 32, 192],
        gradient_503: [192, 32, 224],
        gradient_504: [192, 32, 255],
        gradient_505: [192, 64, 0],
        gradient_506: [192, 64, 32],
        gradient_507: [192, 64, 64],
        gradient_508: [192, 64, 96],
        gradient_509: [192, 64, 128],
        gradient_510: [192, 64, 160],
        gradient_511: [192, 64, 192],
        gradient_512: [192, 64, 224],
        gradient_513: [192, 64, 255],
        gradient_514: [192, 96, 0],
        gradient_515: [192, 96, 32],
        gradient_516: [192, 96, 64],
        gradient_517: [192, 96, 96],
        gradient_518: [192, 96, 128],
        gradient_519: [192, 96, 160],
        gradient_520: [192, 96, 192],
        gradient_521: [192, 96, 224],
        gradient_522: [192, 96, 255],
        gradient_523: [192, 128, 0],
        gradient_524: [192, 128, 32],
        gradient_525: [192, 128, 64],
        gradient_526: [192, 128, 96],
        gradient_527: [192, 128, 128],
        gradient_528: [192, 128, 160],
        gradient_529: [192, 128, 192],
        gradient_530: [192, 128, 224],
        gradient_531: [192, 128, 255],
        gradient_532: [192, 160, 0],
        gradient_533: [192, 160, 32],
        gradient_534: [192, 160, 64],
        gradient_535: [192, 160, 96],
        gradient_536: [192, 160, 128],
        gradient_537: [192, 160, 160],
        gradient_538: [192, 160, 192],
        gradient_539: [192, 160, 224],
        gradient_540: [192, 160, 255],
        gradient_541: [192, 192, 0],
        gradient_542: [192, 192, 32],
        gradient_543: [192, 192, 64],
        gradient_544: [192, 192, 96],
        gradient_545: [192, 192, 128],
        gradient_546: [192, 192, 160],
        gradient_547: [192, 192, 192],
        gradient_548: [192, 192, 224],
        gradient_549: [192, 192, 255],
        gradient_550: [192, 224, 0],
        gradient_551: [192, 224, 32],
        gradient_552: [192, 224, 64],
        gradient_553: [192, 224, 96],
        gradient_554: [192, 224, 128],
        gradient_555: [192, 224, 160],
        gradient_556: [192, 224, 192],
        gradient_557: [192, 224, 224],
        gradient_558: [192, 224, 255],
        gradient_559: [192, 255, 0],
        gradient_560: [192, 255, 32],
        gradient_561: [192, 255, 64],
        gradient_562: [192, 255, 96],
        gradient_563: [192, 255, 128],
        gradient_564: [192, 255, 160],
        gradient_565: [192, 255, 192],
        gradient_566: [192, 255, 224],
        gradient_567: [192, 255, 255],
        gradient_568: [224, 0, 0],
        gradient_569: [224, 0, 32],
        gradient_570: [224, 0, 64],
        gradient_571: [224, 0, 96],
        gradient_572: [224, 0, 128],
        gradient_573: [224, 0, 160],
        gradient_574: [224, 0, 192],
        gradient_575: [224, 0, 224],
        gradient_576: [224, 0, 255],
        gradient_577: [224, 32, 0],
        gradient_578: [224, 32, 32],
        gradient_579: [224, 32, 64],
        gradient_580: [224, 32, 96],
        gradient_581: [224, 32, 128],
        gradient_582: [224, 32, 160],
        gradient_583: [224, 32, 192],
        gradient_584: [224, 32, 224],
        gradient_585: [224, 32, 255],
        gradient_586: [224, 64, 0],
        gradient_587: [224, 64, 32],
        gradient_588: [224, 64, 64],
        gradient_589: [224, 64, 96],
        gradient_590: [224, 64, 128],
        gradient_591: [224, 64, 160],
        gradient_592: [224, 64, 192],
        gradient_593: [224, 64, 224],
        gradient_594: [224, 64, 255],
        gradient_595: [224, 96, 0],
        gradient_596: [224, 96, 32],
        gradient_597: [224, 96, 64],
        gradient_598: [224, 96, 96],
        gradient_599: [224, 96, 128],
        gradient_600: [224, 96, 160],
        gradient_601: [224, 96, 192],
        gradient_602: [224, 96, 224],
        gradient_603: [224, 96, 255],
        gradient_604: [224, 128, 0],
        gradient_605: [224, 128, 32],
        gradient_606: [224, 128, 64],
        gradient_607: [224, 128, 96],
        gradient_608: [224, 128, 128],
        gradient_609: [224, 128, 160],
        gradient_610: [224, 128, 192],
        gradient_611: [224, 128, 224],
        gradient_612: [224, 128, 255],
        gradient_613: [224, 160, 0],
        gradient_614: [224, 160, 32],
        gradient_615: [224, 160, 64],
        gradient_616: [224, 160, 96],
        gradient_617: [224, 160, 128],
        gradient_618: [224, 160, 160],
        gradient_619: [224, 160, 192],
        gradient_620: [224, 160, 224],
        gradient_621: [224, 160, 255],
        gradient_622: [224, 192, 0],
        gradient_623: [224, 192, 32],
        gradient_624: [224, 192, 64],
        gradient_625: [224, 192, 96],
        gradient_626: [224, 192, 128],
        gradient_627: [224, 192, 160],
        gradient_628: [224, 192, 192],
        gradient_629: [224, 192, 224],
        gradient_630: [224, 192, 255],
        gradient_631: [224, 224, 0],
        gradient_632: [224, 224, 32],
        gradient_633: [224, 224, 64],
        gradient_634: [224, 224, 96],
        gradient_635: [224, 224, 128],
        gradient_636: [224, 224, 160],
        gradient_637: [224, 224, 192],
        gradient_638: [224, 224, 224],
        gradient_639: [224, 224, 255],
        gradient_640: [224, 255, 0],
        gradient_641: [224, 255, 32],
        gradient_642: [224, 255, 64],
        gradient_643: [224, 255, 96],
        gradient_644: [224, 255, 128],
        gradient_645: [224, 255, 160],
        gradient_646: [224, 255, 192],
        gradient_647: [224, 255, 224],
        gradient_648: [224, 255, 255],
        gradient_649: [255, 0, 0],
        gradient_650: [255, 0, 32],
        gradient_651: [255, 0, 64],
        gradient_652: [255, 0, 96],
        gradient_653: [255, 0, 128],
        gradient_654: [255, 0, 160],
        gradient_655: [255, 0, 192],
        gradient_656: [255, 0, 224],
        gradient_657: [255, 0, 255],
        gradient_658: [255, 32, 0],
        gradient_659: [255, 32, 32],
        gradient_660: [255, 32, 64],
        gradient_661: [255, 32, 96],
        gradient_662: [255, 32, 128],
        gradient_663: [255, 32, 160],
        gradient_664: [255, 32, 192],
        gradient_665: [255, 32, 224],
        gradient_666: [255, 32, 255],
        gradient_667: [255, 64, 0],
        gradient_668: [255, 64, 32],
        gradient_669: [255, 64, 64],
        gradient_670: [255, 64, 96],
        gradient_671: [255, 64, 128],
        gradient_672: [255, 64, 160],
        gradient_673: [255, 64, 192],
        gradient_674: [255, 64, 224],
        gradient_675: [255, 64, 255],
        gradient_676: [255, 96, 0],
        gradient_677: [255, 96, 32],
        gradient_678: [255, 96, 64],
        gradient_679: [255, 96, 96],
        gradient_680: [255, 96, 128],
        gradient_681: [255, 96, 160],
        gradient_682: [255, 96, 192],
        gradient_683: [255, 96, 224],
        gradient_684: [255, 96, 255],
        gradient_685: [255, 128, 0],
        gradient_686: [255, 128, 32],
        gradient_687: [255, 128, 64],
        gradient_688: [255, 128, 96],
        gradient_689: [255, 128, 128],
        gradient_690: [255, 128, 160],
        gradient_691: [255, 128, 192],
        gradient_692: [255, 128, 224],
        gradient_693: [255, 128, 255],
        gradient_694: [255, 160, 0],
        gradient_695: [255, 160, 32],
        gradient_696: [255, 160, 64],
        gradient_697: [255, 160, 96],
        gradient_698: [255, 160, 128],
        gradient_699: [255, 160, 160],
        gradient_700: [255, 160, 192],
        gradient_701: [255, 160, 224],
        gradient_702: [255, 160, 255],
        gradient_703: [255, 192, 0],
        gradient_704: [255, 192, 32],
        gradient_705: [255, 192, 64],
        gradient_706: [255, 192, 96],
        gradient_707: [255, 192, 128],
        gradient_708: [255, 192, 160],
        gradient_709: [255, 192, 192],
        gradient_710: [255, 192, 224],
        gradient_711: [255, 192, 255],
        gradient_712: [255, 224, 0],
        gradient_713: [255, 224, 32],
        gradient_714: [255, 224, 64],
        gradient_715: [255, 224, 96],
        gradient_716: [255, 224, 128],
        gradient_717: [255, 224, 160],
        gradient_718: [255, 224, 192],
        gradient_719: [255, 224, 224],
        gradient_720: [255, 224, 255],
        gradient_721: [255, 255, 0],
        gradient_722: [255, 255, 32],
        gradient_723: [255, 255, 64],
        gradient_724: [255, 255, 96],
        gradient_725: [255, 255, 128],
        gradient_726: [255, 255, 160],
        gradient_727: [255, 255, 192],
        gradient_728: [255, 255, 224],
        gradient_729: [255, 255, 255],
        // other colors
        BackgroundLayer: [0, 0, 0],
    };

    // make the RGB colors from the values
    for (var key in colors) {
        var c = new RGBColor();
        c.red = colors[key][0];
        c.green = colors[key][1];
        c.blue = colors[key][2];
        colors[key] = c;
    }

    return colors;

};

 

A819434Author
Participating Frequently
July 14, 2023

Thank you so much, will try it ASAP.

Inspiring
July 13, 2023

If you comment our the two lines where you're giving the gradient a name it will work:

 

4372 //colorGradient.name = "GradientArt1";

4406 //colorGradient.name = "GradientArt2";

 

You're not using the name attribute anyway.

A819434Author
Participating Frequently
July 13, 2023

Will try ASAP. Thanks.

Inspiring
July 13, 2023

The script "works" for me, I don't get the PARAM error. It endlessly creates files in the desktop/ChessText with three rows of text, for example:

"Knight
Gradient
BW"

Inspiring
July 13, 2023

EDIT: I forgot to add the ChessNFT and now I also get the PARM error

m1b
Community Expert
Community Expert
July 13, 2023

You need to check all your parameters, that they are valid and correct type, etc. if that doesn't help, please share your code, or, ideally, a small piece of self contained code that throws the error. And also a demo illustrator file to use with script (save as pdf because forum doesn't allow .ai files).

- Mark

A819434Author
Participating Frequently
July 13, 2023

Here is the script: