Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

DIE CUT - scripts for cutting machines

$
0
0

Hello everyone, especially those from die cutting industry.

Due to requirement of new die cutting and printing machines in our company, we have to prepare files for these machines in appropriate way:

 

  • cutting, creasing and pcut lines must be spot colors CUT,CREASE,PCUT as well as NOTE
  • graphic elements, cutting and creasing lines must be in separate layers (there is double reason: if file is need to be printed and cut, it is processed in software, which detects just spot colors and make cut file from them and print file separately, if file is send directly to cutting machine, it detects just layers)

 

Some of our clients make their die cutting layouts on their own, often without conditions above. It means for us in our company to manually adjust files before sending to cutting and printing machines.

After failed try to make these steps via actions I searched something similar via scripts. I am not familiar with JavaScript, so I derivated final script by combining of these:

 

Script to make multiple layers in one task

Creating spot color in Illustrator CS4 js

Move a Spot color to a layer

 

Thank very much to authors and contributors of threads above

 

I put together these three above and made two script from them with little adjustments:

  1. First one add layers and spot colors CUT, CREASE, PCUT and NOTE; you can use this script even before drawing your own layout
  2. Second one makes final step, just for purpose of machine needs - objects with strokes CUT,CREASE,PCUT,NOTE puts to separate layers, only condition is names of each layer CUT, CREASE, PCUT, NOTE (no concern about when first one script created them)

 

DIECUT_add_layers_spot_cut_crease_pcut_note - script for adding spot colors and layers CUT, CRASE,PCUT,NOTE:

var layerName = LayerOrderType;
var myDoc = app.activeDocument;

var layerName
var numberOfLayers=0;

//Create the layers

for(var i=0; i<=numberOfLayers; i++)
{ var layerName = "CUT";  var myLayer = myDoc.layers.add(); myLayer.name = layerName;  }
{ var layerName = "CREASE";  var myLayer = myDoc.layers.add(); myLayer.name = layerName;  }
{ var layerName = "PCUT";  var myLayer = myDoc.layers.add(); myLayer.name = layerName;  }
{ var layerName = "NOTE";  var myLayer = myDoc.layers.add(); myLayer.name = layerName;  }

// Moves the bottom layer to become the topmost layer
if (documents.length > 0) {
countOfLayers = activeDocument.layers.length;
if (countOfLayers > 1) {
bottomLayer = activeDocument.layers[countOfLayers-1];
bottomLayer.zOrder(ZOrderMethod.BRINGTOFRONT);
}
else {
alert("The active document only has only 1 layer")
}  }
addSpot ('CUT', 0, 100, 100, 0);
function addSpot(name, c, m, y, k) {    try {        swatch = app.activeDocument.swatches[name]; // if swatch exists....        addSpot (name+='1', c, m, y, k); // ...add 1 to swatch name  }    catch (e) {        var newSpot = app.activeDocument.spots.add();        newSpot.name = name;            var newColor = new CMYKColor();        newColor.cyan = c;        newColor.magenta = m;        newColor.yellow = y;        newColor.black = k;        newSpot.colorType = ColorModel.SPOT;        newSpot.color = newColor;        var newSpotColor = new SpotColor();        newSpotColor.spot = newSpot;  }
addSpot ('CREASE', 100, 0, 100, 0);
function addSpot(name, c, m, y, k) {    try {        swatch = app.activeDocument.swatches[name]; // if swatch exists....        addSpot (name+='1', c, m, y, k); // ...add 1 to swatch name  }    catch (e) {        var newSpot = app.activeDocument.spots.add();        newSpot.name = name;            var newColor = new CMYKColor();        newColor.cyan = c;        newColor.magenta = m;        newColor.yellow = y;        newColor.black = k;        newSpot.colorType = ColorModel.SPOT;        newSpot.color = newColor;        var newSpotColor = new SpotColor();        newSpotColor.spot = newSpot;  }
addSpot ('PCUT', 0, 50, 100, 0);
function addSpot(name, c, m, y, k) {    try {        swatch = app.activeDocument.swatches[name]; // if swatch exists....        addSpot (name+='1', c, m, y, k); // ...add 1 to swatch name  }    catch (e) {        var newSpot = app.activeDocument.spots.add();        newSpot.name = name;            var newColor = new CMYKColor();        newColor.cyan = c;        newColor.magenta = m;        newColor.yellow = y;        newColor.black = k;        newSpot.colorType = ColorModel.SPOT;        newSpot.color = newColor;        var newSpotColor = new SpotColor();        newSpotColor.spot = newSpot;
}
addSpot ('NOTE', 0, 0, 0, 50);
function addSpot(name, c, m, y, k) {    try {        swatch = app.activeDocument.swatches[name]; // if swatch exists....        addSpot (name+='1', c, m, y, k); // ...add 1 to swatch name  }    catch (e) {        var newSpot = app.activeDocument.spots.add();        newSpot.name = name;            var newColor = new CMYKColor();        newColor.cyan = c;        newColor.magenta = m;        newColor.yellow = y;        newColor.black = k;        newSpot.colorType = ColorModel.SPOT;        newSpot.color = newColor;        var newSpotColor = new SpotColor();        newSpotColor.spot = newSpot;  }
}
}
}
}

 

 

DIECUT_move_spot_cut_crease_pcut_note_to_separate_layers - move all object with stroke CUT to layer CUT, same with CREASE,PCUT lines as well as NOTES

 

#target Illustrator


var doc = app.activeDocument;
var paths = doc.pathItems;
var destLayer = doc.layers.getByName ("CUT");
var spotItems = new Array();


for (var g=0; g<paths.length;g++){    if (paths[g].strokeColor.typename == "SpotColor" && paths[g].strokeColor.spot.name == "CUT") {        spotItems.push(paths[g]);    };
};

for (g=0; g<spotItems.length;g++){     spotItems[g].move(destLayer, ElementPlacement.PLACEATBEGINNING);
};


var doc = app.activeDocument;
var paths = doc.pathItems;
var destLayer = doc.layers.getByName ("CREASE");
var spotItems = new Array();


for (var g=0; g<paths.length;g++){    if (paths[g].strokeColor.typename == "SpotColor" && paths[g].strokeColor.spot.name == "CREASE") {        spotItems.push(paths[g]);    };
};

for (g=0; g<spotItems.length;g++){     spotItems[g].move(destLayer, ElementPlacement.PLACEATBEGINNING);
};


var doc = app.activeDocument;
var paths = doc.pathItems;
var destLayer = doc.layers.getByName ("PCUT");
var spotItems = new Array();


for (var g=0; g<paths.length;g++){    if (paths[g].strokeColor.typename == "SpotColor" && paths[g].strokeColor.spot.name == "PCUT") {        spotItems.push(paths[g]);    };
};

for (g=0; g<spotItems.length;g++){     spotItems[g].move(destLayer, ElementPlacement.PLACEATBEGINNING);
};


var doc = app.activeDocument;
var paths = doc.pathItems;
var destLayer = doc.layers.getByName ("NOTE");
var spotItems = new Array();


for (var g=0; g<paths.length;g++){    if (paths[g].strokeColor.typename == "SpotColor" && paths[g].strokeColor.spot.name == "NOTE") {        spotItems.push(paths[g]);    };
};

for (g=0; g<spotItems.length;g++){     spotItems[g].move(destLayer, ElementPlacement.PLACEATBEGINNING);
};

Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>