Copy link to clipboard
Copied
I wrote following script to export time line as png sequence i want to optimize the code.
Please advise
// enable double clicking from the Macintosh Finder or the Windows Explorer
#target photoshop
// in case we double clicked the file
app.bringToFront();
var folder_path = Folder.selectDialog("--- Select the source folder of PSDs ---");
var folder_files = folder_path.getFiles( );
var folder_file1 = folder_files[0];
// =======================================================
var idOpn = charIDToTypeID( "Opn " );
var desc46 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc46.putPath( idnull, new File( folder_file1 ) ); //"C:\\Users\\vt30353\\Desktop\\delete\\mubarakh\\Tentacle_04_00000.png"
var idsequence = stringIDToTypeID( "sequence" );
desc46.putBoolean( idsequence, true );
var idframeRate = stringIDToTypeID( "frameRate" );
desc46.putDouble( idframeRate, 12.500000 );
executeAction( idOpn, desc46, DialogModes.NO );
/*
// =======================================================
var idOpn = charIDToTypeID( " Opn " );
var desc17 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc17.putPath( idnull, new File( folder_file1 ) ); //"C:\\Users\\vt30353\\Desktop\\delete\\mubarakh\\Tentacle_04_00000.png"
var idsequence = stringIDToTypeID( "sequence" );
desc17.putBoolean( idsequence, true );
var idframeRate = stringIDToTypeID( "frameRate" );
desc17.putDouble( idframeRate, 12.500000 );
executeAction( idOpn, desc17, DialogModes.NO );
*/
// =======================================================
var idmakeLayersFromFrames = stringIDToTypeID( "makeLayersFromFrames" );
var desc47 = new ActionDescriptor();
executeAction( idmakeLayersFromFrames, desc47, DialogModes.NO );
// =======================================================
var idmakeFramesFromLayers = stringIDToTypeID( "makeFramesFromLayers" );
var desc48 = new ActionDescriptor();
executeAction( idmakeFramesFromLayers, desc48, DialogModes.NO );
// =======================================================
var idconvertTimeline = stringIDToTypeID( "convertTimeline" );
var desc51 = new ActionDescriptor();
executeAction( idconvertTimeline, desc51, DialogModes.NO );
// =======================================================
var idDlt = charIDToTypeID( "Dlt " );
var desc103 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref20 = new ActionReference();
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref20.putEnumerated( idanimationFrameClass, idOrdn, idTrgt );
desc103.putReference( idnull, ref20 );
executeAction( idDlt, desc103, DialogModes.NO );
//======================================================
// =======================================================
var idDlt = charIDToTypeID( "Dlt " );
var desc103 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref20 = new ActionReference();
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref20.putEnumerated( idanimationFrameClass, idOrdn, idTrgt );
desc103.putReference( idnull, ref20 );
executeAction( idDlt, desc103, DialogModes.NO );
//======================================================
/*
var docRef = app.activeDocument;
var vikas = docRef.layers.length;
var counter = vikas-3;
var ocounter = vikas-vikas;
var tempcounter = vikas-4;
var cc_tempcounter = counter-1; //12
*/
//alert(cc_tempcounter);
var docRef = app.activeDocument;
var layer_count = docRef.layers.length;
var framecount = layer_count-1
var layer_count1 = layer_count-2
//alert(layer_count1);
// ======================================================= select frame
var idslct = charIDToTypeID( "slct" );
var desc217 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref54 = new ActionReference();
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
ref54.putIndex( idanimationFrameClass, layer_count-3 ); //ref54.putIndex( idanimationFrameClass, 9 ); Select last frame
desc217.putReference( idnull, ref54 );
executeAction( idslct, desc217, DialogModes.NO );
// =======================================================
var idDplc = charIDToTypeID( "Dplc" );
var desc255 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref70 = new ActionReference();
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref70.putEnumerated( idanimationFrameClass, idOrdn, idTrgt );
desc255.putReference( idnull, ref70 );
executeAction( idDplc, desc255, DialogModes.NO );
// ======================================================= select frame
var idslct = charIDToTypeID( "slct" );
var desc217 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref54 = new ActionReference();
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
ref54.putIndex( idanimationFrameClass, layer_count-2 ); //ref54.putIndex( idanimationFrameClass, 9 ); Select last frame
desc217.putReference( idnull, ref54 );
executeAction( idslct, desc217, DialogModes.NO );
// =======================================================
var idDplc = charIDToTypeID( "Dplc" );
var desc255 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref70 = new ActionReference();
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref70.putEnumerated( idanimationFrameClass, idOrdn, idTrgt );
desc255.putReference( idnull, ref70 );
executeAction( idDplc, desc255, DialogModes.NO );
//////////Select Frame/////////////
////////////////second last start///////////////////
// ======================================================= select frame
var idslct = charIDToTypeID( "slct" );
var desc217 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref54 = new ActionReference();
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
ref54.putIndex( idanimationFrameClass, (framecount-1)); //ref54.putIndex( idanimationFrameClass, 9 ); Select last frame
desc217.putReference( idnull, ref54 );
executeAction( idslct, desc217, DialogModes.NO );
// =======================================================
var idShw = charIDToTypeID( "Shw " );
var desc1330 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list108 = new ActionList();
var ref273 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref273.putName( idLyr,"Frame "+(layer_count1-1)); //here we change the layer selection "Frame 13"
list108.putReference( ref273 );
desc1330.putList( idnull, list108 );
var idTglO = charIDToTypeID( "TglO" );
desc1330.putBoolean( idTglO, true );
executeAction( idShw, desc1330, DialogModes.NO );
////////////////second last close ///////////////////
//////////////// last start///////////////////
// ======================================================= select frame
var idslct = charIDToTypeID( "slct" );
var desc217 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref54 = new ActionReference();
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
ref54.putIndex( idanimationFrameClass, framecount); //ref54.putIndex( idanimationFrameClass, 9 ); Select last frame
desc217.putReference( idnull, ref54 );
executeAction( idslct, desc217, DialogModes.NO );
// =======================================================
var idShw = charIDToTypeID( "Shw " );
var desc1330 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list108 = new ActionList();
var ref273 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref273.putName( idLyr,"Frame "+layer_count1); //here we change the layer selection "Frame 13"
list108.putReference( ref273 );
desc1330.putList( idnull, list108 );
var idTglO = charIDToTypeID( "TglO" );
desc1330.putBoolean( idTglO, true );
executeAction( idShw, desc1330, DialogModes.NO );
////////////////last close ///////////////////
var conferm_scale = confirm ("Scale the animation 50%?");
var conferm_scale = conferm_scale;
if(conferm_scale == true){
// =======================================================
var idImgS = charIDToTypeID( "ImgS" );
var desc79 = new ActionDescriptor();
var idWdth = charIDToTypeID( "Wdth" );
var idPrc = charIDToTypeID( "#Prc" );
desc79.putUnitDouble( idWdth, idPrc, 50.000000 );
var idCnsP = charIDToTypeID( "CnsP" );
desc79.putBoolean( idCnsP, true );
var idIntr = charIDToTypeID( "Intr" );
var idIntp = charIDToTypeID( "Intp" );
var idautomaticInterpolation = stringIDToTypeID( "automaticInterpolation" );
desc79.putEnumerated( idIntr, idIntp, idautomaticInterpolation );
executeAction( idImgS, desc79, DialogModes.NO );
}else {
//alert("animation not scaledown") ;
}
///+++++++++++++++++++++ Scale animkation +++++++++++++++++++
//var folder_path = folder_path.slice (0, 1)
var exportfolder = new Folder(folder_path+"/"+"pngs");
if(!exportfolder.exists) exportfolder.create();
//// File exported ///////////// ------------------------------------------------------------
// =======================================================
var idExpr = charIDToTypeID( "Expr" );
var desc110 = new ActionDescriptor();
var idUsng = charIDToTypeID( "Usng" );
var desc111 = new ActionDescriptor();
var iddirectory = stringIDToTypeID( "directory" );
desc111.putPath( iddirectory, new File( exportfolder) );
var idsequenceRenderSettings = stringIDToTypeID( "sequenceRenderSettings" );
var desc112 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc113 = new ActionDescriptor();
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIN = charIDToTypeID( "PGIN" );
desc113.putEnumerated( idPGIT, idPGIT, idPGIN );
var idPNGf = charIDToTypeID( "PNGf" );
var idPNGf = charIDToTypeID( "PNGf" );
var idPGAd = charIDToTypeID( "PGAd" );
desc113.putEnumerated( idPNGf, idPNGf, idPGAd );
var idCmpr = charIDToTypeID( "Cmpr" );
desc113.putInteger( idCmpr, 9 );
var idPNGF = charIDToTypeID( "PNGF" );
desc112.putObject( idAs, idPNGF, desc113 );
var idsequenceRenderSettings = stringIDToTypeID( "sequenceRenderSettings" );
desc111.putObject( idsequenceRenderSettings, idsequenceRenderSettings, desc112 );
var idminDigits = stringIDToTypeID( "minDigits" );
desc111.putInteger( idminDigits, 4 );
var idstartNumber = stringIDToTypeID( "startNumber" );
desc111.putInteger( idstartNumber, 0 );
var iduseDocumentSize = stringIDToTypeID( "useDocumentSize" );
desc111.putBoolean( iduseDocumentSize, true );
var idframeRate = stringIDToTypeID( "frameRate" );
desc111.putDouble( idframeRate, 15.000000 );
var idallFrames = stringIDToTypeID( "allFrames" );
desc111.putBoolean( idallFrames, true );
var idrenderAlpha = stringIDToTypeID( "renderAlpha" );
var idalphaRendering = stringIDToTypeID( "alphaRendering" );
var idstraight = stringIDToTypeID( "straight" );
desc111.putEnumerated( idrenderAlpha, idalphaRendering, idstraight );
var idQlty = charIDToTypeID( "Qlty" );
desc111.putInteger( idQlty, 1 );
var idZthreeDPrefHighQualityErrorThreshold = stringIDToTypeID( "Z3DPrefHighQualityErrorThreshold" );
desc111.putInteger( idZthreeDPrefHighQualityErrorThreshold, 5 );
var idvideoExport = stringIDToTypeID( "videoExport" );
desc110.putObject( idUsng, idvideoExport, desc111 );
executeAction( idExpr, desc110, DialogModes.ALL );
///////////////////////////////++++++++++++++++++Save file++++++++++++++
var filename = prompt ( "file name dont use .psd");
// =======================================================
var idsave = charIDToTypeID( "save" );
var desc172 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc173 = new ActionDescriptor();
var idmaximizeCompatibility = stringIDToTypeID( "maximizeCompatibility" );
desc173.putBoolean( idmaximizeCompatibility, true );
var idPhtthree = charIDToTypeID( "Pht3" );
desc172.putObject( idAs, idPhtthree, desc173 );
var idIn = charIDToTypeID( "In " );
desc172.putPath( idIn, new File( exportfolder+"\\"+filename+".psd") );
var idDocI = charIDToTypeID( "DocI" );
desc172.putInteger( idDocI, 3486 );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveBegin = stringIDToTypeID( "saveBegin" );
desc172.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
executeAction( idsave, desc172, DialogModes.NO );
Copy link to clipboard
Copied
Are you sure that script listener code does what you claim. It looks like that script would try to open the first file in a folder that you select no matter what kind of file it may be. I do not see any loop you added to process frames in a timeline. The sequenced Make layers from frames follow by make frames from layers seem wrongs to me where did the Frame animation come from I see no create frame animation was the first file required to have a frame animation if so would it not already have the layers and frames. Why select a folder of files if you only process the first entry in the folder. I can not believe that is a working script.
Copy link to clipboard
Copied
Thanks for reply
script working fine for me!
I have created this script to change the animation frame rate and change the last two frames only.
It looks like that script would try to open the first file in a folder that you select no matter what kind of file it may be.
-- when user should select the destination folder is full of ".png" images only! (no other type of files will be there)
I do not see any loop you added to process frames in a timeline
-- Check the line number 21,22,23 code "( idsequence, true );" This code add all files and put on timeline so no need to write loop for this.