In you specific case there is a workaround.
replaceWithPlaceholder() method changes the mainSource property and it seems that an Undo, even if apparently you can see the correct file, still leaves mainSource property of type PlaceholderSource.
To avoid this, I simply replaced the item with a solid. 
Here's the full script (also attached):
Code: Select all
function runReplaceWithPlaceHolder ()
{
if (app.project.selection.length > 0) // Process only if user selected some Project Panel items
{
app.beginUndoGroup('Swap to proxy and replace with placeholder');
var
options = {},
replaceCount,
confirmCustomOptions = confirm('Do you want to use other settings for the placeholders?\n\nDefaults:\n- width: 3840\n- height: 2160\n- fps: 30');
if (confirmCustomOptions)
{
options.width = prompt('Width (leave blank for the default value):', '', 'Placeholder options');
options.height = prompt('Height (leave blank for the default value):', '', 'Placeholder options');
options.fps = prompt('Fps (leave blank for the default value):', '', 'Placeholder options');
}
replaceCount = replaceWithPlaceholderRecursive(app.project.selection, options);
app.endUndoGroup();
alert('Successfully replaced ' + replaceCount + ' item' + String(replaceCount > 1 ? 's' : '') + '.', 'Done!', false);
}
else
{
alert('You must selected at least one Project Panel item', 'No items selected.', false);
}
}
function replaceWithPlaceholderRecursive (itemsArr, options, count)
{
var
curItem,
/*
replaceWithPlaceholder() requires parameter 1 (item name) to have 31 characters after the conversion
So, we'll save each item's name and id so we can rename each of the placeholders afterwards
*/
savedItems = {
"names": [],
"ids": []
};
// Some `options` argument checks
if (typeof options !== 'object' || options == null)
{
options = {
"width": 3840,
"height": 2160,
"fps": 30
};
}
else
{
if (!options.hasOwnProperty('width') || isNaN(parseInt(options.width))) options.width = 3840;
if (!options.hasOwnProperty('height') || isNaN(parseInt(options.height))) options.height = 2160;
if (!options.hasOwnProperty('fps') || isNaN(parseFloat(options.fps)) || options.fps < 1) options.fps = 30;
}
if (typeof count === 'undefined') count = 0;
for (var i = 0, iLen = itemsArr.length; i < iLen; i++)
{
curItem = itemsArr[i];
if (curItem instanceof FootageItem && curItem.mainSource instanceof FileSource && !(curItem.mainSource instanceof PlaceholderSource) && curItem.hasVideo)
{
count++;
savedItems.names.push(curItem.name);
savedItems.ids.push(curItem.id);
if (isFileSequence(curItem)) curItem.setProxyWithSequence(curItem.mainSource.file, false);
else curItem.setProxy(curItem.mainSource.file);
// curItem.replaceWithPlaceholder(curItem.name.substr(0, 31), parseInt(options.width), parseInt(options.height), options.fps, curItem.duration);
curItem.replaceWithSolid([0.21167242527008, 0.80082058906555, 0.87058824300766], curItem.name.substr(0, 31), parseInt(options.width), parseInt(options.height), curItem.pixelAspect);
}
else if (curItem instanceof FolderItem)
{
var binItems = [];
for (var k = 1, kLen = curItem.numItems; k <= kLen; k++) binItems.push(curItem.item(k));
count += replaceWithPlaceholderRecursive(binItems, options, count);
}
}
// Add initial items names
for (var i = 0, iLen = savedItems.ids.length; i < iLen; i++)
{
app.project.itemByID(savedItems.ids[i]).name = savedItems.names[i]; // itemByID() introduced in CC2014
}
// Dump variables
savedItems.names = [];
savedItems.ids = [];
curItem = null;
return count;
}
function isFileSequence (item)
{
if (item instanceof FootageItem && item.mainSource instanceof FileSource && !(item.mainSource.isStill) && item.hasVideo)
{
var extname = item.mainSource.file.fsName.split('.').pop();
return extname.match(new RegExp("(ai|bmp|bw|cin|cr2|crw|dcr|dng|dib|dpx|eps|erf|exr|gif|hdr|ico|icb|iff|jpe|jpeg|jpg|mos|mrw|nef|orf|pbm|pef|pct|pcx|pdf|pic|pict|png|ps|psd|pxr|raf|raw|rgb|rgbe|rla|rle|rpf|sgi|srf|tdi|tga|tif|tiff|vda|vst|x3f|xyze)", "i")) !== null;
}
return false;
}
runReplaceWithPlaceHolder();
Cheers!