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

Script to create a text layer

Community Beginner ,
Sep 23, 2019 Sep 23, 2019

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

TOPICS
Actions and scripting
5.5K
Translate
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

#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;

Translate
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

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

 

Translate
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
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");
}
Translate
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