Thursday, March 24, 2011

Photoshop Scripting Tutorials

So far I've actually had alot of issues finding scripting tutorials for photoshop. Adobe InDesign has a ton of scripting tutorials, however, after searching through the Adobe website, youTube, Google, and other resources I was only able to find a few. Either way I did my best, and followed one tutorial that was written, and then followed a youTube video tutorial.

What actually helped me the most in understanding the code, waqs the video tutorial, and then going into photoshop, doing a few simple tasks, and then going through the script listener file ity created. For example this picture, was made by this code:














// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc26 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var desc27 = new ActionDescriptor();
var idpreset = stringIDToTypeID( "preset" );
desc27.putString( idpreset, "Default Photoshop Size" );
var idDcmn = charIDToTypeID( "Dcmn" );
desc26.putObject( idNw, idDcmn, desc27 );
executeAction( idMk, desc26, DialogModes.NO );

// =======================================================
var idFl = charIDToTypeID( "Fl " );
var desc28 = new ActionDescriptor();
var idFrom = charIDToTypeID( "From" );
var desc29 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idRlt = charIDToTypeID( "#Rlt" );
desc29.putUnitDouble( idHrzn, idRlt, 120.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idRlt = charIDToTypeID( "#Rlt" );
desc29.putUnitDouble( idVrtc, idRlt, 96.000000 );
var idPnt = charIDToTypeID( "Pnt " );
desc28.putObject( idFrom, idPnt, desc29 );
var idTlrn = charIDToTypeID( "Tlrn" );
desc28.putInteger( idTlrn, 32 );
var idAntA = charIDToTypeID( "AntA" );
desc28.putBoolean( idAntA, true );
var idUsng = charIDToTypeID( "Usng" );
var idFlCn = charIDToTypeID( "FlCn" );
var idFrgC = charIDToTypeID( "FrgC" );
desc28.putEnumerated( idUsng, idFlCn, idFrgC );
executeAction( idFl, desc28, DialogModes.NO );

// =======================================================
var idsave = charIDToTypeID( "save" );
var desc30 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc31 = new ActionDescriptor();
var idEQlt = charIDToTypeID( "EQlt" );
desc31.putInteger( idEQlt, 8 );
var idMttC = charIDToTypeID( "MttC" );
var idMttC = charIDToTypeID( "MttC" );
var idNone = charIDToTypeID( "None" );
desc31.putEnumerated( idMttC, idMttC, idNone );
var idJPEG = charIDToTypeID( "JPEG" );
desc30.putObject( idAs, idJPEG, desc31 );
var idIn = charIDToTypeID( "In " );
desc30.putPath( idIn, new File( "C:\\Users\\Owner\\Desktop\\Untitled-2.jpg" ) );
executeAction( idsave, desc30, DialogModes.NO );

// =======================================================
var idCls = charIDToTypeID( "Cls " );
executeAction( idCls, undefined, DialogModes.NO );


To be able to go through the code and pick out where the commands lie really helped me understand this. Unfortunately it's not very exciting, but I'm going to try some effects soon too.

The written tutorial, was to create a code that switched between layers.

My final product (after following the tutorial) was this:

if (documents.length == 0) {
alert("there are no deocuments open,");
}

else {
var docRef = activeDocument;
var layerRef = docRef.activeLayer;
if (docRef.layers.length == 1 && layerRef.isBackgroundLayer == true) {
alert("the background layer can not be hidden when it's the only layer in a document.");
}
else {
layerRef.visible = !layerRef.visible;
}
}


Sadly, I couldn't get it to work, I saved it as a .js file, and brought it into photoshop, but couldn't figure exactly how to test it out. What I'm trying next is I'm going to create a photo with multiple layers and then run it.



written tutorial link: http://morris-photographics.com/photoshop/tutorials/scripting2.html

video link: http://www.youtube.com/watch?v=hs0JydYtKng

No comments:

Post a Comment