Copy link to clipboard
Copied
How can I Export - Render Video in script so that it will not overwrite the exported video when running through several files? I have tried calling an action in script but the action always writes to the same name. Is it possible for an action to be called multiple times and have a different name each time. Or maybe it has to be done in script? Either way would be fine as long as I can find a way that will work. Thanks.
Copy link to clipboard
Copied
Actions and scripts are different things.
If you record the action without changing the filename, then the action will use whatever the current filename is. In other words, it will not record an explicit filename entry. If you change the name, then the name is recorded into the action, overwriting previous files.
Copy link to clipboard
Copied
Yes, that's the problem. It overwrites the filename. So I guess it's not possible using an action. How can I Export - Render Video using script so that hopefully I can write out the video files using the filenames that I am processing?
Copy link to clipboard
Copied
Please read my post again. It is possible. Don't change the filename when recording the action.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That screenshot doesn't have a separate line including the filename, so it will use the current doc name. The only way that it will override an existing file is when a file of the same name exists.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I don't know if this helps but here is a snippet of the script that I am using. Writing out the jpg files works fine. But not the video part.
if (theFiles) {
for (var m = 0; m < theFiles.length; m++) {
// Replace SmartObject
theLayer = replaceContents(theFiles[m], theLayer);
var theNewName = theFiles[m].name.match(/(.*)\.[^\.]+$/)[1];
// Save JPG
myDocument.saveAs((new File(thePath + "/" + theNewName + ".jpg")), jpgSaveOptions, true,Extension.LOWERCASE);
// Action for File - Export - Render Video
app.doAction("Render Video", "Video Group");
}
}
Copy link to clipboard
Copied
I figured it out. For anyone else looking, the answer was here:
Copy link to clipboard
Copied
There is no need to script this, the action works. Here is the code directly recorded without including the filename, the same as the action in my previous screenshot:
#target photoshop
(function () {
// Set the output folder
var outputFolder = Folder.selectDialog("Please select the folder to export the video to...");
if (outputFolder === null) {
//alert('Script cancelled!');
return;
}
var idexport = stringIDToTypeID("export");
var desc252 = new ActionDescriptor();
var idusing = stringIDToTypeID("using");
var desc253 = new ActionDescriptor();
var iddirectory = stringIDToTypeID("directory");
desc253.putPath(iddirectory, new File( outputFolder ));
var idameFormatName = stringIDToTypeID("ameFormatName");
desc253.putString(idameFormatName, """H.264""");
var idamePresetName = stringIDToTypeID("amePresetName");
desc253.putString(idamePresetName, """1_High Quality.epr""");
var iduseDocumentSize = stringIDToTypeID("useDocumentSize");
desc253.putBoolean(iduseDocumentSize, true);
var iduseDocumentFrameRate = stringIDToTypeID("useDocumentFrameRate");
desc253.putBoolean(iduseDocumentFrameRate, true);
var idpixelAspectRatio = stringIDToTypeID("pixelAspectRatio");
var idpixelAspectRatio = stringIDToTypeID("pixelAspectRatio");
var iddocument = stringIDToTypeID("document");
desc253.putEnumerated(idpixelAspectRatio, idpixelAspectRatio, iddocument);
var idfieldOrder = stringIDToTypeID("fieldOrder");
var idvideoField = stringIDToTypeID("videoField");
var idpreset = stringIDToTypeID("preset");
desc253.putEnumerated(idfieldOrder, idvideoField, idpreset);
var idmanage = stringIDToTypeID("manage");
desc253.putBoolean(idmanage, true);
var idallFrames = stringIDToTypeID("allFrames");
desc253.putBoolean(idallFrames, true);
var idrenderAlpha = stringIDToTypeID("renderAlpha");
var idalphaRendering = stringIDToTypeID("alphaRendering");
var idnone = stringIDToTypeID("none");
desc253.putEnumerated(idrenderAlpha, idalphaRendering, idnone);
var idvideoExport = stringIDToTypeID("videoExport");
desc252.putObject(idusing, idvideoExport, desc253);
executeAction(idexport, desc252, DialogModes.NO);
}());
Compare this with the filename step recorded as per my previous action screenshot, where I have replaced the hard-coded name with the current document name:
#target photoshop
(function () {
// Set the output folder
var outputFolder = Folder.selectDialog("Please select the folder to export the video to...");
if (outputFolder === null) {
//alert('Script cancelled!');
return;
}
var idexport = stringIDToTypeID( "export" );
var desc279 = new ActionDescriptor();
var idusing = stringIDToTypeID( "using" );
var desc280 = new ActionDescriptor();
var iddirectory = stringIDToTypeID( "directory" );
desc280.putPath( iddirectory, new File( outputFolder ) );
var idname = stringIDToTypeID( "name" );
desc280.putString( idname, app.activeDocument.name.replace(/\.[^\.]+$/, '') );
var idameFormatName = stringIDToTypeID( "ameFormatName" );
desc280.putString( idameFormatName, """H.264""" );
var idamePresetName = stringIDToTypeID( "amePresetName" );
desc280.putString( idamePresetName, """1_High Quality.epr""" );
var iduseDocumentSize = stringIDToTypeID( "useDocumentSize" );
desc280.putBoolean( iduseDocumentSize, true );
var iduseDocumentFrameRate = stringIDToTypeID( "useDocumentFrameRate" );
desc280.putBoolean( iduseDocumentFrameRate, true );
var idpixelAspectRatio = stringIDToTypeID( "pixelAspectRatio" );
var idpixelAspectRatio = stringIDToTypeID( "pixelAspectRatio" );
var iddocument = stringIDToTypeID( "document" );
desc280.putEnumerated( idpixelAspectRatio, idpixelAspectRatio, iddocument );
var idfieldOrder = stringIDToTypeID( "fieldOrder" );
var idvideoField = stringIDToTypeID( "videoField" );
var idpreset = stringIDToTypeID( "preset" );
desc280.putEnumerated( idfieldOrder, idvideoField, idpreset );
var idmanage = stringIDToTypeID( "manage" );
desc280.putBoolean( idmanage, true );
var idallFrames = stringIDToTypeID( "allFrames" );
desc280.putBoolean( idallFrames, true );
var idrenderAlpha = stringIDToTypeID( "renderAlpha" );
var idalphaRendering = stringIDToTypeID( "alphaRendering" );
var idnone = stringIDToTypeID( "none" );
desc280.putEnumerated( idrenderAlpha, idalphaRendering, idnone );
var idvideoExport = stringIDToTypeID( "videoExport" );
desc279.putObject( idusing, idvideoExport, desc280 );
executeAction( idexport, desc279, DialogModes.NO );
}());
Both scripts produce the same result, the active document name is used.
An extra block of code would need to be added to check for an existing file and ask whether you wish to overwrite or not.