Again the handy executeCommand function came to the rescue

Code: Select all
var comp = app.project.activeItem;
var cmd = "Pixel Motion";
app.beginUndoGroup("FrameBlending.jsx");
if (comp instanceof CompItem)
{
// deselect all
while (comp.selectedLayers.length) comp.selectedLayers[0].selected = false;
// loop through each layer
for (var i = 1; i <= comp.numLayers; i++)
{
var layer = comp.layer(i);
// select current layer
layer.selected = true;
// set frame blending type to pixel motion
// when time stretch factor has been modified
if (layer.stretch != 100)
{
app.executeCommand(app.findMenuCommandId(cmd));
}
// deselect current layer
layer.selected = false;
}
// activate frame blending switch for the comp
comp.frameBlending = true;
}
app.endUndoGroup();