• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to create a text layer

Community Beginner ,
Sep 23, 2019 Sep 23, 2019

Copy link to clipboard

Copied

Hi, help me write a script to create a text layer, where text = name of the active layer

TOPICS
Actions and scripting

Views

5.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Sep 23, 2019 Sep 23, 2019

Copy link to clipboard

Copied

#target photoshop-130.064

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var originalUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

// getting the name;

var docName = myDocument.name;

var theLayerName = myDocument.activeLayer.name;

// make the layer;

var myLayerRef = myDocument.artLayers.add();

myLayerRef.kind = LayerKind.TEXT;

myLayerRef.name = theLayerName;

var myTextRef = myLayerRef.textItem;

myTextRef.size = 14;

myTextRef.font = "Courier";

myTextRef.justification = Justification.RIGHT;

//Set text colour in RGB values

var newColor = new SolidColor();

newColor.rgb.red = 0;

newColor.rgb.green = 0;

newColor.rgb.blue = 0;

myTextRef.color = newColor;

// Set the position of the text - percentages from left first, then from top.

myTextRef.position = new Array( myDocument.width - 85, myDocument.height - 85);

myLayerRef.blendMode = BlendMode.NORMAL;

myLayerRef.opacity = 100;

myTextRef.contents = theLayerName;

app.preferences.rulerUnits = originalUnits;

};

//that’s it; thanks to xbytors;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2019 Sep 23, 2019

Copy link to clipboard

Copied

My hack:

 

 

#target photoshop
// Current layer name as text layer
var myDoc = app.activeDocument;
var myRulers = app.preferences.rulerUnits
app.preferences.rulerUnits = Units.PIXELS;
var myLayerName = myDoc.activeLayer.name;
var myLayerText = myDoc.artLayers.add()
myLayerText.kind = LayerKind.TEXT
var myText = myLayerText.textItem
myColor = new SolidColor
myColor.rgb.red = 255
myColor.rgb.green = 0
myColor.rgb.blue = 0
myLayerText.textItem.color = myColor
myText.position = [0,20] // Upper Left
myText.justification = Justification.LEFT
myText.size = 12
myText.contents = myLayerName
myLayerText.name = myLayerName // Or add a fixed string in quotes i.e. 'My Great Layer Name!'
app.preferences.rulerUnits = myRulers

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 24, 2019 Sep 24, 2019

Copy link to clipboard

Copied

LATEST
TextLayer(app.activeDocument.activeLayer.name);
function TextLayer(text) {
        var layers = app.activeDocument.artLayers;
        var layer = layers.add();
        layer.kind = LayerKind.TEXT;
        var textItem = layer.textItem;
        textItem.kind = TextType.PARAGRAPHTEXT;
        textItem.size = 30;
        textItem.position = [10, 10];
        textItem.contents = text;
        textItem.width = new UnitValue("300 pixels");
        textItem.height = new UnitValue("30 pixels");
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines