Files
tools/Mac工具/Yeomai-Toolbox-CEP/jsx/scripts/99.其他工具/零点参考线.jsx
T

52 lines
1.3 KiB
React

#target photoshop
/*
Create missing guides at the document origin.
Existing guides at X=0 or Y=0 are not duplicated.
*/
(function () {
if (app.documents.length === 0) {
alert("请先打开一个文档。");
return;
}
try {
var document = app.activeDocument;
var hasVerticalAtZero = false;
var hasHorizontalAtZero = false;
var tolerance = 0.001;
var i;
for (i = 0; i < document.guides.length; i++) {
var guide = document.guides[i];
var position = guide.coordinate.as("px");
if (Math.abs(position) <= tolerance) {
if (guide.direction === Direction.VERTICAL) {
hasVerticalAtZero = true;
} else if (guide.direction === Direction.HORIZONTAL) {
hasHorizontalAtZero = true;
}
}
}
if (!hasVerticalAtZero) {
document.guides.add(
Direction.VERTICAL,
new UnitValue(0, "px")
);
}
if (!hasHorizontalAtZero) {
document.guides.add(
Direction.HORIZONTAL,
new UnitValue(0, "px")
);
}
} catch (error) {
alert("创建参考线失败:\n" + error.message);
}
}());