Text Direction values from Batchplay PS api

Text Direction

Objectives

  • To export PSD layers and information into our platform using UXP plugin.
  • For this, we process each layer type like (Text, Image, Shape).
  • And map most of the properties from the layer data
  • For Text Layers we need to map the directionType (RTL or LTR) and paragraph alignment.

Approaches

  • Getting all layers from document and using batchPlay commands to get detailed layer information from PS api get these data from layers
  • Attached below BatchPlay commands setup code snippets that we used for gathering detailed layer information.
  • By passing the Text Layers id and getting the data from this batchPlay command.
  ActionDescriptor,
  BatchPlayCommandOptions,
} from "photoshop/dom/CoreModules";

export const executeBatchPlayActions = async (
  commands: ActionDescriptor[],
  options?: BatchPlayCommandOptions | undefined
): Promise<ActionDescriptor[]> => {
  return action.batchPlay(commands, options);
};


const getLayerActionCommand = (layerId: number) => {
  return {
    action: {
      _obj: "get",
      _target: [{ _ref: "layer", _id: layerId }],
      _isCommand: false,
      _options: { dialogOptions: "dontDisplay" },
    },
    options: {
      synchronousExecution: true,
    },
  };
};
export const getLayerDetailedProps = async (
  layerId: number
): Promise<ActionDescriptor[]> => {
  const layerActionCommand = getLayerActionCommand(layerId);
  const result = await executeBatchPlayActions(
    [
      {
        ...layerActionCommand.action,
      },
    ],
    {
      ...layerActionCommand.options,
    }
  );

  return result;
};

The value which we select for textDirection and paragraphAlignment from the above command response

const layerProps = await getLayerDetailedProps(layer.id);
  let justification = layer?.textItem?.paragraphStyle?.justification;
  // So Assuming Default Text direction as LTR.

  const textDirection =
    layerProps?.[0]?.textKey?.paragraphStyleRange?.[0]?.paragraphStyle
      ?.directionType?._value || TextDirections.LTR;
  const paragraphAlignment =
    layerProps?.[0]?.textKey?.paragraphStyleRange?.[0]?.paragraphStyle?.align
      ?._value;

Problems

  • Some Client PSD’s files with Text Layers which had defaultDirection dirLeftToRight or dirRightToLeft assigned from MIddle East Features section its value is coming as undefined.
  • But when we try to toggling between the directions from the same feature section and save the file again.
  • After this if we use the same commands from batchPlay, getting the actual values like expected but initially the data is undefined.
  • In the same PSD file if we try to add a new Text Layer from our PS app and get try to get the informations the default value for the directionType property will be present
  • The already present Text Layers in the particular PSD files are having the problem. Other normal PSDs are also working fine.

Any insights or suggestions would be greatly appreciated!