Reputation: 1
I started looking at scripting for photoshop. I have to say the whole action script code is a bit confusing for me. Is there a way around the whole action manager code?
I read that you can include other JS files
Maybe someone already build a libary for the action functions?
For example this libary could replace this:
var idMk = charIDToTypeID( "Mk " );
var desc21 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var desc22 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc22.putString( idNm, """Set 1""" );
var idASet = charIDToTypeID( "ASet" );
desc21.putObject( idNw, idASet, desc22 );
executeAction( idMk, desc21, DialogModes.NO );
With a single line:
MakeNewActionSet("Set 1", DialogModes.NO, [optional parameter]);
I found one project, but it's outdated. Does someone know something like that?
PS: My first post here. I hope it's not against the rules.
EDIT: I actually found something: JSON Action Manager
Upvotes: 0
Views: 303
Reputation: 6967
Yes. Is the short answer. And with reference to your example: If MakeNewActionSet was a function you could effectively substitute one for the other.
MakeNewActionSet("Set 1", DialogModes.NO);
function MakeNewActionSet(setnumber, dialogue)
{
var idMk = charIDToTypeID( "Mk " );
var desc21 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var desc22 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc22.putString( idNm, setnumber ); // set
var idASet = charIDToTypeID( "ASet" );
desc21.putObject( idNw, idASet, desc22 );
executeAction( idMk, desc21, dialogue ); //dialogue
}
that Whilst action script code is ugly and unreadable it does the job. Sometimes it is easier to get the script listener to record what you want. Other times it makes sense to go back and parameterize things. For example I've got a action script code here that will do a transform (rotate, offset and scale) I've just wrapped it up as a function - which makes it easier to read.
// function transform it
function transformIt(scaleX, scaleY, dx, dy, rot)
{
// =======================================================
var id3561 = charIDToTypeID( "Trnf" );
var desc725 = new ActionDescriptor();
var id3562 = charIDToTypeID( "null" );
var ref430 = new ActionReference();
var id3563 = charIDToTypeID( "Lyr " );
var id3564 = charIDToTypeID( "Ordn" );
var id3565 = charIDToTypeID( "Trgt" );
ref430.putEnumerated( id3563, id3564, id3565 );
desc725.putReference( id3562, ref430 );
var id3566 = charIDToTypeID( "FTcs" );
var id3567 = charIDToTypeID( "QCSt" );
var id3568 = charIDToTypeID( "Qcsa" );
desc725.putEnumerated( id3566, id3567, id3568 );
var id3569 = charIDToTypeID( "Ofst" );
var desc726 = new ActionDescriptor();
var id3570 = charIDToTypeID( "Hrzn" );
var id3571 = charIDToTypeID( "#Pxl" );
desc726.putUnitDouble( id3570, id3571, dx );
var id3572 = charIDToTypeID( "Vrtc" );
var id3573 = charIDToTypeID( "#Pxl" );
desc726.putUnitDouble( id3572, id3573, dy );
var id3574 = charIDToTypeID( "Ofst" );
desc725.putObject( id3569, id3574, desc726 );
var id3575 = charIDToTypeID( "Wdth" );
var id3576 = charIDToTypeID( "#Prc" );
desc725.putUnitDouble( id3575, id3576, scaleX );
var id3577 = charIDToTypeID( "Hght" );
var id3578 = charIDToTypeID( "#Prc" );
desc725.putUnitDouble( id3577, id3578, scaleY );
var id3579 = charIDToTypeID( "Angl" );
var id3580 = charIDToTypeID( "#Ang" );
desc725.putUnitDouble( id3579, id3580, rot );
var id3581 = charIDToTypeID( "Lnkd" );
desc725.putBoolean( id3581, true );
executeAction( id3561, desc725, DialogModes.NO );
}
I hope this helps.
Upvotes: 0