Script error control
Hi,
I have a script which in one part searches for a particular spot color in either the stroke or fill and moves it to a layer. I would like to know how to handle not finding that color and moving on with rest of script. As of now if it doesnt find the spot color it stops and gives an error message. Here is a copy of that section of code:
// find Dimensions color and move to Dimensions layer
var mydoc = app.activeDocument;
mydoc.selection = null;
mydoc.defaultStrokeColor = mydoc.swatches["Dimension"].color;
app.executeMenuCommand("Find Stroke Color menu item");
var doc = app.activeDocument;
var layerName = 'Dimensions';
var _layer = doc.layers.getByName(layerName);
var _selectedItems = app.selection
for (var i = _selectedItems.length - 1; i >= 0; i--) {
_selectedItems[i].move(_layer, ElementPlacement.PLACEATEND);
_selectedItems[i].selected = false;
}
app.redraw();
mydoc.selection = null;
mydoc.defaultFillColor = mydoc.swatches["Dimension"].color;
app.executeMenuCommand("Find Fill Color menu item");
var doc = app.activeDocument;
var layerName = 'Dimensions';
var _layer = doc.layers.getByName(layerName);
var _selectedItems = app.selection
for (var i = _selectedItems.length - 1; i >= 0; i--) {
_selectedItems[i].move(_layer, ElementPlacement.PLACEATEND);
_selectedItems[i].selected = false;
}
app.redraw();
Thanks,
Mark
