Files
DP/PSMARK代码块/自由变换函数.jsx

50 lines
2.5 KiB
JavaScript

function 自由变换(水平位置, 垂直位置, 水平偏移, 垂直偏移, 宽度百分比, 高度百分比, 保持宽高比, 插值方法,角度) {
try {
var 描述符 = new ActionDescriptor();
var 引用 = new ActionReference();
// 引用当前选中的图层
引用.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
描述符.putReference(stringIDToTypeID("null"), 引用);
// 设置自由变换的中心状态为独立
描述符.putEnumerated(stringIDToTypeID("freeTransformCenterState"), stringIDToTypeID("quadCenterState"), stringIDToTypeID("QCSIndependent"));
// 设置位置
var 位置描述符 = new ActionDescriptor();
位置描述符.putUnitDouble(stringIDToTypeID("horizontal"), stringIDToTypeID("pixelsUnit"), 水平位置);
位置描述符.putUnitDouble(stringIDToTypeID("vertical"), stringIDToTypeID("pixelsUnit"), 垂直位置);
描述符.putObject(stringIDToTypeID("position"), stringIDToTypeID("point"), 位置描述符);
// 设置偏移
var 偏移描述符 = new ActionDescriptor();
偏移描述符.putUnitDouble(stringIDToTypeID("horizontal"), stringIDToTypeID("pixelsUnit"), 水平偏移);
偏移描述符.putUnitDouble(stringIDToTypeID("vertical"), stringIDToTypeID("pixelsUnit"), 垂直偏移);
描述符.putObject(stringIDToTypeID("offset"), stringIDToTypeID("offset"), 偏移描述符);
// 设置宽度和高度
描述符.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("percentUnit"), 宽度百分比);
描述符.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("percentUnit"), 高度百分比);
// 设置是否保持宽高比
描述符.putBoolean(stringIDToTypeID("linked"), 保持宽高比);
// 设置插值方法
描述符.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID(插值方法));
描述符.putUnitDouble(stringIDToTypeID("angle"), stringIDToTypeID("angleUnit"), 角度);
// 执行变换
executeAction(stringIDToTypeID("transform"), 描述符, DialogModes.NO);
} catch (e) {
if (e.number != 8007) {
alert("行号: " + e.line + e, "错误", true);
throw(e);
}
}
// 调用示例
自由变换(水平位置, 垂直位置, 水平偏移, 垂直偏移, 宽度百分比, 高度百分比, true, 插值方法,角度);