As described in the title.
I use react with uxp 5.5.6 and api 2.
I need to change all the content of a text layer to the same font in unison, but it doesn’t work.
I execute the command by traversing the layer and determining when the layer is a text layer.
const setStyleCommand = { _obj: "set", _target: { _ref: [{ _ref: "textLayer", _id: genLayer._id }], }, to: { _obj: "textLayer", // layerInfo is the information I have obtained about the current layer textStyleRange: layerInfo[0].textKey.textStyleRange.map((item) => { return { ...item, _obj: "textStyleRange", from: 0, to: textKey.length, textStyle: { ...item.textStyle, _obj: "textStyle", fontPostScriptName: "ArialMT", fontName: "Arial", fontStyleName: "Regular", }, }; }), }, _isCommand: true, };
The magic is that if I change this font to another font, the replacement takes effect. If I use the font ArialMT, it will not take effect.
I don’t understand what I’ve done wrong, please help me.
I use the following command
const setContentCommand = {
_obj: "set",
_target: {
_ref: [{ _ref: "textLayer", _id: layer._id }],
},
to: {
_obj: "textLayer",
textKey: textKey,
textStyleRange: layerInfo[0].textKey.textStyleRange.map(
(item) => {
return {
...item,
_obj: "textStyleRange",
from: 0,
to: textKey.length,
textStyle: {
...item?.textStyle,
_obj: "textStyle",
fontPostScriptName: "ArialMT",
fontName: "Arial",
fontStyleName: "Regular",
fontAvailable: true,
},
};
}
),
},
_isCommand: true,
};
await core.executeAsModal(async (executionControl) => {
// await action.batchPlay([command], {});
return await action.batchPlay([setContentCommand], {});
});