Copied!
It loops through all properties of a layer/layers and finds only the one with a specific matchName or name. You can decide whether to look for two different kinds of properties or to look for a property that passes both conditions (name & matchname)

function SmartPropertyLookup(specificLayers, nameOrMatch1, nm1, andOr, nameOrMatch2, nm2) {
try {
//recursive function to look for all properties that exist
function getProperties(currentProperty, propertyMatchName, propertyMatchName2, propsArray) {
propsArray = propsArray || [];
for (var i = 1, il = currentProperty.numProperties; i <= il; i++) {
switch (nameOrMatch1) {
case ("matchName"):
var condition1 = currentProperty.property(i).matchName === propertyMatchName;
break;
case ("name"):
var condition1 = currentProperty.property(i).name === propertyMatchName;
break;
}
switch (nameOrMatch2) {
case ("matchName"):
var condition2 = currentProperty.property(i).matchName === propertyMatchName2;
break;
case ("name"):
var condition2 = currentProperty.property(i).name === propertyMatchName2;
break;
}
if (andOr !== undefined && andOr.length > 0) {
switch (andOr) {
case ("and"):
var execCompare = condition1 && condition2;
break;
case ("or"):
var execCompare = condition1 || condition2;
break;
}
} else {
var execCompare = condition1
}
if (execCompare) {
propsArray.push(currentProperty.property(i));
}
getProperties(currentProperty.property(i), propertyMatchName, propertyMatchName2, propsArray);
}
//alert(propsArray);
return propsArray;
}
var composition = app.project.activeItem;
if (!composition || !(composition instanceof CompItem)) {
return; //alert("Please select composition first");
}
// will scan all layers in comp by default, unless some layers are selected
// alert(specificLayers == undefined);
if (specificLayers == undefined || specificLayers == "" || specificLayers == null) {
var selectedLayers = composition.numLayers;
var scanLength = composition.numLayers;
var initialIncrementFix = 1;
var scanMe = composition.layers;
} else {
if (specificLayers.length > 0) {
if (specificLayers.length > 1) {
var selectedLayers = specificLayers;
var scanLength = specificLayers.length;
var initialIncrementFix = 0;
var scanMe = selectedLayers;
} else {
var selectedLayers = specificLayers;
var initialIncrementFix = 0;
var scanLength = 1;
var scanMe = selectedLayers;
}
} else {
var selectedLayers = [specificLayers];
var initialIncrementFix = 0;
var scanLength = 1;
var scanMe = selectedLayers;
}
}
var layer;
var propertyToLookFor;
propertiesFound = [];
// For each selected layer
for (var i = 0, il = scanLength; i < il; i++) {
layer = scanMe[i + initialIncrementFix];
propertyToLookFor = getProperties(layer, nm1, nm2);
//Loop through all "ADBE Vector Shape" properties and do your magic
for (var j = 0, jl = propertyToLookFor.length; j < jl; j++) {
propertiesFound.push(propertyToLookFor[j]);
}
}
//alert(propertiesFound);
return propertiesFound;
} catch (e) {
alert("Smart Property Lookup Failed");
return false;
}
}