Highlighted

Photoshop script change textitem size (javascript)

New Here ,
Oct 02, 2020

Copy link to clipboard

Copied

When i reduce size, the text size will bigger.

app.preferences.rulerUnits = Units.PIXELS;  
app.preferences.typeUnits = TypeUnits.PIXELS;  

var doc = app.activeDocument;

var textLayer = doc.layers.getByName('obj-name');
var tI = textLayer.textItem;
var old_size = tI.size;
var size_value = old_size.value;
size_value -= 1;
tI.size = new UnitValue(size_value , 'px');

$.writeln(tI.size + " " + old_size + " " + size_value);

the result is:

134.722198486328 px 33.3333282470703 px 32.3333282470703

 

蒙福5E82_1-1601641793335.png

 

蒙福5E82_0-1601641781975.png

 

My ps version is 2020.

 

 

 

 

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional
Most likely some old bug.
Doesn't work in CS6 either.

Try to set the size property always in points.
 
That is, instead of
tI.size = new UnitValue(size_value, 'px');
use
tI.size = new UnitValue(size_value * 72/doc.resolution, 'pt');
 
TOPICS
Bug, Problem or error

Views

60

Likes

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

Photoshop script change textitem size (javascript)

New Here ,
Oct 02, 2020

Copy link to clipboard

Copied

When i reduce size, the text size will bigger.

app.preferences.rulerUnits = Units.PIXELS;  
app.preferences.typeUnits = TypeUnits.PIXELS;  

var doc = app.activeDocument;

var textLayer = doc.layers.getByName('obj-name');
var tI = textLayer.textItem;
var old_size = tI.size;
var size_value = old_size.value;
size_value -= 1;
tI.size = new UnitValue(size_value , 'px');

$.writeln(tI.size + " " + old_size + " " + size_value);

the result is:

134.722198486328 px 33.3333282470703 px 32.3333282470703

 

蒙福5E82_1-1601641793335.png

 

蒙福5E82_0-1601641781975.png

 

My ps version is 2020.

 

 

 

 

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional
Most likely some old bug.
Doesn't work in CS6 either.

Try to set the size property always in points.
 
That is, instead of
tI.size = new UnitValue(size_value, 'px');
use
tI.size = new UnitValue(size_value * 72/doc.resolution, 'pt');
 
TOPICS
Bug, Problem or error

Views

61

Likes

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
Oct 02, 2020 0
Adobe Community Professional ,
Oct 02, 2020

Copy link to clipboard

Copied

Most likely some old bug.
Doesn't work in CS6 either.

Try to set the size property always in points.
 
That is, instead of
tI.size = new UnitValue(size_value, 'px');
use
tI.size = new UnitValue(size_value * 72/doc.resolution, 'pt');
 

Likes

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
Reply
Loading...
Oct 02, 2020 0
New Here ,
Oct 03, 2020

Copy link to clipboard

Copied

Thank you. work grek! And the bug can be fix ?

Likes

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
Reply
Loading...
Oct 03, 2020 0