feat: AI套图分层方案 + Gemini集成 - 4种图案类型处理 + 正片叠底 + 宽高比 + 模型选择
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
306
PSMARK代码块/码标添加2().jsx
Normal file
306
PSMARK代码块/码标添加2().jsx
Normal file
@@ -0,0 +1,306 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 检查是否有打开的文档
|
||||
|
||||
function 码标添加2() {
|
||||
|
||||
app.activeDocument.suspendHistory("码标添加", "码标放置()");
|
||||
}
|
||||
|
||||
|
||||
function 码标放置() {
|
||||
app.activeDocument.layerSets.add().name = "码标";
|
||||
|
||||
app.preferences.rulerUnits = Units.PIXELS;
|
||||
if (app.documents.length > 0) {
|
||||
var doc = app.activeDocument; // 获取当前文档
|
||||
|
||||
// 查找名为"裁片"的组
|
||||
var cropGroup = doc.layerSets.getByName("裁片"); // 将“裁片”替换为您的组名称
|
||||
|
||||
if (cropGroup) {
|
||||
// 遍历裁片组内的所有图层
|
||||
for (var i = 0; i < cropGroup.layers.length; i++) {
|
||||
var layer = cropGroup.layers[i];
|
||||
//alert("图层名称: " + layer.name);
|
||||
当前图层名称=layer.name
|
||||
parts = layer.name.split("_")
|
||||
// alert(parts[2])
|
||||
大货成品图层 = app.activeDocument.layerSets.getByName("裁片").layers.getByName(当前图层名称);
|
||||
app.activeDocument.activeLayer = 大货成品图层;
|
||||
切换mask();
|
||||
|
||||
载入选区蒙版()
|
||||
大货成品图层边距 = 获取当前选区四边距();
|
||||
右边距=大货成品图层边距.right
|
||||
|
||||
var currentDocument = app.activeDocument;
|
||||
var height = currentDocument.height.value;
|
||||
var 上边距新 = 0;
|
||||
var 左边距新 = 右边距 - 1;
|
||||
var 下边距新 = height;
|
||||
var 右边距新 = 右边距 + 1;
|
||||
新建选区(上边距新, 左边距新, 下边距新, 右边距新);
|
||||
选取交叉()
|
||||
获取码标记点 = 获取当前选区四边距();
|
||||
码标记点下标记 = 获取码标记点.bottom
|
||||
码标记点左标记 = 获取码标记点.left
|
||||
码标x中心坐标=码标记点左标记
|
||||
码标y中心坐标=码标记点下标记
|
||||
$.writeln(码标x中心坐标);
|
||||
$.writeln(码标y中心坐标);
|
||||
载入选区蒙版()
|
||||
收缩45像素()
|
||||
收缩45像素成品图层边距 = 获取当前选区四边距();
|
||||
收缩45像素右边距=收缩45像素成品图层边距.right
|
||||
var 收缩45像素上边距新 = 0;
|
||||
var 收缩45像素左边距新 = 0 ;
|
||||
var 收缩45像素下边距新 = height;
|
||||
var 收缩45像素右边距新 = 收缩45像素右边距-1 ;
|
||||
//$.writeln(收缩45像素上边距新);
|
||||
//$ .writeln(收缩45像素左边距新);
|
||||
//$.writeln(收缩45像素下边距新);
|
||||
//$.writeln(收缩45像素右边距新);
|
||||
减去选区(收缩45像素上边距新, 收缩45像素左边距新, 收缩45像素下边距新, 收缩45像素右边距新);
|
||||
//选取交叉()
|
||||
收缩45像素获取码标记点 = 获取当前选区四边距();
|
||||
收缩45像素码标记点y标记 = 收缩45像素获取码标记点.bottom
|
||||
收缩45像素码标记点x标记 = 收缩45像素获取码标记点.left
|
||||
$.writeln(收缩45像素码标记点x标记);
|
||||
$.writeln(收缩45像素码标记点y标记);
|
||||
|
||||
获取中心点1=获取中心点(收缩45像素码标记点x标记, 收缩45像素码标记点y标记, 码标x中心坐标, 码标y中心坐标)
|
||||
$.writeln("中心点坐标: x = " + 获取中心点1.x + ", y = " + 获取中心点1.y);
|
||||
|
||||
|
||||
var 码标高度转毫米y = pixelsToMillimeters(获取中心点1.y);
|
||||
var 码标宽度转毫米x = pixelsToMillimeters(获取中心点1.x );
|
||||
|
||||
//alert(码标高度转毫米)
|
||||
//alert(码标宽度转毫米)
|
||||
var fileName = currentDocument.name;
|
||||
|
||||
// 去掉文件名的后缀名
|
||||
var fileNameWithoutExtension = fileName.split('.').slice(0, -1).join('.');
|
||||
var textLayer = currentDocument.artLayers.add();
|
||||
textLayer.kind = LayerKind.TEXT;
|
||||
|
||||
// 设置文本图层的文本内容
|
||||
textLayer.textItem.contents = fileNameWithoutExtension
|
||||
textLayer.textItem.size = 10
|
||||
var cmykColor = new SolidColor();
|
||||
cmykColor.cmyk.cyan = 50; // 青色通道值
|
||||
cmykColor.cmyk.magenta = 40; // 品红色通道值
|
||||
cmykColor.cmyk.yellow = 50; // 黄色通道值
|
||||
cmykColor.cmyk.black = 70; // 黑色通道值
|
||||
|
||||
// 将文本图层的颜色设置为上面创建的CMYK颜色
|
||||
textLayer.textItem.color = cmykColor;
|
||||
|
||||
app.preferences.rulerUnits = Units.MM;
|
||||
|
||||
当前图层 = app.activeDocument.activeLayer;
|
||||
当前图层的底边 = 当前图层.bounds[3];
|
||||
当前图层的上边 = 当前图层.bounds[1];
|
||||
当前图层的高度 = 当前图层的底边 - 当前图层的上边;
|
||||
当前图层的左边 = 当前图层.bounds[0];
|
||||
当前图层的右边 = 当前图层.bounds[2];
|
||||
当前图层的宽度 = 当前图层的右边 - 当前图层的左边;
|
||||
当前图层的高度的一半 = 当前图层的高度 / 2;
|
||||
当前图层的宽度的一半 = 当前图层的宽度 / 2;
|
||||
当前图层的高度中心 = 当前图层的上边 + 当前图层的高度的一半;
|
||||
当前图层的宽度中心 = 当前图层的左边 + 当前图层的宽度的一半;
|
||||
|
||||
|
||||
//app.activeDocument.activeLayer.translate(Number(当前图层的宽度中心) - Number(码标宽度转毫米), Number(当前图层的高度中心) - Number(码标高度转毫米));
|
||||
|
||||
app.activeDocument.activeLayer.translate(Number(码标宽度转毫米x) - Number(当前图层的宽度中心), Number(码标高度转毫米y) - Number(当前图层的高度中心));
|
||||
app.preferences.rulerUnits = Units.PIXELS;
|
||||
app.activeDocument.activeLayer.move(app.activeDocument.layerSets.getByName("码标"), ElementPlacement.INSIDE);
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
alert("找不到名为“裁片”的组。");
|
||||
}
|
||||
} else {
|
||||
alert("没有打开的文档。");
|
||||
}
|
||||
|
||||
}
|
||||
码标 = app.activeDocument.layerSets.getByName("码标")
|
||||
app.activeDocument.activeLayer = 码标;
|
||||
描边()
|
||||
|
||||
function 减去选区(上边距, 左边距, 下边距, 右边距) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putUnitDouble(stringIDToTypeID("top"), stringIDToTypeID("pixelsUnit"), 上边距);
|
||||
d1.putUnitDouble(stringIDToTypeID("left"), stringIDToTypeID("pixelsUnit"), 左边距);
|
||||
d1.putUnitDouble(stringIDToTypeID("bottom"), stringIDToTypeID("pixelsUnit"), 下边距);
|
||||
d1.putUnitDouble(stringIDToTypeID("right"), stringIDToTypeID("pixelsUnit"), 右边距);
|
||||
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("rectangle"), d1);
|
||||
executeAction(stringIDToTypeID("subtractFrom"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 收缩45像素() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putUnitDouble(stringIDToTypeID("by"), stringIDToTypeID("pixelsUnit"), 45);
|
||||
d.putBoolean(stringIDToTypeID("selectionModifyEffectAtCanvasBounds"), false);
|
||||
executeAction(stringIDToTypeID("contract"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 获取中心点(x1, y1, x2, y2) {
|
||||
var centerX = (x1 + x2) / 2;
|
||||
var centerY = (y1 + y2) / 2;
|
||||
return { x: centerX, y: centerY };
|
||||
}
|
||||
|
||||
function 切换mask() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("mask"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function 选择组() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("layer"), "码标");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(153);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
function 合并组() //合并组
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 新建选区(上边距, 左边距, 下边距, 右边距) {
|
||||
var currentDocument = app.activeDocument;
|
||||
var top = 上边距;
|
||||
var left = 左边距;
|
||||
var bottom = 下边距;
|
||||
var right = 右边距;
|
||||
|
||||
var selectionRegion = Array(Array(left, top), Array(right, top), Array(right, bottom), Array(left, bottom));
|
||||
currentDocument.selection.select(selectionRegion);
|
||||
}
|
||||
|
||||
|
||||
function 载入选区蒙版() //载入选区
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
function 获取当前选区四边距() {
|
||||
var currentDocument = app.activeDocument;
|
||||
var selectionBounds = currentDocument.selection.bounds;
|
||||
|
||||
var top = selectionBounds[1].value;
|
||||
var left = selectionBounds[0].value;
|
||||
var bottom = selectionBounds[3].value;
|
||||
var right = selectionBounds[2].value;
|
||||
|
||||
return {
|
||||
top: top,
|
||||
left: left,
|
||||
bottom: bottom,
|
||||
right: right
|
||||
};
|
||||
}
|
||||
|
||||
function 描边() //描边
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("layerEffects"));
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putUnitDouble(stringIDToTypeID("scale"), stringIDToTypeID("percentUnit"), 208.333290947808);
|
||||
var d2 = new ActionDescriptor();
|
||||
d2.putBoolean(stringIDToTypeID("enabled"), true);
|
||||
d2.putBoolean(stringIDToTypeID("present"), true);
|
||||
d2.putBoolean(stringIDToTypeID("showInDialog"), true);
|
||||
d2.putEnumerated(stringIDToTypeID("style"), stringIDToTypeID("frameStyle"), stringIDToTypeID("outsetFrame"));
|
||||
d2.putEnumerated(stringIDToTypeID("paintType"), stringIDToTypeID("frameFill"), stringIDToTypeID("solidColor"));
|
||||
d2.putEnumerated(stringIDToTypeID("mode"), stringIDToTypeID("blendMode"), stringIDToTypeID("normal"));
|
||||
d2.putUnitDouble(stringIDToTypeID("opacity"), stringIDToTypeID("percentUnit"), 100);
|
||||
d2.putUnitDouble(stringIDToTypeID("size"), stringIDToTypeID("pixelsUnit"), 2);
|
||||
var d3 = new ActionDescriptor();
|
||||
d3.putDouble(stringIDToTypeID("cyan"), 0);
|
||||
d3.putDouble(stringIDToTypeID("magenta"), 0);
|
||||
d3.putDouble(stringIDToTypeID("yellowColor"), 0);
|
||||
d3.putDouble(stringIDToTypeID("black"), 0);
|
||||
d2.putObject(stringIDToTypeID("color"), stringIDToTypeID("CMYKColorClass"), d3);
|
||||
d2.putBoolean(stringIDToTypeID("overprint"), false);
|
||||
d1.putObject(stringIDToTypeID("frameFX"), stringIDToTypeID("frameFX"), d2);
|
||||
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("layerEffects"), d1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
// 将像素转换为毫米
|
||||
function pixelsToMillimeters(pixels) {
|
||||
// 获取当前文档
|
||||
var doc = app.activeDocument;
|
||||
|
||||
// 获取图像的分辨率(像素/英寸)
|
||||
var resolution = doc.resolution;
|
||||
|
||||
// 计算像素转换为毫米
|
||||
var inches = pixels / resolution;
|
||||
var millimeters = inches * 25.4;
|
||||
|
||||
return millimeters.toFixed(2); // 保留两位小数
|
||||
}
|
||||
|
||||
|
||||
function 选取交叉() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
|
||||
d.putReference(stringIDToTypeID("with"), r1);
|
||||
executeAction(charIDToTypeID("Intr"), d, DialogModes.NO);
|
||||
}
|
||||
Reference in New Issue
Block a user