Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

JSX Script Creates New Swatch, But Stays as Process Color (Won’t Convert to Spot)

New Here ,
Nov 24, 2025 Nov 24, 2025

Hey everyone, hoping someone can help me out.

I had ChatGPT write a JSX script for Illustrator that automatically creates a new swatch named CutContour using CMYK values (0, 100, 0, 0) and sets the swatch Color Type to Spot Color. The script runs fine, the swatch is created, and it applies correctly as a .25pt stroke with no fill.

The only problem is that Illustrator keeps creating it as a Process Color, even though the JavaScript clearly defines it as a Spot Color.

>> No matter what, the swatch still shows as Process Color in the Swatches panel. I have to manually go in and change it to Spot Color.
??? Is there a better way to force Spot Color in scripting?

 

/**
 * Create / fix a "CutContour" spot swatch (C0 M100 Y0 K0),
 * apply it as a 0.25 pt stroke with no fill to all selected paths,
 * then move those paths to a new top layer called "CutContour_Paths".
 *
 * HOW TO USE:
 * 1. In Illustrator, select all objects that should be cut paths.
 * 2. Go to File > Scripts > Create_CutContour_From_Selection.
 */

(function () {
    // -----------------------------------
    // Safety checks
    // -----------------------------------
    if (app.documents.length === 0) {
        alert("Open a document before running this script.");
        return;
    }

    var doc = app.activeDocument;

    if (doc.selection.length === 0) {
        alert("Select the objects you want to convert to CutContour paths, then run the script.");
        return;
    }

    // -----------------------------------
    // 1. Get or create the CutContour spot swatch
    // -----------------------------------
    var spotName = "CutContour";
    var cutSpot = null;

    // Look for an existing spot named "CutContour"
    for (var i = 0; i < doc.spots.length; i++) {
        if (doc.spots[i].name === spotName) {
            cutSpot = doc.spots[i];
            break;
        }
    }

    // Create if it does not exist
    if (!cutSpot) {
        cutSpot = doc.spots.add();
        cutSpot.name = spotName;
    }

    // Force it to be a SPOT CMYK color with C0 M100 Y0 K0
    cutSpot.kind = SpotColorKind.SPOTCMYK;

    var cmyk = new CMYKColor();
    cmyk.cyan = 0;
    cmyk.magenta = 100;
    cmyk.yellow = 0;
    cmyk.black = 0;
    cutSpot.color = cmyk;

    // Create SpotColor instance for stroke assignment
    var cutStrokeColor = new SpotColor();
    cutStrokeColor.spot = cutSpot;
    cutStrokeColor.tint = 100;

    // -----------------------------------
    // 2. Process the selection and style paths
    // -----------------------------------
    var selectionItems = doc.selection;
    var modifiedItems = [];

    function processItem(item) {
        if (!item || item.locked || item.hidden) return;

        switch (item.typename) {
            case "GroupItem":
                // Process each item inside the group
                for (var i = 0; i < item.pageItems.length; i++) {
                    processItem(item.pageItems[i]);
                }
                break;

            case "CompoundPathItem":
                // Process each path inside compound path
                for (var j = 0; j < item.pathItems.length; j++) {
                    stylePath(item.pathItems[j]);
                }
                break;

            case "PathItem":
                stylePath(item);
                break;

            default:
                // Try to style pathItems if present (e.g. some shapes)
                if (item.pathItems && item.pathItems.length > 0) {
                    for (var k = 0; k < item.pathItems.length; k++) {
                        stylePath(item.pathItems[k]);
                    }
                }
                break;
        }
    }

    function stylePath(path) {
        if (!path || path.locked || path.hidden) return;

        try {
            path.stroked = true;
            path.strokeWidth = 0.25;      // 0.25 pt stroke
            path.strokeColor = cutStrokeColor;

            path.filled = false;          // no fill for cut paths

            modifiedItems.push(path);
        } catch (e) {
            // Ignore items that cannot be styled
        }
    }

    // Run through all selected items
    for (var s = 0; s < selectionItems.length; s++) {
        processItem(selectionItems[s]);
    }

    if (modifiedItems.length === 0) {
        alert("No valid paths were found in the selection to convert to CutContour.");
        return;
    }

    // -----------------------------------
    // 3. Create a top layer and move all cut paths into it
    // -----------------------------------
    var cutLayerName = "CutContour_Paths";
    var cutLayer = null;

    // Check if the layer already exists
    for (var l = 0; l < doc.layers.length; l++) {
        if (doc.layers[l].name === cutLayerName) {
            cutLayer = doc.layers[l];
            break;
        }
    }

    // If not found, create it
    if (!cutLayer) {
        cutLayer = doc.layers.add();
        cutLayer.name = cutLayerName;
    }

    // Move this layer to the top of the layer stack
    try {
        cutLayer.move(doc.layers[0], ElementPlacement.PLACEBEFORE);
    } catch (e) {
        // If move fails, leave as is
    }

    // Move all modified paths into the CutContour_Paths layer
    for (var m = 0; m < modifiedItems.length; m++) {
        try {
            modifiedItems[m].move(cutLayer, ElementPlacement.PLACEATBEGINNING);
        } catch (eMove) {
            // Skip any items that cannot be moved
        }
    }

    // -----------------------------------
    // Done
    // -----------------------------------
    alert("CutContours created and applied.\nCut paths moved to the 'CutContour_Paths' layer. \nScript authored by Drew Key utilizing ChatGPT");
})();



TOPICS
How-to , Scripting
91
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 24, 2025 Nov 24, 2025

Hi @drew_3709 try adding an extra line, here...

 

// Force it to be a SPOT CMYK color with C0 M100 Y0 K0
cutSpot.colorType = ColorModel.SPOT
cutSpot.kind = SpotColorKind.SPOTCMYK;

- Mark 

Translate
Adobe
Community Expert ,
Nov 24, 2025 Nov 24, 2025

Hi @drew_3709 try adding an extra line, here...

 

// Force it to be a SPOT CMYK color with C0 M100 Y0 K0
cutSpot.colorType = ColorModel.SPOT
cutSpot.kind = SpotColorKind.SPOTCMYK;

- Mark 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 24, 2025 Nov 24, 2025
LATEST

Thanks @m1b 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines