Copy link to clipboard
Copied
I am trying to apply stroke to my photoshop text using scripts. But I have failed all the time. Here's what I've come up with:
#target photoshop
var textArray = ["Hello"];
var fontSize = 13;
var fontFamily = "KomikaAxis";
var strokeSize = 10;
for (var i = 0; i < textArray.length; i++) {
var currentText = textArray[i];
var textLayer = app.activeDocument.artLayers.add();
textLayer.kind = LayerKind.TEXT;
textLayer.textItem.contents = currentText;
textLayer.textItem.font = fontFamily;
textLayer.textItem.size = fontSize;
var textColor = new SolidColor();
textColor.rgb.red = 255;
textColor.rgb.green = 255;
textColor.rgb.blue = 255;
textLayer.textItem.color = textColor;
textLayer.textItem.position = [541, 1144];
textLayer.rasterize(RasterizeType.TEXTCONTENTS);
textLayer.layerStyle.stroke.enabled = true;
textLayer.layerStyle.stroke.size = strokeSize;
textLayer.layerStyle.stroke.color = new SolidColor();
textLayer.layerStyle.stroke.color.rgb.hexValue = '000000';
textLayer.layerStyle.stroke.position = StrokeLocation.CENTER;
textLayer.layerStyle.stroke.blendMode = BlendMode.NORMAL;
}
I have run the code and it says undefined is not an object at line: textLayer.layerStyle.stroke.enabled = true; Why is so? The text is made surely, not the stroke. What am I making wrong here?
// 2024, use it at your own risk;
var textArray = ["Hello"];
var fontSize = 30;
var fontFamily = "KomikaAxis";
var strokeSize = 10;
if (app.documents.length > 0) {
for (var i = 0; i < textArray.length; i++) {
var currentText = textArray[i];
var textLayer = app.activeDocument.artLayers.add();
textLayer.kind = LayerKind.TEXT;
textLayer.textItem.contents = currentText;
textLayer.textItem.font = fontFamily;
textLayer.textItem.size = fontSize;
var textColor
...
Copy link to clipboard
Copied
What gave you the idea that »layerStyle.stroke« is a property of an ArtLayer?
Are you at all familiar with Photoshop’s DOM Scripting?
Copy link to clipboard
Copied
Did you use ChatGPT or some other AI-tool to create the code?
Because from past examples on this Forum it seems those occasionally produce mixtures of Illustrator DOM/Photoshop DOM-Script-elements.
And those cannot work in either application.
Copy link to clipboard
Copied
Have you been able to create a functioning Script yet?
Copy link to clipboard
Copied
Unfortunately, it is made by ChatGPT. Can you help me with one script? And yes, I have written a smaller script once since I have a good understanding of JS.
Copy link to clipboard
Copied
// 2024, use it at your own risk;
var textArray = ["Hello"];
var fontSize = 30;
var fontFamily = "KomikaAxis";
var strokeSize = 10;
if (app.documents.length > 0) {
for (var i = 0; i < textArray.length; i++) {
var currentText = textArray[i];
var textLayer = app.activeDocument.artLayers.add();
textLayer.kind = LayerKind.TEXT;
textLayer.textItem.contents = currentText;
textLayer.textItem.font = fontFamily;
textLayer.textItem.size = fontSize;
var textColor = new SolidColor();
textColor.rgb.red = 255;
textColor.rgb.green = 255;
textColor.rgb.blue = 255;
textLayer.textItem.color = textColor;
textLayer.textItem.position = [541, 1144];
applyLayerStyleStroke (strokeSize, 128, 128, 128)
}
};
////// make stroke //////
function applyLayerStyleStroke (theWitdh, theR, theG, theB) {
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc12 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref7 = new ActionReference();
var idPrpr = charIDToTypeID( "Prpr" );
var idLefx = charIDToTypeID( "Lefx" );
ref7.putProperty( idPrpr, idLefx );
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref7.putEnumerated( idLyr, idOrdn, idTrgt );
desc12.putReference( idnull, ref7 );
var idT = charIDToTypeID( "T " );
var desc13 = new ActionDescriptor();
var idScl = charIDToTypeID( "Scl " );
var idPrc = charIDToTypeID( "#Prc" );
desc13.putUnitDouble( idScl, idPrc, 100.000000 );
var idFrFX = charIDToTypeID( "FrFX" );
var desc14 = new ActionDescriptor();
var idenab = charIDToTypeID( "enab" );
desc14.putBoolean( idenab, true );
var idStyl = charIDToTypeID( "Styl" );
var idFStl = charIDToTypeID( "FStl" );
desc14.putEnumerated( idStyl, idFStl, charIDToTypeID( "OutF" ) );
var idPntT = charIDToTypeID( "PntT" );
var idFrFl = charIDToTypeID( "FrFl" );
var idSClr = charIDToTypeID( "SClr" );
desc14.putEnumerated( idPntT, idFrFl, idSClr );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc14.putEnumerated( idMd, idBlnM, idNrml );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc14.putUnitDouble( idOpct, idPrc, 100.000000 );
var idSz = charIDToTypeID( "Sz " );
var idPxl = charIDToTypeID( "#Pxl" );
desc14.putUnitDouble( idSz, idPxl, theWitdh );
var idClr = charIDToTypeID( "Clr " );
var desc15 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc15.putDouble( idRd, theR );
var idGrn = charIDToTypeID( "Grn " );
desc15.putDouble( idGrn, theG );
var idBl = charIDToTypeID( "Bl " );
desc15.putDouble( idBl, theB );
var idRGBC = charIDToTypeID( "RGBC" );
desc14.putObject( idClr, idRGBC, desc15 );
var idFrFX = charIDToTypeID( "FrFX" );
desc13.putObject( idFrFX, idFrFX, desc14 );
var idLefx = charIDToTypeID( "Lefx" );
desc12.putObject( idT, idLefx, desc13 );
executeAction( idsetd, desc12, DialogModes.NO );
};
Copy link to clipboard
Copied
That's such an elegant solution. Is there any reference where I can learn these things from?
Copy link to clipboard
Copied
The »peculiar looking« part in the function is Action Manager (AM) code, one can get it by recording Photoshop oprations with ScriptingListener.plugin.
As for general references:
SCRIPTING GUIDE ADOBE PHOTOSHOPAdobe Communityhttps://community.adobe.com › photoshop › phot...