Hi @brian_p_dts, I've rejigged your code, to my taste, and might be not appropriate to your exact needs, but I hope it will give us a platform to understand your problem (which I don't understand yet). Can you have a look and see if you can glean anything further?
- Mark
var designDoc = app.activeDocument,
designLayer = designDoc.layers[0];
var collarColors = getCollarColors(designDoc, designLayer);
if (collarColors != undefined)
alert('We have collarColors');
else
alert('Nothing');
function getCollarColors(doc, layer) {
// I don't like the try-catch approach,
// preferring to offload to a fault-tolerant
// function getByName. MUCH easier to read.
var collarItem = getByName(layer.pathItems, "Collar-Main");
if (collarItem == undefined)
collarItem = getByName(layer.groupItems, "Collar-Main");
if (collarItem == undefined)
return undefined;
// I think it is good form to fill out
// your object notation even if many
// properties are undefined, so that when
// you go back to look over your code
// it is easy to see what you intended.
// I also suggest you don't create unnecessary
// structure yet (eg. collarColors), and give
// more explicit property name (eg. mainCollar vs main)
var mainCollar = {
obj: collarItem,
color: undefined,
isSpot: undefined,
isGradient: undefined,
dupe: undefined
};
// target collarItem not collarColors.main
// 'clipped' no 'isClipped'
if (!collarItem.clipped) {
mainCollar.color = collarItem.fillColor;
mainCollar.isSpot = collarItem.fillColor.typename == "SpotColor";
mainCollar.isGradient = collarItem.fillColor.typename == "GradientColor"
}
if (collarItem.clipped || mainCollar.isGradient) {
app.activeDocument = doc;
mainCollar.dupe = collarItem.duplicate(layer);
}
// can give the structure here
// (if needed, which I doubt)
return { mainCollar: mainCollar };
};
function getByName(styles, name) {
for (var i = 0; i < styles.length; i++)
if (styles[i].name == name)
return styles[i];
};