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

How to change font in all paragraph style and character style in photoshop using javascript

New Here ,
Jul 08, 2020 Jul 08, 2020

Copy link to clipboard

Copied

I want to change some properties like font, size, leading ect. in all paragraph styles and character styles in photoshop using javascript

TOPICS
Actions and scripting , SDK

Views

1.3K

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
New Here ,
Jul 08, 2020 Jul 08, 2020

Copy link to clipboard

Copied

just try

FOR EACH STATEMENT to find the text items in document , then change the
properties using assignment values...

I don't know java script but do that in vb.net

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
New Here ,
Jul 09, 2020 Jul 09, 2020

Copy link to clipboard

Copied

I want to change font, size, leading ect. in paragraph style and Character Style in photoshop.

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
LEGEND ,
Jul 09, 2020 Jul 09, 2020

Copy link to clipboard

Copied

This script will let you selectively format text.

#target photoshop

layerUpdate();

function setFormatting(start, end, fontName, fontStyle, fontSize){
var idsetd = app.charIDToTypeID('setd');
var action = new ActionDescriptor();
var idnull = app.charIDToTypeID('null');
var reference = new ActionReference();
var idTxLr = app.charIDToTypeID('TxLr');
var idOrdn = app.charIDToTypeID('Ordn');
var idTrgt = app.charIDToTypeID('Trgt');
reference.putEnumerated(idTxLr, idOrdn, idTrgt);
action.putReference(idnull, reference);
var idT = app.charIDToTypeID('T ');
var textAction = new ActionDescriptor();
var idTxtt = app.charIDToTypeID('Txtt');
var actionList = new ActionList();
var textRange = new ActionDescriptor();
var idFrom = app.charIDToTypeID('From');
textRange.putInteger(idFrom, start);
textRange.putInteger(idT, end);
var idTxtS = app.charIDToTypeID('TxtS');
var formatting = new ActionDescriptor();
var idFntN = app.charIDToTypeID('FntN');
formatting.putString(idFntN, fontName);
var idFntS = app.charIDToTypeID('FntS');
formatting.putString(idFntS, fontStyle);
var idSz = app.charIDToTypeID('Sz ');
var idPnt = app.charIDToTypeID('#Pnt');
formatting.putUnitDouble(idSz, idPnt, fontSize);
textRange.putObject(idTxtS, idTxtS, formatting);
actionList.putObject(idTxtt, textRange);
textAction.putList(idTxtt, actionList);
action.putObject(idT, idTxLr, textAction);
app.executeAction(idsetd, action, DialogModes.NO);
}

function layerUpdate(){
if(documents.length > 0){
var originalDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.ERROR;
var originalRulerUnits = preferences.rulerUnits;
var j = 0;
try{
var docRef = activeDocument;
preferences.rulerUnits = Units.POINTS;
var m = 0;
for(var i = 0; i < docRef.artLayers.length; i++){
var LayerRef = docRef.artLayers[i];
if(LayerRef.kind == LayerKind.TEXT){
var TextRef = LayerRef.textItem;
TextRef.textComposer = TextComposer.ADOBESINGLELINE;
var layerText = TextRef.contents;
if(newText != layerText){
j = i;
TextRef.contents = newText;
//formatting block
if(TextRef.size == 96){
TextRef.size = 42;
TextRef.font = 'Calibri';
TextRef.useAutoLeading = false;
TextRef.leading = 42;
var l = TextRef.contents.split(/\r/);
docRef.activeLayer = LayerRef;
setFormatting(0, l[0].length, 'Calibri', 'Bold', 96);
break;
}
}
}
}
}
catch(e){
alert(e + ' ' + e.line);
preferences.rulerUnits = originalRulerUnits;
app.displayDialogs = originalDialogMode;
return;
}
preferences.rulerUnits = originalRulerUnits;
app.displayDialogs = originalDialogMode;
}
else{
alert('You must have a document open to run this script.');
return;
}
}

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
New Here ,
Jul 09, 2020 Jul 09, 2020

Copy link to clipboard

Copied

LATEST

I have the code to update the existing characterStyle:
But Two things are need to be included:
1. Style name should be dynamic, instead of hard coding the style name, Because I need to apply it for all the character style in new master psd, since we don't now the Style name.

2. It replacing the properties what we given like Font and FontStyle and Size. But it removes all the other properties like leading.
Can you help me on this

var params = {

styleSheetName: "01 Headline SFP-D-SB 80/88/0 1d1d1f LRG" ,

fontPostScriptName: "MyriadPro-BoldIt" ,

fontName: "Myriad Pro" ,

fontStyle: "Bold" ,

size: 12.000000 ,

};

 

 

var desc1 = new ActionDescriptor();

var ref1 = new ActionReference();

ref1.putProperty( charIDToTypeID( "Prpr" ), charIDToTypeID( "TxtS" ) );

ref1.putEnumerated( charIDToTypeID( "TxLr" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

desc1.putReference( charIDToTypeID( "null" ), ref1 );

var desc2 = new ActionDescriptor();

    

desc2.putString( stringIDToTypeID( "styleSheetName" ), params.styleSheetName);

desc2.putString( stringIDToTypeID( "fontPostScriptName" ), params.fontPostScriptName);

desc2.putString( charIDToTypeID( "FntN" ), params.fontName);

desc2.putString( charIDToTypeID( "FntS" ), params.fontStyle);

desc2.putUnitDouble( charIDToTypeID( "Sz  " ), charIDToTypeID( "#Pnt" ), params.size);

desc1.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "TxtS" ), desc2 );

executeAction( charIDToTypeID( "setd" ), desc1, DialogModes.NO );

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