Found your problem. applyPresset applies to all selected layers. So you should deselect them all after saving your numLayer variable, and select each one when needed, then deselect it again. I ran into this problem before. I have a function that i sometimes use . So i think this should solve your problem.
{
app.beginUndoGroup("Link Stroke Color");
var myComp = app.project.activeItem;
var numLayer = myComp.selectedLayers;
var colorExp = '(expression placeholder - for code length reasons :D)"';
deselectEverything();
for (var a = 0; a < numLayer.length; a++) {
if (numLayer[a] instanceof ShapeLayer){
//it is a shape layer
scanPropGroupProperties(numLayer[a]);
} else {
//its not a shape layer
alert(numLayer[a].name + " is not a Shape Layer!");
numLayer[a].selected = true;
numLayer[a].applyPreset(File("D:\\fill.ffx"));
numLayer[a].selected=false;
}
}
//==============================================================================
function scanPropGroupProperties(propGroup){ //scans the proprieties and adds expressions to the strokes
var i, prop;
// Iterate over the specified property group's properties
for (i = 1; i <= propGroup.numProperties; i++){
prop = propGroup.property(i);
if (prop.propertyType === PropertyType.PROPERTY && prop.name === 'Color' && propGroup.canSetEnabled && prop.parentProperty.name.slice(0, 6) === 'Stroke'){ // Found a property
prop.expression = colorExp;
} else if ((prop.propertyType === PropertyType.INDEXED_GROUP) || (prop.propertyType === PropertyType.NAMED_GROUP)) {
// Found an indexed or named group, so check its nested properties
scanPropGroupProperties(prop);
}
}
}
app.endUndoGroup();
}
//==============================================================================
//Go through the current active composition and deselect everything
function deselectEverything() {
var myActiveComp = app.project.activeItem;
for (i = 1; i <= myActiveComp.numLayers; i++){
myActiveComp.layer(i).selected = false;
}
}
But i still don’t know why applyPreset acts this way.
Andrei
My Envato portfolio.