Script causes AE to Crash - any advice?
I've been working on a script that would go and replace all media with a user-specified file extention with placeholders. The script works, but not long after the script completes, AE will crash. I'm not seeing what the script is doing that couled cause this. I was hoping someone might have a suggestion?
And, the showMsg function is because when I use alert, the message would not appear. But using my custom message box function generally works. (Not always though!)
----
var w = new Window("palette", "Offline Media", undefined);
w.add ('statictext', undefined, "Enter media file suffix (e.g., mxf):");
var nameWindow = w.add ("edittext");
nameWindow.characters = 30;
var sb = w.add("button", undefined, "Start");
w.show();
sb.onClick = offlineFunction;
function offlineFunction() {
try {
var name = nameWindow.text.toLocaleLowerCase();
var count = 0;
for (var i = 1; i <= app.project.numItems; i++) {
var footageItem = app.project.items[i];
if (footageItem instanceof FootageItem) {
var filename = footageItem.file.name;
var idx = filename.lastIndexOf(".");
if (idx > 0) {
var suffix = filename.slice(idx+1).toLocaleLowerCase();
if (suffix.localeCompare(name) == 0) {
count++;
fr = footageItem.frameRate;
if (fr < 1) fr = 1;
dur = footageItem.duration;
if (dur < 1) dur = 1;
footageItem.replaceWithPlaceholder(filename, footageItem.width, footageItem.height, fr, dur); // name, width, height, frameRate, duration)
}
}
}
}
var msg = "Offlined " + count + " media items.";
showMsg(msg);
} catch (e) {
var msg = "Exception! " + e;
showMsg(msg);
}
}
function showMsg(msg) {
var myWindow = new Window ("dialog");
var myMessage = myWindow.add ("statictext");
myMessage.text = msg;
myWindow.add("button", undefined, "OK").onClick = function(){myWindow.close();}
myWindow.show ( );
}
