Read Font size with script

Participant ,
Oct 28, 2019 Oct 28, 2019

Copy link to clipboard

Copied

Hi,

 

I need a little help..

I want to get the Font size as a value wich is set  in Photoshop is that possible?

TOPICS
Actions and scripting

Views

1.2K

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
community guidelines
Adobe Community Professional ,
Oct 28, 2019 Oct 28, 2019

Copy link to clipboard

Copied

One warning about getting font size: if the layer has been transformed, you will get an incorrect reading of the size.

You can try this:

var tLayer = activeDocument.activeLayer;

alert(tLayer.textItem.font.size);

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
community guidelines
LEGEND ,
Oct 28, 2019 Oct 28, 2019

Copy link to clipboard

Copied

Text layers can also have a mixture of text font size and more than a single font. Text is very complex.

Capture.jpg

 
JJMack

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
community guidelines
Participant ,
Oct 28, 2019 Oct 28, 2019

Copy link to clipboard

Copied

Is there any way to get this value from here without a text layer?

textsize.jpg

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
community guidelines
LEGEND ,
Oct 28, 2019 Oct 28, 2019

Copy link to clipboard

Copied

I do not think there would be any way to retrieve field values in all the different tools option bars.  I could be wrong if the text tools is the current selected tool.  For I know script cans get at some current brush tools setting of some brush types.  Photoshop brushes support is very complex , Photoshop Text tool is very complex as well. Action Manager code  would need to be used and the get  refence part of action manager code requires a lot of knowledge about the ways Photoshop works.  I count on r-bin to help me out in that area. 

 

Why do you need that value if there is no text layer you can most likely set the tool up anyway you want?

JJMack

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
community guidelines
Engaged ,
Oct 29, 2019 Oct 29, 2019

Copy link to clipboard

Copied

// select tool
app.currentTool="typeCreateOrEditTool";

try{
var r = new ActionReference();
var d = new ActionDescriptor();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));
r.putEnumerated(charIDToTypeID("capp"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var options = executeActionGet(r);
var object = options.getObjectValue(stringIDToTypeID("currentToolOptions")).getObjectValue(stringIDToTypeID("textToolCharacterOptions")).getObjectValue(stringIDToTypeID("textStyle"));


alert(object.getUnitDoubleValue(stringIDToTypeID("size")));
}
catch(e){alert(e)}

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
community guidelines
Explorer ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

PSA: this also grabs the incorrect size from a transformed layer

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
community guidelines
LEGEND ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

 

sTT = stringIDToTypeID, tK = sTT('textKey');
(ref = new ActionReference()).putProperty(sTT('property'), tK)
ref.putEnumerated(sTT('textLayer'),sTT('ordinal'),sTT('targetEnum'))
executeActionGet(ref).getObjectValue(tK).getObjectValue
(sTT('transform')).getDouble(sTT('yy'))	// * size

 

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
community guidelines
Explorer ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

@Kukurykus sorry i didn't see this until recently.

attached (as txt) is my basic test to use this code.

maybe i'm using it wrong, because I'm getting undefined for the transform value expected.

nickcombs_0-1658253804575.png

 

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
community guidelines
Explorer ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Disregard my last post. It was a silly mistake on my part. I forgot to return the value from GetTransform().

nickcombs_1-1658254340223.png

 

 

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
community guidelines
Explorer ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

LATEST

@Kukurykus I'd like to apply this transform to get the accurate textItem width and height (for paragraph type). Can't really go to the post I made earlier because we broke the page, so I'll put it here.

 

What I'm seeing is an accurate width, but the height always usually differs by 7-13% regardless of whether there is a transform on the text.

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
community guidelines