Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

Need help cleaning up a script and adding loop

$
0
0

I have the following script that I pieced together that basically takes the selected layer, gets its name, makes a text object with that name and then places it in a specific place using the original layer as the reference.

 

I need to be able to select multiple layers and have it loop through all of them one by one.

 

Here's the script, I'm hopeing someone can help me out! I'm new at this, but learning quickly!

 

function run(){   var docRef = app.activeDocument;
var layerRef = docRef.activeLayer;
var docWidth = docRef.width;
var layer = activeDocument.activeLayer; //Grab the currently selected layer
var myLayer = activeDocument.activeLayer.name;
var layerWidth = layer.bounds[2].value - layer.bounds[0].value;
var relUpperCenterX = layerWidth / 2;
//Calculate length and width based on the rectangular bounds of the selected layer
var idsetd = charIDToTypeID( "setd" );    var desc2045 = new ActionDescriptor();    var idnull = charIDToTypeID( "null" );        var ref1289 = new ActionReference();        var idChnl = charIDToTypeID( "Chnl" );        var idfsel = charIDToTypeID( "fsel" );        ref1289.putProperty( idChnl, idfsel );    desc2045.putReference( idnull, ref1289 );    var idT = charIDToTypeID( "T   " );        var ref1290 = new ActionReference();        var idChnl = charIDToTypeID( "Chnl" );        var idChnl = charIDToTypeID( "Chnl" );        var idTrsp = charIDToTypeID( "Trsp" );        ref1290.putEnumerated( idChnl, idChnl, idTrsp );    desc2045.putReference( idT, ref1290 );
executeAction( idsetd, desc2045, DialogModes.NO );


// =======================================================
var idDplc = charIDToTypeID( "Dplc" );
    var desc2046 = new ActionDescriptor();    var idnull = charIDToTypeID( "null" );        var ref1291 = new ActionReference();        var idChnl = charIDToTypeID( "Chnl" );        var idfsel = charIDToTypeID( "fsel" );        ref1291.putProperty( idChnl, idfsel );    desc2046.putReference( idnull, ref1291 );    var idNm = charIDToTypeID( "Nm  " );    desc2046.putString( idNm, """working""" );
executeAction( idDplc, desc2046, DialogModes.NO );


// =======================================================
var idsetdd = charIDToTypeID( "setd" );
    var desc2047 = new ActionDescriptor();    var idnull = charIDToTypeID( "null" );        var ref1292 = new ActionReference();        var idChnl = charIDToTypeID( "Chnl" );        var idfsel = charIDToTypeID( "fsel" );        ref1292.putProperty( idChnl, idfsel );    desc2047.putReference( idnull, ref1292 );    var idT = charIDToTypeID( "T   " );    var idOrdn = charIDToTypeID( "Ordn" );    var idNone = charIDToTypeID( "None" );    desc2047.putEnumerated( idT, idOrdn, idNone );
executeAction( idsetdd, desc2047, DialogModes.NO );    //Create a text layer    var textLayer = activeDocument.artLayers.add(); //Make a new layer on the canvas    textLayer.kind = LayerKind.TEXT; //Make that layer a text layer    textLayer.name = layer.name; //Name the layer "Dimensions"
var red = new SolidColor();    red.rgb.red = 255;
red.rgb.green = 0;    red.rgb.blue = 0;       var textReference = textLayer.textItem; //Create a textItem which we'll use to fill the text layer    textReference.contents = layer.name //Set the contents of that textItem to the length and width
textReference.color = red;
textReference.size = 40;
textReference.position[0] = Array (Math.floor(0, relUpperCenterX));


var idsetd2 = charIDToTypeID( "setd" );
    var desc2051 = new ActionDescriptor();    var idnull = charIDToTypeID( "null" );        var ref1295 = new ActionReference();        var idChnl = charIDToTypeID( "Chnl" );        var idfsel = charIDToTypeID( "fsel" );        ref1295.putProperty( idChnl, idfsel );    desc2051.putReference( idnull, ref1295 );    var idT = charIDToTypeID( "T   " );        var ref1296 = new ActionReference();        var idChnl = charIDToTypeID( "Chnl" );        ref1296.putName( idChnl, "working" );    desc2051.putReference( idT, ref1296 );
executeAction( idsetd2, desc2051, DialogModes.NO );


// =======================================================
var idAlgn1 = charIDToTypeID( "Algn" );
    var desc2071 = new ActionDescriptor();    var idnull = charIDToTypeID( "null" );        var ref1313 = new ActionReference();        var idLyr = charIDToTypeID( "Lyr " );        var idOrdn = charIDToTypeID( "Ordn" );        var idTrgt = charIDToTypeID( "Trgt" );        ref1313.putEnumerated( idLyr, idOrdn, idTrgt );    desc2071.putReference( idnull, ref1313 );    var idUsng = charIDToTypeID( "Usng" );    var idADSt = charIDToTypeID( "ADSt" );    var idAdCH = charIDToTypeID( "AdCH" );    desc2071.putEnumerated( idUsng, idADSt, idAdCH );
executeAction( idAlgn1, desc2071, DialogModes.NO );


// =======================================================
var idAlgn2 = charIDToTypeID( "Algn" );
    var desc2072 = new ActionDescriptor();    var idnull = charIDToTypeID( "null" );        var ref1314 = new ActionReference();        var idLyr = charIDToTypeID( "Lyr " );        var idOrdn = charIDToTypeID( "Ordn" );        var idTrgt = charIDToTypeID( "Trgt" );        ref1314.putEnumerated( idLyr, idOrdn, idTrgt );    desc2072.putReference( idnull, ref1314 );    var idUsng = charIDToTypeID( "Usng" );    var idADSt = charIDToTypeID( "ADSt" );    var idAdTp = charIDToTypeID( "AdTp" );    desc2072.putEnumerated( idUsng, idADSt, idAdTp );
executeAction( idAlgn2, desc2072, DialogModes.NO );


// =======================================================
var idsetd3 = charIDToTypeID( "setd" );
    var desc2073 = new ActionDescriptor();    var idnull = charIDToTypeID( "null" );        var ref1315 = new ActionReference();        var idChnl = charIDToTypeID( "Chnl" );        var idfsel = charIDToTypeID( "fsel" );        ref1315.putProperty( idChnl, idfsel );    desc2073.putReference( idnull, ref1315 );    var idT = charIDToTypeID( "T   " );    var idOrdn = charIDToTypeID( "Ordn" );    var idNone = charIDToTypeID( "None" );    desc2073.putEnumerated( idT, idOrdn, idNone );
executeAction( idsetd3, desc2073, DialogModes.NO );


// =======================================================
var idmove = charIDToTypeID( "move" );
    var desc2074 = new ActionDescriptor();    var idnull = charIDToTypeID( "null" );        var ref1316 = new ActionReference();        var idLyr = charIDToTypeID( "Lyr " );        var idOrdn = charIDToTypeID( "Ordn" );        var idTrgt = charIDToTypeID( "Trgt" );        ref1316.putEnumerated( idLyr, idOrdn, idTrgt );    desc2074.putReference( idnull, ref1316 );    var idT = charIDToTypeID( "T   " );        var desc2075 = new ActionDescriptor();        var idHrzn = charIDToTypeID( "Hrzn" );        var idRlt = charIDToTypeID( "#Rlt" );        desc2075.putUnitDouble( idHrzn, idRlt, 0.000000 );        var idVrtc = charIDToTypeID( "Vrtc" );        var idRlt = charIDToTypeID( "#Rlt" );        desc2075.putUnitDouble( idVrtc, idRlt, -50.000000 );    var idOfst = charIDToTypeID( "Ofst" );    desc2074.putObject( idT, idOfst, desc2075 );
executeAction( idmove, desc2074, DialogModes.NO );


// =======================================================
var idslct1 = charIDToTypeID( "slct" );
    var desc2077 = new ActionDescriptor();    var idnull = charIDToTypeID( "null" );        var ref1318 = new ActionReference();        var idChnl = charIDToTypeID( "Chnl" );        ref1318.putName( idChnl, "working" );    desc2077.putReference( idnull, ref1318 );
executeAction( idslct1, desc2077, DialogModes.NO );


// =======================================================
var idDlt2 = charIDToTypeID( "Dlt " );
    var desc2078 = new ActionDescriptor();    var idnull = charIDToTypeID( "null" );        var ref1319 = new ActionReference();        var idChnl = charIDToTypeID( "Chnl" );        var idOrdn = charIDToTypeID( "Ordn" );        var idTrgt = charIDToTypeID( "Trgt" );        ref1319.putEnumerated( idChnl, idOrdn, idTrgt );    desc2078.putReference( idnull, ref1319 );
executeAction( idDlt2, desc2078, DialogModes.NO );
}
run();

Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>