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

Selecting by stroke color?

Community Beginner ,
Nov 15, 2017 Nov 15, 2017

Copy link to clipboard

Copied

Forgive me, this is my first attempt at truly working with any sort of scripting and it has been an interesting week. I've been trying to work up something for some of my production guys that will be a script for Illustrator that will work with 'plotter' type equipment. 

What I am wanting to do is to take the flattened .ai file (Layer 1) that has been output and remove any clipping masks, then create the four necesary layers for our cutters that they need.  From there, separate the stroke colors into the respective layers. For example, the strokes colored with the 'Cut swatch' would go into a newly created 'knife' layer, Crease will go into 'Crease layer', etc.

So far, I have everything working else working, but cannot figure out how to select the paths by their swatch color and move them into the layers I have created.  Everything I have tried from reading online (or stealing other peoples) doesn't seem to be working and I am afraid I don't know enough to figure out what I need to do. 

TOPICS
Scripting

Views

2.4K

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

Contributor , Nov 19, 2017 Nov 19, 2017

Hi, BradB73.

You may be Kongsberg and ArtiosCAD user.

I made the process of ungrouping and dismantling compoundItems simpler.

However, the selected state can not be kept.

You can use it by customizing the presets in the main function.

Try this:

#target illustrator

(function () {

  

    function dismantleCompoundPathItem() {

        var doc = app.activeDocument;

        app.executeMenuCommand("selectall");

        app.executeMenuCommand("noCompoundPath");

    }

  

    function ungroup() {

        var doc = app

...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 15, 2017 Nov 15, 2017

Copy link to clipboard

Copied

function container()

{

    var docRef = app.activeDocument;

    var layers = docRef.layersj

    var myPaths = docRef.pathItems;

    var knifeLayer = layers["knife"];

    var creaseLayer = layers["crease"];

    var pathLen = myPaths.length;

    var myPath;

    for(var x=pathLen-1;x>=0;x--)

    {

        myPath = myPaths;

        if(myPath.stroked && myPath.strokeColor.spot)

        {

            if(myPath.strokeColor.spot.name === "Cut swatch")

            {

                myPath.moveToBeginning(knifeLayer);

            }

            else if(myPath.strokeColor.spot.name === "Crease")

            {

                myPath.moveToBeginning(creaseLayer);

            }

        }

    }

}

container();

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 Beginner ,
Nov 16, 2017 Nov 16, 2017

Copy link to clipboard

Copied

Awesome!  Thanks for the help William.  That has me on the right path (no pun intended).

Got one question though. After running the script I still have just a few random paths on Layer 1. I looked at the paths and they are all showing as <Path> and aren't part of any group or Compound Path.  I checked their color and they share the same colors as the ones that the script moved successfully and also have the same stroke attributes as far as I can tell.  It doesn't seem to be limited to Crease or Cut (seems to be a little of both) or the file - I have tried it with a couple files now and get the same results - the file .  I got no errors when running the script. Any thoughts?

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 ,
Nov 16, 2017 Nov 16, 2017

Copy link to clipboard

Copied

can you share the file so I can do some debugging?

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 Beginner ,
Nov 16, 2017 Nov 16, 2017

Copy link to clipboard

Copied

Yes, I put the script along with a couple working files I have been using to test in a dropbox folder.  Here is a link:

https://www.dropbox.com/sh/x9idapvf5s1983g/AAAH5wBVuji2aZDI2mPC4tUma?dl=0

One thing I had to change was the swatch color.  Per their workflow I had to change the names.  You will see that when you look at it.  However, it found the swatches in the files and ran with no problems.  Only thing was what I mentioned.

Thank you again for looking at it.

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
Contributor ,
Nov 19, 2017 Nov 19, 2017

Copy link to clipboard

Copied

Hi, BradB73.

You may be Kongsberg and ArtiosCAD user.

I made the process of ungrouping and dismantling compoundItems simpler.

However, the selected state can not be kept.

You can use it by customizing the presets in the main function.

Try this:

#target illustrator

(function () {

  

    function dismantleCompoundPathItem() {

        var doc = app.activeDocument;

        app.executeMenuCommand("selectall");

        app.executeMenuCommand("noCompoundPath");

    }

  

    function ungroup() {

        var doc = app.activeDocument;

        app.executeMenuCommand("selectall");

        app.executeMenuCommand("releaseMask");

        app.executeMenuCommand("ungroup");

    }

  

    function classify(pathItem, preset) {

        var i,

            max;

        for (i = 0, max = preset.length; i < max; i += 1) {

            if (pathItem.strokeColor.spot.name === preset.spotName) {

                pathItem.moveToBeginning(app.activeDocument.layers[preset.layerName]);

            }

        }

    }

  

    function main() {

        var preset = [

                {

                    spotName: "Camera",

                    layerName: "iCut"

                },

                {

                    spotName: "[Registration]",

                    layerName: "Registration Marks"

                },

                {

                    spotName: "Artios Cut",

                    layerName: "Knife"

                },

                {

                    spotName: "Artios Crease",

                    layerName: "Crease"

                }

            ],

            doc,

            layer,

            pathItem,

            i,

            max;

      

        // VALIDATE DOCUMENT

        if (app.documents.length === 0) {

            return;

        }

      

        doc = app.activeDocument;

        // DISMANTLE COMPOUNDPATHITEMS

        if (0 < doc.compoundPathItems.length) {

            dismantleCompoundPathItem();

        }

      

        // CLEAR CLIPPING PATH AND UNGROUP

        while (0 < doc.groupItems.length) {

            ungroup();

        }

      

        // CREATE LAYERS FOR CAD TABLES

        for (i = 0, max = preset.length; i < max; i += 1) {

            layer = doc.layers.add();

            layer.name = preset.layerName;

        }

      

        // MOVE THE STROKES TO NEW CAD LAYERS

        for (i = 0, max = doc.pathItems.length; i < max; i += 1) {

            pathItem = doc.pathItems;

            if (pathItem.stroked && pathItem.strokeColor.spot) {

                classify(pathItem, preset);

            }

        }

      

        doc.selection = null;

    }

  

    main();

}());

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 Beginner ,
Nov 20, 2017 Nov 20, 2017

Copy link to clipboard

Copied

Thank you sir!  Yes you are correct, we use ArtiosCAD + Kongsberg as well as the Esko Automation Engine.  The Pilot Workflow is what we have setup to generate our cut files from the art separating the print, production art, and the CAD but it ends up generating a flattened mess for the cutting table with the art embedded.  This script works beautifully.  Thanks again.

Can you explain briefly what you fixed?  I may end up adding another color in the future (line type) and I would like to know for my own knowledge.

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 Beginner ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

LATEST

OMOTI,

 

Hello! I know this thread is pretty old but I am in a similar situation where I am needing help with scripting. I am looking to seperate by Spot Color Fill instead of stroke. I have a nesting tool I use and place linked .ai files across multiple artboards. I then embed the linked files but now need to seperate the layers into Named layers for our CNC machine. What would be the best approach to this solution? Thanks in advance!

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
Contributor ,
Nov 20, 2017 Nov 20, 2017

Copy link to clipboard

Copied

You have a wonderful system. I would like to try operating the Esko Automation Engine.

~ about JavaScript ~

I think it is a problem that variables with the same name are scattered. If you keep in mind that simplifying the scope of variables and changing the properties of Illustrator DOM objects every time you manipulate, it will work with the same previous approach (your 'CURRENT.jsx').

~ my code ~

// DISMANTLE COMPOUNDPATHITEMS

Since it is a hard work, I changed it to a menu command.

// CLEAR CLIPPING PATH AND UNGROUP

Continue ungrouping while group objects exist in the document.

Since it is a hard work, I changed it to a menu command.

~ adding new line type (Vibra Knife) and removing line type (Knife)~

Change preset in the main function.

var preset = [

        {

            spotName: "Camera",

            layerName: "iCut"

        },

        {

            spotName: "[Registration]",

            layerName: "Registration Marks"

        },

        {

            spotName: "Artios Crease",

            layerName: "Crease"

        },

        {

            spotName: "Artios Vibra",

            layerName: "Vibra Knife"

        }

    ],

Before executing the script, keep all of the objects editable by unlock and visible.

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