I've never had this problem with extendscript before and I thought extendscript was synchronous. I'm looping thru an array: for each object in the array I'm opening, reading and updating an xml and then importing it into PPro. I think the loop is finishing faster than the file update and import - no files are being imported.
If I alert(array[i])
each time everything works but once I comment out the alert the files no longer import.
function importXML(targetFile){
app.project.importFiles([targetFile], 1); // 1 == suppress UI
updateEventPanel('Media imported for ' + show);
return 'success';
}
function processXML(obj){
var shows = obj.shows;
// alert(shows.length);
var currentShow = obj.shows[0];
for(var i = 0; i < shows.length-1; i++){
var xmlDoc = obj.targetXml;
var show = obj.shows[i+1];
// alert('currentShow: ' + currentShow);
// alert('show: ' + show);
var currentValue1 = new RegExp('<Name>'+ currentShow, 'g');
var currentValue2 = new RegExp('HIGHLIGHT_VERSIONING/'+ currentShow, 'g');
var newValue1 = '<Name>'+ show;
var newValue2 = 'HIGHLIGHT_VERSIONING/'+ show;
var myFile = new File(xmlDoc);
myFile.open('e', undefined, undefined);
var inText = myFile.read();
inText = inText
.replace(currentValue1, newValue1)
.replace(currentValue2, newValue2);
myFile.seek(0);
myFile.write(inText);
myFile.close();
updateEventPanel('XML updated for ' + show);
importXML(xmlDoc);
// updateEventPanel('Media imported for ' + show);
currentShow = show;
};
}