Write a texte layer with a prompt

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

pixeltuti

Write a texte layer with a prompt

Post by pixeltuti »

Good evening

I need help!

I wish create a text layer with a selected font, size selected, write the text with a dialog Box ( prompt )!

Thank you in advance
Christian

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Paul MR

Write a texte layer with a prompt

Post by Paul MR »

Here is a basic script to add a layer...

Code: Select all#target photoshop
main();
function main(){
if(!documents.length) return;
var w = new Window ("dialog");
w.orientation = 'row';
w.alignment='top';
w.pnl = w.add('panel', undefined, undefined, {borderStyle:'black'});
w.g5 = w.pnl.add('group');
w.g5.alignment='left';
w.g5.st1 = w.g5.add('statictext',undefined,'Select font');
w.g5.dd1 = w.g5.add('dropdownlist');
for(var f =0;f< app.fonts.length;f++){w.g5.dd1.add('item',app.fonts[f].name.toString());}
w.g5.dd1.selection=0;
w.g10 = w.pnl.add('group');
w.g10.alignment='left';
w.g10.st1 = w.g10.add('statictext',undefined,'Font Size');
w.g10.et1 = w.g10.add('edittext',undefined,'14');
w.g10.et1.preferredSize=[50,20];
w.g10.et1.onChanging = function() {
  if (this.text.match(/[^\-\.\d]/)) {
    this.text = this.text.replace(/[^\-\.\d]/g, '');
  }
};
w.g15 = w.pnl.add('group');
w.g15.alignment='left';
w.g15.st1 = w.g15.add('statictext',undefined,'Text');
w.g15.et1 = w.g15.add('edittext');
w.g15.et1.preferredSize=[300,20];
w.g20 = w.pnl.add('group');
w.g20.bu1 = w.g20.add('button',undefined,'Create Text');
w.g20.bu1.preferredSize=[150,30];
w.g20.bu2 = w.g20.add('button',undefined,'Cancel');
w.g20.bu2.preferredSize=[150,30];
w.g20.bu1.onClick=function(){
if(w.g15.et1.text == ''){
    alert('No text has been entered!');
    return;
    }
w.close(0);
var startRulerUnits = preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var textColour = new SolidColor();
textColour.rgb.hexValue  = '000000';       
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT
newTextLayer.textItem.color = textColour;
newTextLayer.textItem.font = app.fonts[w.g5.dd1.selection.index].postScriptName;
newTextLayer.textItem.size = Number(w.g10.et1.text);
newTextLayer.textItem.contents = w.g15.et1.text;
var LB = newTextLayer.bounds;
activeDocument.activeLayer.translate((5-LB[0].value),(5-LB[1].value));
preferences.rulerUnits = startRulerUnits;
}
w.show();
}
pixeltuti

Write a texte layer with a prompt

Post by pixeltuti »

Tank You MR
!
It is possible, y have a prompt only with the Text. And the choice of font and the size inside the script !

And the Texte layer in a position i have determined in the script ( middle , right )

Thank you in advance

christian
Paul MR

Write a texte layer with a prompt

Post by Paul MR »

Please try this..

Code: Select all#target photoshop
main();
function main(){
if(!documents.length) return;
var w = new Window ("dialog");
w.orientation = 'row';
w.alignment='top';
w.pnl = w.add('panel', undefined, undefined, {borderStyle:'black'});
w.g15 = w.pnl.add('group');
w.g15.alignment='left';
w.g15.st1 = w.g15.add('statictext',undefined,'Text');
w.g15.et1 = w.g15.add('edittext');
w.g15.et1.preferredSize=[300,20];
w.g20 = w.pnl.add('group');
w.g20.bu1 = w.g20.add('button',undefined,'Create Text');
w.g20.bu1.preferredSize=[140,25];
w.g20.bu2 = w.g20.add('button',undefined,'Cancel');
w.g20.bu2.preferredSize=[140,25];
w.g20.bu1.onClick=function(){
if(w.g15.et1.text == ''){
    alert('No text has been entered!');
    return;
    }
w.close(0);
var startRulerUnits = preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var textColour = new SolidColor();
textColour.rgb.hexValue  = '000000';       
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT
newTextLayer.textItem.color = textColour;
newTextLayer.textItem.font = "Georgia";
newTextLayer.textItem.size = 14;
newTextLayer.textItem.contents = w.g15.et1.text;
var LB = newTextLayer.bounds;
var X = (activeDocument.width - 5) - LB[2].value;
var Y = (activeDocument.height/2) - (LB[1].value +((LB[3].value - LB[1].value)/2));
activeDocument.activeLayer.translate(X,Y);
preferences.rulerUnits = startRulerUnits;
}
w.show();
}

pixeltuti

Write a texte layer with a prompt

Post by pixeltuti »

Thank you so much MR Paul for your help !

Your script work perfectly !!