How to rasterize a text layer

UXPでテキストレイヤーをラスタライズ化したいのですが、以下のコードを実行してもRasterizeTypeの定義エラーで実行できません。
こちらはどのように修正すればよろしいでしょうか?

I want to rasterize the text layer with UXP, but even if I run the sample code below, it cannot be executed due to a RasterizeType definition error.
How would you like to fix this?

   const app = require("photoshop").app;
   const doc = app.activeDocument;
   var layers = doc.layers;
   async function LayersRasterize(){
     try{
       for(layer of layers){
         layer.rasterize(RasterizeType.ENTIRELAYER);
       }
     }catch(e){
       console.error(e);
     }
   }
   await require('photoshop').core.executeAsModal(LayersRasterize);

エラー文言は下記になります。
The error message is below.

index.js:13 ReferenceError: RasterizeType is not defined
    at LayersRasterize (index.js:10)
    at _internalExecuteAsModalWrapper (uxp://uxp-internal/ps-common.js:61)
    at _internalCallbackWrapper (uxp://uxp-internal/ps-common.js:42)

下記のドキュメントを参考に実装していきました。
I used the following document as a reference.
https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes/layer/#rasterize

I self-solved.
There was no problem with executing the rasterize function without arguments.
thank you very much.

自己解決しました。
rasterize関数の引数無しで実行で問題ありませんでした。
ありがとうございました。

layer.rasterize();

RasterizeType is not present in the global scope. First, you need to import it from constants. Then use it.

1 Like

thank you for your reply.
I understand that I need to import Constants.
I will investigate how to use it.

お返事ありがとうございます。
Constantsのインポートが必要とのこと承知しました。
使い方を調査してみます。

After importing constants, I was able to get the RasterizeType constants.
thank you very much.
constantsをimportしたところ、RasterizeTypeの定数を得ることができました。
ありがとうございました。

const constants = require("photoshop").constants;
await layer.rasterize(constants.RasterizeType.ENTIRELAYER);