I am trying to change font size of a textLayer using batchPlay and action descriptors, based on the size of new text content.
const actionDescriptor = [
{
_obj: "set",
_target: [
{
_ref: "textLayer",
_id: layerId,
},
],
to: {
_obj: "textLayer",
textKey: {
_obj: "textLayer",
textStyleRange: [
{
_obj: "textStyleRange",
from: 0,
to: textLength,
textStyle: {
_obj: "textStyle",
size: {
_unit: "pointsUnit",
_value: unitsFontSize,
},
},
},
],
},
},
_isCommand: true,
},
];
const result = await action.batchPlay(actionDescriptor, {});
But getting an error response in result:
[
{
message: "Could not complete your request because of a program error.",
result: -1715,
_obj: "error"
}
]
I am execuing this inside a executeAsModal scope.
What does this error mean?
sttk3
August 16, 2023, 10:57am
2
Perhaps if textKey is targeted, all structures under textKey need to be specified.
If you want to target textStyleRanges and resize them, the code would be as follows. However, you need to duplicate all the original properties , not just the size, or it will look different.
const photoshop = require('photoshop') ;
const { app, core, action } = photoshop ;
const main = async () => {
try {
await core.executeAsModal(
async (control) => {
const layerId = app.activeDocument.activeLayers[0].id ;
const textLength = 2 ;
const unitsFontSize = 10 ;
const actionDescriptor = [
{
_obj: "set",
_target: [
{
_ref: "textLayer",
_id: layerId
}
],
to: {
_obj: "textLayer",
textStyleRange: [
{
_obj: "textStyleRange",
from: 0,
to: textLength,
textStyle: {
_obj: "textStyle",
size: {
_unit: "pointsUnit",
_value: unitsFontSize
}
}
}
]
}
}
] ;
const result = await action.batchPlay(actionDescriptor, {}) ;
console.log(result) ;
},
{
'commandName': 'Set Font Size'
}
) ;
} catch(e) {
await app.showAlert(e) ;
}
} ;
1 Like
It worked. It seems that in _to
key we already have a textKey reference. So now i am just copying all the old properties for the parts i am editing.
const batchPlayRes = await action.batchPlay(
[
{
_obj: "set",
_target: [
{
_ref: "textLayer",
_id: layerData.layer.id,
},
],
to: {
...layerPSdata.textKey,
_obj: "textLayer",
textStyleRange: [
{
...layerPSdata.textKey.textStyleRange[0],
_obj: "textStyleRange",
textStyle: {
...layerPSdata.textKey.textStyleRange[0].textStyle,
_obj: "textStyle",
impliedFontSize: {
_unit: "pointsUnit",
_value: newFontSize,
},
},
},
],
},
_isCommand: true,
_options: {
dialogOptions: "dontDisplay",
},
},
],
{}
);
1 Like
The descriptor for text is perhaps the largest one we have. That’s why it took so long to get it into DOM (as @DavideBarranca can attest).
I’m curious then if there is something missing from DOM that you are using the descriptor instead of TextItem.
textItem.characterStyle.size = 24;
https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes/textitem/
1 Like
sttk3
August 16, 2023, 9:15pm
5
@samgannaway In my case, the main reason is that textItem
did not exist when I developed Split Rows for PS Pro .
This plugin needs to get and set the character attribute for each character to split the text per row and per character. Even now, I don’t know how to achieve that with textItem
.
If I understand correctly, DOM in Photoshop (and Adobe XD) only provides per-text-frame access.
1 Like
gms9797
September 1, 2023, 7:21am
6
impliedFontSize
represents the actual font size we see in the document.
The font size we get from textItem.characterStyle.size
is different from the impliedFontSize
we get from descriptors.
Also we cannot get textStyleRange
from uxp ps_reference
.