Skip to main content
Geppetto Luis
Legend
May 13, 2020
Question

Select the font manually

  • May 13, 2020
  • 2 replies
  • 3119 views

I would like to select the font manually and not preset it in the script

 

 


//#target photoshop
main();
function main(){
if(!documents.length) return;
var w = new Window ("dialog","TEXT TEST");

w.orientation = 'row';
w.alignment='top';
w.pnl = w.add('panel', undefined, undefined, {borderStyle:'white'});


w.g15 = w.pnl.add('group');
w.g15.alignment='center';
w.g15.st1 = w.g15.add('statictext',undefined,''); 
w.g15.et1 = w.g15.add('edittext');
w.g15.et1.text = 'TEST'; 

w.g15.et1.preferredSize=[300,20];


w.g20 = w.pnl.add('group');
w.g20.alignment='center';
w.g20.bu1 = w.g20.add('button',undefined,'OK');
w.g20.bu1.preferredSize=[147,25];
w.g20.bu2 = w.g20.add('button',undefined,'Close', { name: "cancel" });
w.g20.bu2.preferredSize=[147,25];


w.g20.bu1.onClick=function(){
    
var txtLayer = activeDocument.artLayers.add();
txtLayer.kind = LayerKind.TEXT;

txtLayer.textItem.size = 30; 
txtLayer.textItem.font = "ArialNarrow";   /// CHANGE FONT MANUAL

var TXTColor = new SolidColor;
TXTColor.rgb.hexValue = '00ffc8';
txtLayer.textItem.color = TXTColor;

var X = ((activeDocument.width/100)*1);   
var Y = ((activeDocument.height/100)*6); 

txtLayer.textItem.position = new Array( X, Y);

txtLayer.textItem.contents = "TEST"; 

var LB=activeDocument.activeLayer.bounds;
var Height = LB[3].value - LB[1].value;
var Width = LB[2].value - LB[0].value;
activeDocument.selection.select([[LB[0],LB[1]], [LB[2],LB[1]], [LB[2],LB[3]], [LB[0], LB[3]]], SelectionType.REPLACE, 0, false);

activeDocument.selection.deselect();
activeDocument.flatten();

preferences.rulerUnits = originalRulerUnits;

w.close();

}
w.show();
}

This topic has been closed for replies.

2 replies

Geppetto Luis
Legend
May 14, 2020

nobody can help me in this request.

c.pfaffenbichler
Community Expert
Community Expert
May 14, 2020

What is the problem? 

You can get a list if the available fonts via app.fonts and populate the dropdownList with the names or postScriptNames. 

Legend
May 14, 2020

Maybe I explained myself wrong
I know what you have entered

my problem is that I don't want to preset the font
but I want to select it from the drop down menu
as in the video.

 


Maybe you just want to activate (select) the Type Tool after creating a text layer so that font options appear in the options panel?
Tom Winkelmann
Inspiring
May 13, 2020
Geppetto Luis
Legend
May 13, 2020

Tom_Winkelmann

I need it because I'm creating an html panel
and I need to select the text as described above.