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

Illustrator 2017 script for creating layers from spot colors in document

New Here ,
Jul 09, 2017 Jul 09, 2017

Copy link to clipboard

Copied

Hello, i have script that I use in my workflow everyday but with new Illustrator 2017 I get an error.

The script is trying to find 4 spot color in document (Cut, Crease, Reverse crease and Outside bleed) and put every single color in own layer named as follows:

Spot color "Cut" > layer "Thru-cut"

Spot color "Crease" > layer "Crease"

Spot color "Outside bleed" > layer "Bleed"

Spot color "Reverse crease" > layer "Crease"

Script that I have used in old Illustrator is this:

#target Illustrator
//Apply to myDoc the active document
var myDoc = app.activeDocument;
//define firts caracter and how many layers do you need
var layerIniName =65;
var numberOfLayers=2;

//Create the layers
for(var i=0; i<=numberOfLayers; i++) {
var layerName = String.fromCharCode(layerIniName)
var myLayer = myDoc.layers.add();
myLayer.name = layerName
layerIniName++

// JavaScript Document 
var doc = app.activeDocument; 
// name indexed object 
var layernames = { 
'A':'Bleed / Grafika', 
'B':'Crease', 
'C':'Thru-cut' 
}; 
// loop through all layers 
for (var i = 0; i < doc.layers.length; i++) 

//Set up Variable to access layer name 
var currentLayer = app.activeDocument.layers
if (layernames[currentLayer.name]) 

  currentLayer.name = layernames[currentLayer.name]; 




var doc = app.activeDocument;
var paths = doc.pathItems;
var destLayer = doc.layers.getByName ("Thru-cut");


for (var g=0; g<paths.length;g++){
    if (paths.strokeColor.typename == "SpotColor" && paths.strokeColor.spot.name == "Cut") {
        paths.move(destLayer, ElementPlacement.PLACEATBEGINNING);
    };
};

var doc = app.activeDocument;
var paths = doc.pathItems;
var destLayer = doc.layers.getByName ("Crease");


for (var g=0; g<paths.length;g++){
    if (paths.strokeColor.typename == "SpotColor" && paths.strokeColor.spot.name == "Crease") {
        paths.move(destLayer, ElementPlacement.PLACEATBEGINNING);
    };
};

var doc = app.activeDocument;
var paths = doc.pathItems;
var destLayer = doc.layers.getByName ("Bleed / Grafika");


for (var g=0; g<paths.length;g++){
    if (paths.strokeColor.typename == "SpotColor" && paths.strokeColor.spot.name == "Outside Bleed") {
        paths.move(destLayer, ElementPlacement.PLACEATBEGINNING);
    };
};

var doc = app.activeDocument;
var paths = doc.pathItems;
var destLayer = doc.layers.getByName ("Crease");


for (var g=0; g<paths.length;g++){
    if (paths.strokeColor.typename == "SpotColor" && paths.strokeColor.spot.name == "Reverse crease") {
        paths.move(destLayer, ElementPlacement.PLACEATBEGINNING);
    };
};

Can anybody help me resolve this script with new Illustrator?

Thanks

Denis

Sample file and script link:

https://www.dropbox.com/sh/hiffbk7yd3lspjg/AACdWhCbuMf2QC3fET8dd4mta?dl=0

TOPICS
Scripting

Views

2.9K

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
Adobe
People's Champ ,
Jul 10, 2017 Jul 10, 2017

Copy link to clipboard

Copied

Hi,

Let's try to make things simple.

var main = function(layerCount) {

var doc, layers;

if ( !app.documents.length ) {

alert("This scripts needs an open document !");

return;

}

//The doc

doc = app.activeDocument;

//Adding useful layers

addLayers ( doc );

//Moving items onto specific layers

moveItems ( doc );

}

var moveItems = function ( doc ) {

var items = doc.pageItems, item, n = items.length, sc, tn, sn,

layers = getLayersDB(doc),

cutLayer = layers['Thru-cut'],

creaseLayer = layers.Crease,

bleedLayer = layers['Bleed / Grafika'];

while ( n-- ) {

item = items;

sc = item.strokeColor;

tn = sc.typename;

if ( tn =="SpotColor" ) {

sn = sc.spot.name;

if ( sn=="Cut") {

item.move(cutLayer, ElementPlacement.PLACEATBEGINNING);

}

else if ( /^(Reverse )?Crease$/i.test( sn ) ){

item.move(creaseLayer, ElementPlacement.PLACEATBEGINNING);

}

else if ( sn=="Outside Bleed") {

item.move(bleedLayer, ElementPlacement.PLACEATBEGINNING);

}

}

}

}

var addLayers = function ( doc ) {

var layers = getLayersDB ( doc );

var layerNames = [

'Bleed / Grafika',

'Crease',

'Thru-cut'

],

name;

while ( name = layerNames.pop() )  !layers[name]  && addLayer ( doc, name );

};

var addLayer = function ( doc, name ) {

doc.layers.add().name = name;

}

var getLayersDB = function ( doc ) {

var db = {}, layers = doc.layers, n = layers.length, layer;

while ( n-- ) {

layer = layers;

db[layer.name] = layer;

}

return db;

}

main();

HTH

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
New Here ,
Jul 10, 2017 Jul 10, 2017

Copy link to clipboard

Copied

LATEST

Thanks, will try this new script

Denis

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