Skip to main content
Inspiring
June 13, 2020
Answered

Add Stroke to Text Layer

  • June 13, 2020
  • 2 replies
  • 1451 views

I can create text layers and add text to them but do not know how to add a stroke to the layer in javascript. As usual help appreciated

Mike

This topic has been closed for replies.
Correct answer Kukurykus

Add Stroke to Text Layer

2 replies

Kukurykus
KukurykusCorrect answer
Legend
June 13, 2020
c.pfaffenbichler
Community Expert
Community Expert
June 13, 2020

Just record the application of the Layer Style with ScriptingListener.plugin

 

If you are talking about a stroke that can output as vector data you would need to convert the Type Layer to a Shape Layer and apply a Shape Stroke (see the Options Bar). 

Inspiring
June 13, 2020

I have scriptListener installed and what is 2 clicks in Photoshop gives me all this code and I have no idea what I need

// =======================================================
var idmodalStateChanged = stringIDToTypeID( "modalStateChanged" );
    var desc105 = new ActionDescriptor();
    var idLvl = charIDToTypeID( "Lvl " );
    desc105.putInteger( idLvl, 1 );
    var idStte = charIDToTypeID( "Stte" );
    var idStte = charIDToTypeID( "Stte" );
    var identer = stringIDToTypeID( "enter" );
    desc105.putEnumerated( idStte, idStte, identer );
    var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );
    desc105.putBoolean( idkcanDispatchWhileModal, true );
    var idTtl = charIDToTypeID( "Ttl " );
    desc105.putString( idTtl, """Layer Style""" );
executeAction( idmodalStateChanged, desc105, DialogModes.NO );

// =======================================================
var idmodalStateChanged = stringIDToTypeID( "modalStateChanged" );
    var desc106 = new ActionDescriptor();
    var idLvl = charIDToTypeID( "Lvl " );
    desc106.putInteger( idLvl, 0 );
    var idStte = charIDToTypeID( "Stte" );
    var idStte = charIDToTypeID( "Stte" );
    var idexit = stringIDToTypeID( "exit" );
    desc106.putEnumerated( idStte, idStte, idexit );
    var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );
    desc106.putBoolean( idkcanDispatchWhileModal, true );
    var idTtl = charIDToTypeID( "Ttl " );
    desc106.putString( idTtl, """Layer Style""" );
executeAction( idmodalStateChanged, desc106, DialogModes.NO );

// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc107 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref10 = new ActionReference();
        var idPrpr = charIDToTypeID( "Prpr" );
        var idLefx = charIDToTypeID( "Lefx" );
        ref10.putProperty( idPrpr, idLefx );
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref10.putEnumerated( idLyr, idOrdn, idTrgt );
    desc107.putReference( idnull, ref10 );
    var idT = charIDToTypeID( "T   " );
        var desc108 = new ActionDescriptor();
        var idScl = charIDToTypeID( "Scl " );
        var idPrc = charIDToTypeID( "#Prc" );
        desc108.putUnitDouble( idScl, idPrc, 416.666667 );
        var idFrFX = charIDToTypeID( "FrFX" );
            var desc109 = new ActionDescriptor();
            var idenab = charIDToTypeID( "enab" );
            desc109.putBoolean( idenab, true );
            var idpresent = stringIDToTypeID( "present" );
            desc109.putBoolean( idpresent, true );
            var idshowInDialog = stringIDToTypeID( "showInDialog" );
            desc109.putBoolean( idshowInDialog, true );
            var idStyl = charIDToTypeID( "Styl" );
            var idFStl = charIDToTypeID( "FStl" );
            var idOutF = charIDToTypeID( "OutF" );
            desc109.putEnumerated( idStyl, idFStl, idOutF );
            var idPntT = charIDToTypeID( "PntT" );
            var idFrFl = charIDToTypeID( "FrFl" );
            var idSClr = charIDToTypeID( "SClr" );
            desc109.putEnumerated( idPntT, idFrFl, idSClr );
            var idMd = charIDToTypeID( "Md  " );
            var idBlnM = charIDToTypeID( "BlnM" );
            var idNrml = charIDToTypeID( "Nrml" );
            desc109.putEnumerated( idMd, idBlnM, idNrml );
            var idOpct = charIDToTypeID( "Opct" );
            var idPrc = charIDToTypeID( "#Prc" );
            desc109.putUnitDouble( idOpct, idPrc, 100.000000 );
            var idSz = charIDToTypeID( "Sz  " );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc109.putUnitDouble( idSz, idPxl, 7.000000 );
            var idClr = charIDToTypeID( "Clr " );
                var desc110 = new ActionDescriptor();
                var idRd = charIDToTypeID( "Rd  " );
                desc110.putDouble( idRd, 0.000000 );
                var idGrn = charIDToTypeID( "Grn " );
                desc110.putDouble( idGrn, 0.000000 );
                var idBl = charIDToTypeID( "Bl  " );
                desc110.putDouble( idBl, 0.000000 );
            var idRGBC = charIDToTypeID( "RGBC" );
            desc109.putObject( idClr, idRGBC, desc110 );
            var idoverprint = stringIDToTypeID( "overprint" );
            desc109.putBoolean( idoverprint, false );
        var idFrFX = charIDToTypeID( "FrFX" );
        desc108.putObject( idFrFX, idFrFX, desc109 );
    var idLefx = charIDToTypeID( "Lefx" );
    desc107.putObject( idT, idLefx, desc108 );
executeAction( idsetd, desc107, DialogModes.NO );

 from it or how to hack it
 

c.pfaffenbichler
Community Expert
Community Expert
June 13, 2020

Wrap the third part in a function and set up arguments for the elements that might need to take different inputs. 

 

applyAStroke (128, 128, 255);
function applyAStroke (theRed, theGreen, theBlue) {
// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc107 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref10 = new ActionReference();
        var idPrpr = charIDToTypeID( "Prpr" );
        var idLefx = charIDToTypeID( "Lefx" );
        ref10.putProperty( idPrpr, idLefx );
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref10.putEnumerated( idLyr, idOrdn, idTrgt );
    desc107.putReference( idnull, ref10 );
    var idT = charIDToTypeID( "T   " );
        var desc108 = new ActionDescriptor();
        var idScl = charIDToTypeID( "Scl " );
        var idPrc = charIDToTypeID( "#Prc" );
        desc108.putUnitDouble( idScl, idPrc, 416.666667 );
        var idFrFX = charIDToTypeID( "FrFX" );
            var desc109 = new ActionDescriptor();
            var idenab = charIDToTypeID( "enab" );
            desc109.putBoolean( idenab, true );
            var idpresent = stringIDToTypeID( "present" );
            desc109.putBoolean( idpresent, true );
            var idshowInDialog = stringIDToTypeID( "showInDialog" );
            desc109.putBoolean( idshowInDialog, true );
            var idStyl = charIDToTypeID( "Styl" );
            var idFStl = charIDToTypeID( "FStl" );
            var idOutF = charIDToTypeID( "OutF" );
            desc109.putEnumerated( idStyl, idFStl, idOutF );
            var idPntT = charIDToTypeID( "PntT" );
            var idFrFl = charIDToTypeID( "FrFl" );
            var idSClr = charIDToTypeID( "SClr" );
            desc109.putEnumerated( idPntT, idFrFl, idSClr );
            var idMd = charIDToTypeID( "Md  " );
            var idBlnM = charIDToTypeID( "BlnM" );
            var idNrml = charIDToTypeID( "Nrml" );
            desc109.putEnumerated( idMd, idBlnM, idNrml );
            var idOpct = charIDToTypeID( "Opct" );
            var idPrc = charIDToTypeID( "#Prc" );
            desc109.putUnitDouble( idOpct, idPrc, 100.000000 );
            var idSz = charIDToTypeID( "Sz  " );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc109.putUnitDouble( idSz, idPxl, 7.000000 );
            var idClr = charIDToTypeID( "Clr " );
                var desc110 = new ActionDescriptor();
                var idRd = charIDToTypeID( "Rd  " );
                desc110.putDouble( idRd, theRed );
                var idGrn = charIDToTypeID( "Grn " );
                desc110.putDouble( idGrn, theGreen );
                var idBl = charIDToTypeID( "Bl  " );
                desc110.putDouble( idBl, theBlue );
            var idRGBC = charIDToTypeID( "RGBC" );
            desc109.putObject( idClr, idRGBC, desc110 );
            var idoverprint = stringIDToTypeID( "overprint" );
            desc109.putBoolean( idoverprint, false );
        var idFrFX = charIDToTypeID( "FrFX" );
        desc108.putObject( idFrFX, idFrFX, desc109 );
    var idLefx = charIDToTypeID( "Lefx" );
    desc107.putObject( idT, idLefx, desc108 );
executeAction( idsetd, desc107, DialogModes.NO );
};