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

Adding Color Names Instead of Color Bars

Participant ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

Hi everyone,

 

I'm looking for a way to save a PDF file with color information, specifically to write separation color names instead of the standard color bar. The typical trim and marks provide a color bar, but I need to add the actual color names in their corresponding colors.

 

Any help is appreciated!

 

TOPICS
Experiment , How-to , Import and export , Print and publish , Scripting

Views

1.2K

Translate

Translate

Report

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

Enthusiast , Jul 04, 2024 Jul 04, 2024

 

main();

function main () {
  if (parseFloat(app.version) < 16) {
    alert('Error\nSorry, script only works in Illustrator CS6 and later');
    return;
  }

  if (!documents.length) {
    alert('Error\nOpen a document and try again');
    return;
  }

  var win = new Window("dialog", "Show Ink List v0.2");
      win.alignChildren = ["fill", "top"];
      win.spacing = 10;
      win.margins = 16;

  var fontGrp = win.add("group");
      fontGrp.alignChildren = ["fill", "center"];

  var fontLbl
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

Hi @MidoSemsem, the best way forward is to post a pdf showing exactly what you ideally would like. Then people can look at that and see if they know a way. Good luck.

- Mark

Votes

Translate

Translate

Report

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
Participant ,
Jul 03, 2024 Jul 03, 2024

Copy link to clipboard

Copied

Thank you @m1b , 
I want to use the color names as in "Color Names.pdf" file instead of color bar

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

I'm, not near a computer but I have an old script that places spot color names on the document for screen printing separations. It may give you some insight in how the process.

 

https://github.com/joshbduncan/illustrator-scripts/blob/main/jsx/ScreenSepMarks.jsx

Votes

Translate

Translate

Report

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
Participant ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

Thanks @jduncan 
Nice script by the way, but I cannot add document color names

Votes

Translate

Translate

Report

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
Participant ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

I’ve been working on a script, and this is what I’ve accomplished so far:

 

 

 

var doc = app.activeDocument; // Ensure there is an active document
var newLayer = doc.layers.add();
newLayer.name = "InkNames";

var inkNames = getDocumentInkNames();
var inkNameStrings = inkNames.split(", ");

var artboards = doc.artboards;
for (var i = 0; i < artboards.length; i++) {
    var artboard = artboards[i];
    var artboardRect = artboard.artboardRect;
    
var x = artboardRect[0] + 15;
var y = artboardRect[3] + artboardRect[1] + 15;

for (var i = 0; i < inkNameStrings.length; i++) {
    var inkName = inkNameStrings[i];
    var inkNameText = newLayer.textFrames.add();
    inkNameText.contents = inkName;
    inkNameText.position = [y, x];
        inkNameText.rotate(90, true, true, true, true, Transformation.DOCUMENTORIGIN);

    y += 70; // Adjust spacing between ink names (negative value to move upward)
}
}
function getDocumentInkNames() {
    var inkNames = [];
    var inks = doc.inkList;
    for (var j = 0; j < inks.length; j++) {
        inkNames.push(inks[j].name);
    }
    return inkNames.join(", ");
}

 

 

Votes

Translate

Translate

Report

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
Participant ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

Currently, the text is filled with black. Is there a way to fill it with the actual corresponding color names?

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

My script colors the text with the actual color but it setup to work with only spot colors. You'll need to adjust it to make it work with all color types.

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

Hi Josh,

the reason why your script may not colour the text properly is probably a localisation conflict when using non-English Illustrator versions.

 

I did not test it thoroughly, but as far as I can see in line 352 the default [Registration] swatch is used. In non-English Illustrator versions the name of this swatch varies and therefore it can cause errors.

 

Just as an example, when using your script in the German version of Illustrator, the default [Registration]  swatch would have to be renamed to [Passermarken]  in order to get the colourised text objects (based on existing spot colours).

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

Probably so. That was one of the first scripts I wrote and it's been quite some time since I touched it. I'm no where near a computer but if I remember correctly it only ignores the Registration color so it is not added to the document text. Hopefully the code for writing the text in specific colors is enough for the OP to get an understanding of the process. Cheers!

Votes

Translate

Translate

Report

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
Enthusiast ,
Jul 04, 2024 Jul 04, 2024

Copy link to clipboard

Copied

 

main();

function main () {
  if (parseFloat(app.version) < 16) {
    alert('Error\nSorry, script only works in Illustrator CS6 and later');
    return;
  }

  if (!documents.length) {
    alert('Error\nOpen a document and try again');
    return;
  }

  var win = new Window("dialog", "Show Ink List v0.2");
      win.alignChildren = ["fill", "top"];
      win.spacing = 10;
      win.margins = 16;

  var fontGrp = win.add("group");
      fontGrp.alignChildren = ["fill", "center"];

  var fontLbl = fontGrp.add("statictext", undefined, "Font Size, pt:");
  var fontInp = fontGrp.add("edittext", undefined, 12);
      fontInp.characters = 10;

  var spGrp = win.add("group");
      spGrp.alignChildren = ["fill", "center"];

  var spLbl = spGrp.add("statictext", undefined, "Spacing, pt:");
  var spInp = spGrp.add("edittext", undefined, 15);
      spInp.characters = 10;

  var isSkipUnused = win.add("checkbox", undefined, "Skip Unused Spot Colors");
      isSkipUnused.value = true;

  var btns = win.add("group");

  var cancel = btns.add("button", undefined, "Cancel", {name: "cancel"});
  var ok = btns.add("button", undefined, "OK", {name: "ok"});

  cancel.onClick = win.close;

  ok.onClick = function () {
    var doc = app.activeDocument;// Ensure there is an active document
    app.executeMenuCommand('deselectall');
  
    try {
      var newLayer = doc.layers.getByName("InkNames");
      newLayer.locked = false;
      newLayer.visible = true;
      newLayer.hasSelectedArtwork = true;
      // Remove previous text labels
      for (var s = app.selection.length - 1;s >= 0;s--) {
        app.selection[s].remove();
      }
    } catch (err) {
      var newLayer = doc.layers.add();
      newLayer.name = "InkNames";
    }

    var font = parseFloat(fontInp.text);
    if (isNaN(font)) font = 12;

    var spacing = parseFloat(spInp.text);
    if (isNaN(spacing)) spacing = 15;

    var artboards = doc.artboards;

    for (var i = 0; i < artboards.length;i++) {
      app.executeMenuCommand('deselectall');
      doc.artboards.setActiveArtboardIndex(i);
      doc.selectObjectsOnActiveArtboard();

      if (!app.selection.length) continue;

      inks = getArtboardInks(app.selection, doc.documentColorSpace, isSkipUnused.value);

      var ab = artboards[i];
      var abRect = ab.artboardRect;
  
      addInkList(doc, inks, abRect[0], abRect[3], spacing, font, newLayer);
    }

    if (!newLayer.pageItems.length) newLayer.remove();

    app.executeMenuCommand('deselectall');
    win.close();
  }

  win.show();
}

function addInkList(doc, inks, left, bottom, spacing, font, target) {
  var x = left - spacing;
  var y = bottom + spacing;

  for (var i = 0; i < inks.length; i++) {
    var inkName = inks[i].name;
    var inkNameText = target.textFrames.add();

    inkNameText.contents = inkName;
    inkNameText.textRange.characterAttributes.size = font;

    var inkNameTextChar = inkNameText.textRange.characterAttributes;

    switch (inks[i].inkInfo.kind) {
      case InkType.CYANINK:
        inkNameTextChar.fillColor = setCMYKColor([100, 0, 0, 0]);
        break;
      case InkType.MAGENTAINK:
        inkNameTextChar.fillColor = setCMYKColor([0, 100, 0, 0]);
        break;
      case InkType.YELLOWINK:
        inkNameTextChar.fillColor = setCMYKColor([0, 0, 100, 0]);
        break;
      case InkType.BLACKINK:
        inkNameTextChar.fillColor = setCMYKColor([0, 0, 0, 100]);
        break;
      case InkType.CUSTOMINK:
        try {
          inkNameTextChar.fillColor = doc.swatches.getByName(inkName).color;
        } catch (err) {}
        break;
    }

    inkNameText.rotate(90, true, true, true, true, Transformation.CENTER);
    inkNameText.position = [x - inkNameText.width, y + inkNameText.height];
    y += inkNameText.height + spacing;
  }
}

function getArtboardInks(items, colorMode, isSkipUnused) {
  var newDoc = app.documents.add(colorMode);
  copyObjectsTo(items, newDoc);
  app.executeMenuCommand('Fit Artboard to artwork bounds');

  var inks = newDoc.inkList;
  var result = [];

  for (var i = 0; i < inks.length; i++) {
    if (!isSkipUnused || inks[i].inkInfo.printingStatus === InkPrintStatus.ENABLEINK) {
      result.push(inks[i]);
    }
  }

  newDoc.close(SaveOptions.DONOTSAVECHANGES);

  return result;
}

function copyObjectsTo(items, doc) {
  if (Object.prototype.toString.call(items) === '[object Array]') {
    for (var i = 0; i < items.length; i++) {
      items[i].duplicate(doc.activeLayer, ElementPlacement.PLACEATEND);
    }
  } else {
    items.duplicate(doc.activeLayer, ElementPlacement.PLACEATBEGINNING);
  }
}

function setCMYKColor(cmyk) {
  var c = new CMYKColor();
  c.cyan = cmyk[0];
  c.magenta = cmyk[1];
  c.yellow = cmyk[2];
  c.black = cmyk[3];
  return c;
}

 

 

However, in Illustrator localizations with their own alphabets (Russian, Chinese, Japanese, etc.), there is a problem with getting ink names in the correct encoding. Discussions here: https://community.adobe.com/t5/illustrator-discussions/how-to-make-the-script-support-chinese-japane...

 

Upd v0.2: Added isolated ink list output per artboard if objects are not hidden or locked

Votes

Translate

Translate

Report

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
Participant ,
Jul 05, 2024 Jul 05, 2024

Copy link to clipboard

Copied

Thank you @Sergey Osokin ,
Perfect script, exactly what I was looking for.

 

Can it be adjusted to work for each artboard separtely?

 

Votes

Translate

Translate

Report

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
Enthusiast ,
Jul 05, 2024 Jul 05, 2024

Copy link to clipboard

Copied

Check out the updated version v0.2. How do you find ink for an artboard? I took the easy way in my solution. I copy the artboard objects into a new document and get a list of inks in this new document, which I then print into the original document. And so for each artboard

Votes

Translate

Translate

Report

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
Participant ,
Jul 05, 2024 Jul 05, 2024

Copy link to clipboard

Copied

Nice approach @Sergey Osokin 
This will be slower for complex documents, right?

Votes

Translate

Translate

Report

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
Enthusiast ,
Jul 05, 2024 Jul 05, 2024

Copy link to clipboard

Copied

Yes. But the other way would also be slow - going through all the paths on each artboard, all the characters of the editable text frames, looking for Spot swatches or CMYK channels in Fills or Strokes, and then filtering the resulting color list to remove duplicate color names. If the object has a second color applied in the Appearance panel, the script will not be able to access this information in the Appearance panel either.

 

In fact, there are not many ways in scripts to get quick (!) information about some data about objects on a certain artboard when there will be hundreds or thousands of objects.

Votes

Translate

Translate

Report

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
Participant ,
Jul 05, 2024 Jul 05, 2024

Copy link to clipboard

Copied

I thought inks were read from output separation preview rather than individual objects or paths. That approach would likely be more straightforward.

Votes

Translate

Translate

Report

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
Enthusiast ,
Jul 05, 2024 Jul 05, 2024

Copy link to clipboard

Copied

In the object model, the ink list is for the whole document. But you asked the question to define the ink list in isolation for each artboard 🙂

Votes

Translate

Translate

Report

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
Enthusiast ,
Jul 09, 2024 Jul 09, 2024

Copy link to clipboard

Copied

With some fixes, I published the script v0.2.1 on Gist Github https://gist.github.com/creold/1e0fc33ca6b9748b4b689e44d07779b4

Votes

Translate

Translate

Report

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
Participant ,
Jul 09, 2024 Jul 09, 2024

Copy link to clipboard

Copied

Thanks @Sergey Osokin  
I noticed that it ignores locked objects and layers
How can this be solved without losing locking information?

Votes

Translate

Translate

Report

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
Enthusiast ,
Jul 09, 2024 Jul 09, 2024

Copy link to clipboard

Copied

This will slow down the script considerably for complex documents. This is because the script has to remember and restore the state of layers and objects.

Votes

Translate

Translate

Report

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
Participant ,
Jul 22, 2024 Jul 22, 2024

Copy link to clipboard

Copied

LATEST

@Sergey Osokin Check this out  😉

 

 

var doc = app.activeDocument;  // Reference to the active document
        // Create 'Inks' sublayer
        var inkNamesLayer = doc.layers.add();
        inkNamesLayer.name = "Inks";
        
        // Main function to apply the script logic to each artboard
function applyScriptToEachArtboard() {
    var artboards = doc.artboards; // Array of artboards in the document

    // Save the status of all items before modifying them
    function saveItemStatuses() {
        var itemStatuses = [];
        for (var k = 0; k < doc.pageItems.length; k++) {
            var item = doc.pageItems[k];
            itemStatuses.push({
                item: item,
                locked: item.locked,
                                hidden: item.hidden

            });
        }
        return itemStatuses;
    }

    // Restore the status of all items after processing
    function restoreItemStatuses(itemStatuses) {
        for (var l = 0; l < itemStatuses.length; l++) {
            var status = itemStatuses[l];
                        status.item.locked = status.locked;
            status.item.hidden = status.hidden;
        }
    }

    // Process each artboard
    for (var i = 0; i < artboards.length; i++) {
        doc.artboards.setActiveArtboardIndex(i); // Set the active artboard
        var activeArtboardIndex = doc.artboards.getActiveArtboardIndex();
        var activeArtboardRect = doc.artboards[activeArtboardIndex].artboardRect;
        var itemStatuses = saveItemStatuses(); // Save item statuses
        
        // Your script logic starts here
        doc.selectObjectsOnActiveArtboard();
        app.executeMenuCommand("Inverse menu item");
        var selectedItems = doc.selection;
        for (var j = 0; j < selectedItems.length; j++) {
            selectedItems[j].hidden = true;
        }


        // Define settings
        var font = "Arial";
        var fontSize = 7;
        var spacing = 9;
        var isSkipUnused = true;
        var inks = doc.inkList;

        // Process inks for the current artboard
        var x = activeArtboardRect[0] - 15;
        var y = activeArtboardRect[3] + 35;

        for (var j = 0; j < inks.length; j++) {
            var ink = inks[j];
            if (isSkipUnused && ink.inkInfo.printingStatus === InkPrintStatus.DISABLEINK) continue;

            var inkNameText = inkNamesLayer.textFrames.add();
            inkNameText.contents = ink.name.replace("Process ", "");
            inkNameText.textRange.paragraphAttributes.composerEngine = ComposerEngineType.optycaComposer;
            setCharacterAttributes(inkNameText, font, fontSize);
            setInkColor(inkNameText, ink);
            inkNameText.rotate(90, true, true, true, true, Transformation.CENTER);

            // Position ink names for the current artboard
            inkNameText.position = [x - inkNameText.width, y + inkNameText.height];
            y += inkNameText.height + spacing;
        }

        // Restore item statuses after processing
        restoreItemStatuses(itemStatuses);

        // Function definitions
        function setCharacterAttributes(textFrame, font, size) {
            var charAttrs = textFrame.textRange.characterAttributes;
            charAttrs.size = size;
            charAttrs.digitSet = DigitSetType.ARABIC_DIGITS;
        }

        function setInkColor(textFrame, ink) {
            var color;
            switch (ink.inkInfo.kind) {
                case InkType.CYANINK:
                    color = setCMYKColor([100, 0, 0, 0]);
                    break;
                case InkType.MAGENTAINK:
                    color = setCMYKColor([0, 100, 0, 0]);
                    break;
                case InkType.YELLOWINK:
                    color = setCMYKColor([0, 0, 100, 0]);
                    break;
                case InkType.BLACKINK:
                    color = setCMYKColor([0, 0, 0, 100]);
                    break;
                case InkType.CUSTOMINK:
                    try {
                        color = doc.swatches.getByName(ink.name).color;
                    } catch (err) {
                        color = null;
                    }
                    break;
            }
            if (color) {
                textFrame.textRange.characterAttributes.fillColor = color;
            }
        }

        function setCMYKColor(cmyk) {
            var color = new CMYKColor();
            color.cyan = cmyk[0];
            color.magenta = cmyk[1];
            color.yellow = cmyk[2];
            color.black = cmyk[3];
            return color;
        }
    }
}

// Run the main function
applyScriptToEachArtboard();

 

 

Votes

Translate

Translate

Report

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