Skip to main content
Known Participant
March 18, 2019
Question

error while running script for multiple files

  • March 18, 2019
  • 1 reply
  • 439 views

Hi All,

I have script for Spliting artboard layers. it works fine as a single file or multiple files. but if the file does not have that layer what i need to export. the script stops working. not move to verify another file stucks with the same file.

var names = ["Opaque White Layer", "Opaque White 2nd Layer", "Frosted White Layer"];

doesLayerExist(app.activeDocument.layers, names)

function doesLayerExist(layers, names) {

for (i=0; i<layers.length; i++) {

for (j=0; j<names.length; j++) {

if (layers.name==names) return true;

}

}

return false;

}

if there is no

["Opaque White Layer", "Opaque White 2nd Layer", "Frosted White Layer"];

the script fails to move to analyse next file.

This topic has been closed for replies.

1 reply

CarlosCanto
Community Expert
Community Expert
March 18, 2019

the script is failing somewhere else, we need to see more of your code.

Known Participant
March 18, 2019

//Create the new Artbaord for the White Ink Layers if those are available

var names = ["Opaque White Layer", "Opaque White 2nd Layer", "Frosted White Layer"];

doesLayerExist(app.activeDocument.layers, names)

function doesLayerExist(layers, names) {

for (i=0; i<layers.length; i++) {

for (j=0; j<names.length; j++) {

if (layers.name==names) return true;

}

}

return false;

}

if (doesLayerExist(app.activeDocument.layers, names)) {

ArtLayer = myLayers.getByName ("Cutterguide");

ArtLayer.locked = false;

app.executeMenuCommand('unlockAll');

var thisBoardIndex = doc.artboards.getActiveArtboardIndex();

var thisBoard = doc.artboards[thisBoardIndex];

var thisRect = thisBoard.artboardRect;

var lastBoard = doc.artboards[doc.artboards.length - 1];

var lastRect = lastBoard.artboardRect;

doc.selectObjectsOnActiveArtboard();

app.copy();

var newBoard = doc.artboards.add(thisRect);

var offsetH = 20;

newBoard.artboardRect = [

lastRect[2] + offsetH,

lastRect[1],

lastRect[2] + offsetH + (thisRect[2] - thisRect[0]),

lastRect[3]

];

newBoard.name = thisBoard.name + " copy";

app.executeMenuCommand("pasteFront");

doc.selection = null;

var docRef = app.activeDocument;

var myLayers = docRef.layers;

ArtLayer = myLayers.getByName ("Cutterguide");

ArtLayer.locked = true;

var ABName = "Artboard 1";

function setActiveArtboardBy(name) {

var artboard = docRef.artboards.getByName(name);

for (i = 0; i < docRef.artboards.length; i++) {

if (docRef.artboards == artboard) {

docRef.artboards.setActiveArtboardIndex(i);

break;

}

}

}

//Go to active artboard

setActiveArtboardBy(ABName);

var doc = app.activeDocument;

doc.selectObjectsOnActiveArtboard()

app.executeMenuCommand("clear");

}

}