[ExtendScript] Adobe ExtendScript 常用語法

Photoshop

基本

// 文字輸出
$.writeln("--- Processing...");

檔案操作 (Document)

// 取得目前顯示的文件
var doc = activeDocument;

// 切換目前顯示的文件
activeDocument = anotherDoc;

// 開啟檔案
var newDoc = open(File("C:/temp/aaa.jpg"), OpenDocumentType.JPEG , false);

// 開啟檔案 (為智慧型物件)
var newDoc = open(File("C:/temp/aaa.jpg"), OpenDocumentType.JPEG , true);

圖層操作 (ArtLayer)

// 取得目前選取的圖層
var layer = doc.activeLayer;

// 移動 (從目前位置移動)
layer.translate(disX, disY);

// 縮放
layer.resize(width, height);

// 複製圖層到指定文件中
var newLayer = doc.activeLayer.duplicate( anotherDoc );

// 取得圖層內容位置與大小
var boundRect = doc.activeLayer.bounds;
$.writeln("X: "+boundRect[0]);
$.writeln("Y: "+boundRect[1]);
$.writeln("Width: "+boundRect[2]);
$.writeln("Height: "+boundRect[3]);

留言