Question
Collect files script not working
i saw a scipt of VIDCRAFTER
in here:
Is there a way to call Collect Files with Extendsc... - Adobe Community - 6906263
and try to debug and use it for myself, but it just can't copy and replace the source as default AE tool, can anyone please help me
// -- GET PROJECT PATH --//
function get_ProjectPath(){
var projectPath = '';
if (app.project.file != null) {
projectPath = app.project.file.fsName;
}
return projectPath;
}
g_projectPath = get_ProjectPath();
// -- GET collect_files --//
var OPpath = "C:\\Test"
var originalName = g_projectPath.split("\\").pop();
var baseName = originalName.substring(0, originalName.lastIndexOf("."));
function createFolderIfNotExists(folderPath) {
var folder = new Folder(folderPath);
if (!folder.exists) {
folder.create();
}
}
function includes(array, value) {
for (var i = 0; i < array.length; i++) {
if (value.indexOf(array[i]) !== -1) {
return true;
}
}
return false;
}
function collect_files(target_path) {
// Create folder if app project do not exits
var project_dir = target_path.toString() + "/" + baseName;
createFolderIfNotExists(project_dir);
var footage_dir = project_dir + "/(Footage)";
createFolderIfNotExists(footage_dir);
for (i = 1; i <= app.project.numItems; i++) {
item = app.project.item(i)
// Check these before continuing.
if (item instanceof FootageItem == false) {
continue
}
;
if (item.file == null) {
continue
}
;
if (item.footageMissing) {
continue
}
;
// Get item's extension. Will be used to differentiate between image sequences and other media.
var item_extension = item.file.name.split('.').pop();
//alert (item_extension)
// Make the item's directory if it doesn't exist
var item_dir = new Folder(footage_dir.toString() + "\\" + item.parentFolder.name);
createFolderIfNotExists(item_dir);
alert ("item_dir:" + item_dir.path)
// Create target dir and target file variables
var target_dir = new Folder(footage_dir.toString() + "\\" + item.parentFolder.name);
createFolderIfNotExists(target_dir);
alert ("target_dir:" + target_dir.path)
var target_file = new File(target_dir.toString() + "\\" + item.file.name);
createFolderIfNotExists(target_file);
//alert ("target_file:" + target_file.name)
// If the target is a still.
if (item.mainSource.isStill) {
item.file.copy(target_dir.absoluteURI + "\\" + item.file.name);
item.replace(target_file);
continue
}
// list of still image extensions
var still_extensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp', 'ico', 'tif', 'tiff', 'eps', 'raw', 'ai', 'ps', 'indd', 'pdf', 'xcf', 'sketch', 'xd', 'cin', 'dpx', 'exr', 'pxr', 'rla', 'hdr', 'tga'];
var footage_extensions = ['mov', 'avi', 'mpeg', 'mp4', 'wmv', 'flv', 'mkv', 'webm', 'ogg', 'wav', 'mp3', 'aac', 'aiff', 'flac'];
//If it's a footages sequence.
if (includes(footage_extensions, item_extension)) {
item.file.copy(target_dir.toString() + "\\" + item.file.name);
item.replace(target_file);
}
//If it's a image sequence.
if (includes(still_extensions, item_extension)) {
var source_folder = item.file.parent;
var frames = source_folder.getFiles();
alert("Source folder: " + source_folder.path);
alert("Number of frames: " + frames.length);
for (f = 0; f<frames.length; f++){
frame = frames[f]
frame.copy(target_dir.toString() + "\\" + frame.name)
}
try {
item.replaceWithSequence(target_file, true)
} catch (e){
alert(item.name)
}
}
}
app.project.save(new File(project_dir.toString() + "\\" + app.project.file.name));
}
collect_files(OPpath); // Call savefile() here
