feat: AI套图分层方案 + Gemini集成 - 4种图案类型处理 + 正片叠底 + 宽高比 + 模型选择
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
225
PSMARK代码块/44222.jsx
Normal file
225
PSMARK代码块/44222.jsx
Normal file
@@ -0,0 +1,225 @@
|
||||
|
||||
贴图换图()
|
||||
function 贴图换图() {
|
||||
建立快照();
|
||||
var folder = Folder.selectDialog("请选择一个文件夹");
|
||||
var 模特文档 = app.activeDocument;
|
||||
|
||||
if (folder) {
|
||||
// 在选择的文件夹中创建一个新的子文件夹
|
||||
var targetFolder = new Folder(folder.fullName + "/贴图生成");
|
||||
if (!targetFolder.exists) {
|
||||
targetFolder.create();
|
||||
}
|
||||
|
||||
var fileNames = [];
|
||||
var files = folder.getFiles();
|
||||
|
||||
// 获取文件夹中的所有文件名
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
if (files[i] instanceof File) {
|
||||
fileNames.push(files[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取“贴图位置”图层组中的所有图层名称
|
||||
var layerSet = 模特文档.layerSets.getByName("贴图位置");
|
||||
var layerNames = [];
|
||||
for (var j = 0; j < layerSet.artLayers.length; j++) {
|
||||
layerNames.push(layerSet.artLayers[j].name);
|
||||
}
|
||||
|
||||
// 遍历“贴图位置”图层组中的每个图层
|
||||
for (var k = 0; k < layerNames.length; k++) {
|
||||
var layname = layerNames[k];
|
||||
var 贴图位置 = app.activeDocument.layerSets.getByName("贴图位置").layers.getByName(layname);
|
||||
app.activeDocument.activeLayer = 贴图位置;
|
||||
|
||||
// 依次调取文件夹中的文件
|
||||
if (k < fileNames.length) {
|
||||
var file = new File(folder + "/" + fileNames[k]);
|
||||
if (file.exists) {
|
||||
try {
|
||||
app.open(file);
|
||||
app.activeDocument.flatten();
|
||||
var 当前文档 = app.activeDocument;
|
||||
var 当前文档名称 = 当前文档.name;
|
||||
预设图案(当前文档名称); // 需要自定义实现
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
app.activeDocument = 模特文档;
|
||||
载入选区(); // 需要自定义实现
|
||||
填充图案(当前文档名称); // 需要自定义实现
|
||||
} catch (e) {
|
||||
alert("无法打开文件: " + fileNames[k]);
|
||||
}
|
||||
|
||||
// 保存文件为 TIF 格式
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
var 当前文档 = app.activeDocument; // 获取当前文档
|
||||
var 当前文档名称 = 当前文档.name; // 获取当前文档名称(包含扩展名)
|
||||
|
||||
// 去除文件扩展名并添加 ".tif" 后缀
|
||||
var 文件名 = 当前文档名称.replace(/\.[^\.]+$/, "") + ".tif";
|
||||
|
||||
// 创建保存路径的 File 对象
|
||||
var saveFile = new File(当前文档.path + "/" + 文件名);
|
||||
|
||||
// 设置 Tiff 保存选项
|
||||
var tiffSaveOptions = new TiffSaveOptions();
|
||||
tiffSaveOptions.imageCompression = TIFFEncoding.NONE; // 无压缩
|
||||
tiffSaveOptions.alphaChannels = true; // 保留 alpha 通道
|
||||
tiffSaveOptions.layers = true; // 保留图层
|
||||
|
||||
// 另存为 TIF 格式
|
||||
当前文档.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
|
||||
alert("换图完成");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 其他函数保持不变
|
||||
|
||||
|
||||
function generateRandomNumber(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 图像大小() //图像大小
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putUnitDouble(stringIDToTypeID("resolution"), stringIDToTypeID("densityUnit"), 150);
|
||||
d.putBoolean(stringIDToTypeID("scaleStyles"), true);
|
||||
d.putBoolean(stringIDToTypeID("constrainProportions"), true);
|
||||
d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("nearestNeighbor"));
|
||||
executeAction(stringIDToTypeID("imageSize"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 取消链接蒙版() //取消链接蒙版
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putBoolean(stringIDToTypeID("userMaskLinked"), false);
|
||||
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("layer"), d1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 栅格化图层() //栅格化图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("rasterizeLayer"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 预设图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("pattern"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
|
||||
r1.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("using"), r1);
|
||||
d.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
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("channel"), stringIDToTypeID("transparencyEnum"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 填充图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("contentLayer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
var d2 = new ActionDescriptor();
|
||||
var d3 = new ActionDescriptor();
|
||||
d3.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
|
||||
d2.putObject(stringIDToTypeID("pattern"), stringIDToTypeID("pattern"), d3);
|
||||
d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("patternLayer"), d2);
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("contentLayer"), d1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 位移(水平,垂直) //位移
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putInteger(stringIDToTypeID("horizontal"), 水平);
|
||||
d.putInteger(stringIDToTypeID("vertical"), 垂直);
|
||||
d.putEnumerated(stringIDToTypeID("fill"), stringIDToTypeID("fillMode"), stringIDToTypeID("wrap"));
|
||||
executeAction(stringIDToTypeID("offset"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 历史记录回退到快照1() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("snapshotClass"), "快照 1");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 建立快照() //打开
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("snapshotClass"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("historyState"), stringIDToTypeID("currentHistoryState"));
|
||||
d.putReference(stringIDToTypeID("from"), r1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
1001
PSMARK代码块/JSX17.jsx
Normal file
1001
PSMARK代码块/JSX17.jsx
Normal file
File diff suppressed because it is too large
Load Diff
80
PSMARK代码块/JSX监听单个事件-漂流鱼.jsx
Normal file
80
PSMARK代码块/JSX监听单个事件-漂流鱼.jsx
Normal file
@@ -0,0 +1,80 @@
|
||||
//JSX监听某个事件
|
||||
|
||||
alert("当前监听事件个数:"+app.notifiers.length,"提示:")
|
||||
|
||||
try
|
||||
{
|
||||
arg_num = arguments.length;
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
arguments = []; //初始赋值为空
|
||||
}
|
||||
|
||||
eventName = "recordMeasurements";
|
||||
|
||||
//开启监听
|
||||
enable_notifier(eventName, $.fileName);
|
||||
|
||||
//取消监听
|
||||
//~ disable_notifier(eventName, $.fileName);
|
||||
|
||||
//这里进行监控调用事件
|
||||
if (arguments.length >= 2)
|
||||
{
|
||||
//alert(arguments.length);
|
||||
//~ alert(arguments[0],"动作参数1"); //动作描述符 AR
|
||||
//~ alert(arguments[1],"动作参数2"); //动作事件ID
|
||||
|
||||
alert("事件名:"+typeIDToStringID(arguments[1])+"\n"+"事件ID:"+arguments[1],"提示:");
|
||||
|
||||
//main(arguments[0], arguments[1]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function enable_notifier(event_name, script_name, event_class)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < app.notifiers.length; i++)
|
||||
{
|
||||
if (app.notifiers[i].event == event_name &&
|
||||
File(app.notifiers[i].eventFile).fsName.toLowerCase() == File(script_name).fsName.toLowerCase())
|
||||
{
|
||||
if (!app.notifiersEnabled) app.notifiersEnabled = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
app.notifiers.add(event_name, File(script_name), event_class);
|
||||
app.notifiersEnabled = true;
|
||||
return true;
|
||||
}
|
||||
catch (e) { _alert(e); return false; }
|
||||
}
|
||||
|
||||
|
||||
function disable_notifier(event_name, script_name, event_class)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ret = false;
|
||||
|
||||
for (var i = 0; i < app.notifiers.length; i++)
|
||||
{
|
||||
if (app.notifiers[i].event == event_name &&
|
||||
File(app.notifiers[i].eventFile).fsName.toLowerCase() == File(script_name).fsName.toLowerCase())
|
||||
{
|
||||
app.notifiers[i].remove();
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!app.notifiers.length) app.notifiersEnabled = false;
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch (e) { _alert(e); return false; }
|
||||
}
|
||||
627
PSMARK代码块/PNG素材拆分图层 - 函数.jsx
Normal file
627
PSMARK代码块/PNG素材拆分图层 - 函数.jsx
Normal file
@@ -0,0 +1,627 @@
|
||||
// photoshopscripts.wordpress.com
|
||||
|
||||
////////////////////////////////////
|
||||
// Split to Layers 1.0 //
|
||||
// 2012, David Jensen //
|
||||
// //
|
||||
// With help from //
|
||||
// pfaffenbichler and xbytor //
|
||||
// at ps-scripts.com //
|
||||
////////////////////////////////////
|
||||
|
||||
#target photoshop
|
||||
|
||||
|
||||
|
||||
//更改以下 5 个值中的任何一个以自定义脚本的默认选项:
|
||||
|
||||
var showOptionsDialog = true; //设置为 false 以禁用对用户的提示.
|
||||
var tolerance = 2; // 将被忽略的透明像素的最大间隙,设置默认值.
|
||||
var confirmThreshold = 20; // 如果脚本要制作大量图层,提示用户确认这是可以的.
|
||||
var suffix = "-"; // 将此添加到新图层的图层名称中. 设置为空不添加.
|
||||
var addCount = true; // 在每个新层的末尾添加一个增量数字.
|
||||
|
||||
|
||||
///////////////////////////////////////
|
||||
///////////////////////////////////////
|
||||
///////////////////////////////////////
|
||||
///////////////////////////////////////
|
||||
///////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
function 裁片分解()
|
||||
{
|
||||
var layerNamePreview=activeDocument.activeLayer.name + suffix;
|
||||
if (addCount === true){
|
||||
layerNamePreview += "1";
|
||||
}
|
||||
|
||||
var originalRulerUnits = app.preferences.rulerUnits;
|
||||
app.preferences.rulerUnits = Units.POINTS;
|
||||
|
||||
bounds = activeDocument.activeLayer.bounds
|
||||
var emptyLayer=false;
|
||||
if (Number(bounds[0]) == 0 && Number(bounds[1]) == 0 && Number(bounds[2]) == 0 && Number(bounds[3]) == 0) {emptyLayer = true};
|
||||
|
||||
try{
|
||||
if (activeDocument.activeLayer.kind != undefined && activeDocument.activeLayer.isBackgroundLayer == false && emptyLayer == false){
|
||||
activeDocument.suspendHistory("Separate", "main()");
|
||||
//~ app.doForcedProgress("PSMark-裁片分解","PSMark_main()");
|
||||
//~ app.doProgress("PSMark-裁片分解","PSMark_main()");
|
||||
//~ app.doForcedProgress("PSMark-裁片分解","main()");
|
||||
}else{
|
||||
alert( "未选择支持的图层类型.");
|
||||
}
|
||||
}catch(err){
|
||||
alert(err)
|
||||
}
|
||||
|
||||
app.preferences.rulerUnits = originalRulerUnits;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function PSMark_main()
|
||||
{
|
||||
app.activeDocument.suspendHistory("Separate", "main()");
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
||||
baseLayer=activeDocument.activeLayer;
|
||||
activeDocument.quickMaskMode = false;
|
||||
activeDocument.selection.deselect()
|
||||
var layerName = activeDocument.activeLayer.name
|
||||
//if a selection can't be made, stop running the script
|
||||
|
||||
|
||||
var idCpTL = charIDToTypeID("CpTL");
|
||||
executeAction(idCpTL, undefined, DialogModes.NO);
|
||||
|
||||
activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER)
|
||||
try{
|
||||
var idDlt = charIDToTypeID( "Dlt " );
|
||||
var desc120 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID( "null" );
|
||||
var ref112 = new ActionReference();
|
||||
var idChnl = charIDToTypeID( "Chnl" );
|
||||
var idChnl = charIDToTypeID( "Chnl" );
|
||||
var idMsk = charIDToTypeID( "Msk " );
|
||||
ref112.putEnumerated( idChnl, idChnl, idMsk );
|
||||
desc120.putReference( idnull, ref112 );
|
||||
var idAply = charIDToTypeID( "Aply" );
|
||||
desc120.putBoolean( idAply, true );
|
||||
executeAction( idDlt, desc120, DialogModes.NO );
|
||||
}catch(e){}
|
||||
|
||||
|
||||
|
||||
activeDocument.activeLayer.name = layerName;
|
||||
|
||||
baseLayer=activeDocument.activeLayer;
|
||||
|
||||
|
||||
|
||||
makeSelection();
|
||||
|
||||
var idMk = charIDToTypeID("Mk ");
|
||||
var desc642 = new ActionDescriptor();
|
||||
var idNw = charIDToTypeID("Nw ");
|
||||
var idDcmn = charIDToTypeID("Dcmn");
|
||||
desc642.putClass(idNw, idDcmn);
|
||||
var idUsng = charIDToTypeID("Usng");
|
||||
var ref535 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref535.putEnumerated(idChnl, idOrdn, idTrgt);
|
||||
desc642.putReference(idUsng, ref535);
|
||||
executeAction(idMk, desc642, DialogModes.NO);
|
||||
|
||||
newDoc = activeDocument;
|
||||
// =======================================================
|
||||
activeDocument.resizeImage("200%", "200%", undefined, ResampleMethod.NEARESTNEIGHBOR);
|
||||
|
||||
// =======================================================
|
||||
var idsetd = charIDToTypeID("setd");
|
||||
var desc934 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref535 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref535.putProperty(idChnl, idfsel);
|
||||
desc934.putReference(idnull, ref535);
|
||||
var idT = charIDToTypeID("T ");
|
||||
var ref536 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref536.putEnumerated(idChnl, idOrdn, idTrgt);
|
||||
desc934.putReference(idT, ref536);
|
||||
executeAction(idsetd, desc934, DialogModes.NO);
|
||||
|
||||
|
||||
var idMk = charIDToTypeID("Mk ");
|
||||
var desc403 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref288 = new ActionReference();
|
||||
var idPath = charIDToTypeID("Path");
|
||||
ref288.putClass(idPath);
|
||||
desc403.putReference(idnull, ref288);
|
||||
var idFrom = charIDToTypeID("From");
|
||||
var ref289 = new ActionReference();
|
||||
var idcsel = charIDToTypeID("csel");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref289.putProperty(idcsel, idfsel);
|
||||
desc403.putReference(idFrom, ref289);
|
||||
var idTlrn = charIDToTypeID("Tlrn");
|
||||
var idPxl = charIDToTypeID("#Pxl");
|
||||
desc403.putUnitDouble(idTlrn, idPxl, 0.500000);
|
||||
executeAction(idMk, desc403, DialogModes.NO);
|
||||
|
||||
var subPathsLength = activeDocument.pathItems[0].subPathItems.length
|
||||
|
||||
if (subPathsLength>confirmThreshold){
|
||||
var answer = confirm("基于"+subPathsLength+ "个拆分对象将创建图层. 你想继续吗?",true)
|
||||
if (answer === false){
|
||||
newDoc.close(SaveOptions.DONOTSAVECHANGES);
|
||||
activeDocument.quickMaskMode = false;
|
||||
activeDocument.selection.deselect();
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =======================================================
|
||||
activeDocument.resizeImage("50%", "50%", undefined, ResampleMethod.NEARESTNEIGHBOR)
|
||||
|
||||
var pathInfo = collectPathInfoFromDesc(activeDocument, activeDocument.pathItems[activeDocument.pathItems.length - 1])
|
||||
|
||||
// =======================================================
|
||||
newDoc.close(SaveOptions.DONOTSAVECHANGES)
|
||||
|
||||
// =======================================================
|
||||
activeDocument.quickMaskMode = false
|
||||
|
||||
// =======================================================
|
||||
//make channel
|
||||
// =======================================================
|
||||
var idMk = charIDToTypeID("Mk ");
|
||||
var desc6 = new ActionDescriptor();
|
||||
var idNw = charIDToTypeID("Nw ");
|
||||
var desc7 = new ActionDescriptor();
|
||||
var idNm = charIDToTypeID("Nm ");
|
||||
desc7.putString(idNm, "ContiguityMask");
|
||||
var idClrI = charIDToTypeID("ClrI");
|
||||
var idMskI = charIDToTypeID("MskI");
|
||||
var idMskA = charIDToTypeID("MskA");
|
||||
desc7.putEnumerated(idClrI, idMskI, idMskA);
|
||||
var idClr = charIDToTypeID("Clr ");
|
||||
var desc8 = new ActionDescriptor();
|
||||
var idRd = charIDToTypeID("Rd ");
|
||||
desc8.putDouble(idRd, 255.000000);
|
||||
var idGrn = charIDToTypeID("Grn ");
|
||||
desc8.putDouble(idGrn, 0.000000);
|
||||
var idBl = charIDToTypeID("Bl ");
|
||||
desc8.putDouble(idBl, 0.000000);
|
||||
var idRGBC = charIDToTypeID("RGBC");
|
||||
desc7.putObject(idClr, idRGBC, desc8);
|
||||
var idOpct = charIDToTypeID("Opct");
|
||||
desc7.putInteger(idOpct, 50);
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
desc6.putObject(idNw, idChnl, desc7);
|
||||
var idUsng = charIDToTypeID("Usng");
|
||||
var ref5 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref5.putProperty(idChnl, idfsel);
|
||||
desc6.putReference(idUsng, ref5);
|
||||
executeAction(idMk, desc6, DialogModes.NO);
|
||||
|
||||
|
||||
doc_name = app.activeDocument.name.replace(/(?:\.[^.]*$|$)/, '');
|
||||
|
||||
var layerCount = 1
|
||||
for (i = 0; i < subPathsLength; i++) {
|
||||
//deselect
|
||||
var idsetd = charIDToTypeID("setd");
|
||||
var desc279 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref137 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref137.putProperty(idChnl, idfsel);
|
||||
desc279.putReference(idnull, ref137);
|
||||
var idT = charIDToTypeID("T ");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idNone = charIDToTypeID("None");
|
||||
desc279.putEnumerated(idT, idOrdn, idNone);
|
||||
executeAction(idsetd, desc279, DialogModes.NO);
|
||||
///select alpha channel
|
||||
var idslct = charIDToTypeID("slct");
|
||||
var desc315 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref175 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
ref175.putName(idChnl, "ContiguityMask");
|
||||
desc315.putReference(idnull, ref175);
|
||||
executeAction(idslct, desc315, DialogModes.NO);
|
||||
//use magic wand
|
||||
var idsetd = charIDToTypeID("setd");
|
||||
var desc263 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref123 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref123.putProperty(idChnl, idfsel);
|
||||
desc263.putReference(idnull, ref123);
|
||||
var idT = charIDToTypeID("T ");
|
||||
var desc264 = new ActionDescriptor();
|
||||
var idHrzn = charIDToTypeID("Hrzn");
|
||||
var idRlt = charIDToTypeID("#Rlt");
|
||||
desc264.putUnitDouble(idHrzn, idRlt, pathInfo[i][0][0]);
|
||||
var idVrtc = charIDToTypeID("Vrtc");
|
||||
var idRlt = charIDToTypeID("#Rlt");
|
||||
|
||||
desc264.putUnitDouble(idVrtc, idRlt, pathInfo[i][0][1]);
|
||||
var idPnt = charIDToTypeID("Pnt ");
|
||||
desc263.putObject(idT, idPnt, desc264);
|
||||
var idTlrn = charIDToTypeID("Tlrn");
|
||||
desc263.putInteger(idTlrn, 1);
|
||||
executeAction(idsetd, desc263, DialogModes.NO);
|
||||
|
||||
var idslct = charIDToTypeID("slct");
|
||||
var desc346 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref205 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idRGB = charIDToTypeID("RGB ");
|
||||
ref205.putEnumerated(idChnl, idChnl, idRGB);
|
||||
desc346.putReference(idnull, ref205);
|
||||
var idMkVs = charIDToTypeID("MkVs");
|
||||
desc346.putBoolean(idMkVs, false);
|
||||
executeAction(idslct, desc346, DialogModes.NO);
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
// =======================================================
|
||||
var idCpTL = charIDToTypeID("CpTL");
|
||||
executeAction(idCpTL, undefined, DialogModes.NO);
|
||||
|
||||
try {
|
||||
var idrasterizeLayer = stringIDToTypeID("rasterizeLayer");
|
||||
var desc924 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref721 = new ActionReference();
|
||||
var idLyr = charIDToTypeID("Lyr ");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref721.putEnumerated(idLyr, idOrdn, idTrgt);
|
||||
desc924.putReference(idnull, ref721);
|
||||
var idWhat = charIDToTypeID("What");
|
||||
var idrasterizeItem = stringIDToTypeID("rasterizeItem");
|
||||
var idvectorMask = stringIDToTypeID("vectorMask");
|
||||
desc924.putEnumerated(idWhat, idrasterizeItem, idvectorMask);
|
||||
executeAction(idrasterizeLayer, desc924, DialogModes.NO);
|
||||
} catch (err) {}
|
||||
|
||||
try {
|
||||
var idIntr = charIDToTypeID("Intr");
|
||||
var desc864 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref658 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref658.putEnumerated(idChnl, idOrdn, idTrgt);
|
||||
desc864.putReference(idnull, ref658);
|
||||
var idWith = charIDToTypeID("With");
|
||||
var ref659 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref659.putProperty(idChnl, idfsel);
|
||||
desc864.putReference(idWith, ref659);
|
||||
executeAction(idIntr, desc864, DialogModes.NO);
|
||||
|
||||
// =======================================================
|
||||
var idDlt = charIDToTypeID("Dlt ");
|
||||
var desc865 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref660 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref660.putEnumerated(idChnl, idOrdn, idTrgt);
|
||||
desc865.putReference(idnull, ref660);
|
||||
executeAction(idDlt, desc865, DialogModes.NO);
|
||||
|
||||
// =======================================================
|
||||
var idMk = charIDToTypeID("Mk ");
|
||||
var desc866 = new ActionDescriptor();
|
||||
var idNw = charIDToTypeID("Nw ");
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
desc866.putClass(idNw, idChnl);
|
||||
var idAt = charIDToTypeID("At ");
|
||||
var ref661 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idMsk = charIDToTypeID("Msk ");
|
||||
ref661.putEnumerated(idChnl, idChnl, idMsk);
|
||||
desc866.putReference(idAt, ref661);
|
||||
var idUsng = charIDToTypeID("Usng");
|
||||
var idUsrM = charIDToTypeID("UsrM");
|
||||
var idRvlS = charIDToTypeID("RvlS");
|
||||
desc866.putEnumerated(idUsng, idUsrM, idRvlS);
|
||||
executeAction(idMk, desc866, DialogModes.NO);
|
||||
|
||||
} catch (err) {}
|
||||
|
||||
var finalSuffix = suffix;
|
||||
if (addCount===true)
|
||||
{
|
||||
finalSuffix += layerCount;
|
||||
}
|
||||
|
||||
|
||||
//~ activeDocument.activeLayer.name = layerName + finalSuffix;
|
||||
//分解的图层命名
|
||||
activeDocument.activeLayer.name = "Mark" +"-" + doc_name + finalSuffix;
|
||||
layerCount++;
|
||||
|
||||
|
||||
//~ $.writeln(100*(layerCount-1)/subPathsLength);
|
||||
//~ $.writeln("subPathsLength:"+subPathsLength);
|
||||
//~ app.updateProgress(100*(layerCount-1)/subPathsLength,100);
|
||||
|
||||
|
||||
activeDocument.activeLayer=baseLayer;
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
var idsetd = charIDToTypeID("setd");
|
||||
var desc1045 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref578 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref578.putProperty(idChnl, idfsel);
|
||||
desc1045.putReference(idnull, ref578);
|
||||
var idT = charIDToTypeID("T ");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idNone = charIDToTypeID("None");
|
||||
desc1045.putEnumerated(idT, idOrdn, idNone);
|
||||
executeAction(idsetd, desc1045, DialogModes.NO);
|
||||
|
||||
// =======================================================
|
||||
var idDlt = charIDToTypeID("Dlt ");
|
||||
var desc694 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref323 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
ref323.putName(idChnl, "ContiguityMask");
|
||||
desc694.putReference(idnull, ref323);
|
||||
executeAction(idDlt, desc694, DialogModes.NO);
|
||||
|
||||
|
||||
activeDocument.activeLayer.remove();
|
||||
|
||||
|
||||
|
||||
var idHd = charIDToTypeID("Hd ");
|
||||
var desc736 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var list22 = new ActionList();
|
||||
var ref541 = new ActionReference();
|
||||
var idLyr = charIDToTypeID("Lyr ");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref541.putEnumerated(idLyr, idOrdn, idTrgt);
|
||||
list22.putReference(ref541);
|
||||
desc736.putList(idnull, list22);
|
||||
executeAction(idHd, desc736, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// pfaffenbichler and xbytor //
|
||||
// at ps-scripts.com //
|
||||
// created this function //
|
||||
function collectPathInfoFromDesc(myDocument, thePath) {
|
||||
var myDocument = app.activeDocument;
|
||||
|
||||
// based of functions from xbytor’s stdlib;
|
||||
var ref = new ActionReference();
|
||||
for (var l = 0; l < myDocument.pathItems.length; l++) {
|
||||
var thisPath = myDocument.pathItems[l];
|
||||
if (thisPath == thePath && thisPath.name == "Work Path") {
|
||||
ref.putProperty(cTID("Path"), cTID("WrPt"));
|
||||
};
|
||||
if (thisPath == thePath && thisPath.name != "Work Path" && thisPath.kind != PathKind.VECTORMASK) {
|
||||
ref.putIndex(cTID("Path"), l + 1);
|
||||
};
|
||||
if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {
|
||||
var idPath = charIDToTypeID("Path");
|
||||
var idPath = charIDToTypeID("Path");
|
||||
var idvectorMask = stringIDToTypeID("vectorMask");
|
||||
ref.putEnumerated(idPath, idPath, idvectorMask);
|
||||
};
|
||||
};
|
||||
var desc = app.executeActionGet(ref);
|
||||
var pname = desc.getString(cTID('PthN'));
|
||||
// create new array;
|
||||
var theArray = new Array;
|
||||
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
|
||||
// for subpathitems;
|
||||
for (var m = 0; m < pathComponents.count; m++) {
|
||||
var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
|
||||
// for subpathitem’s count;
|
||||
for (var n = 0; n < listKey.count; n++) {
|
||||
var points = listKey.getObjectValue(n).getList(sTID('points'));
|
||||
// get first point;
|
||||
var anchorObj = points.getObjectValue(0).getObjectValue(sTID("anchor"));
|
||||
var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
|
||||
var thisPoint = [anchor];
|
||||
theArray.push(thisPoint);
|
||||
};
|
||||
};
|
||||
// by xbytor, thanks to him;
|
||||
|
||||
|
||||
function cTID(s) {
|
||||
return cTID[s] || cTID[s] = app.charIDToTypeID(s);
|
||||
};
|
||||
|
||||
function sTID(s) {
|
||||
return sTID[s] || sTID[s] = app.stringIDToTypeID(s);
|
||||
};
|
||||
// reset;
|
||||
return theArray;
|
||||
};
|
||||
|
||||
|
||||
function makePreviewSelection(){
|
||||
makeSelection()
|
||||
app.refresh()
|
||||
activeDocument.quickMaskMode = false;
|
||||
}
|
||||
|
||||
function makeSelection(){
|
||||
try{
|
||||
|
||||
var idsetd = charIDToTypeID("setd");
|
||||
var desc922 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref529 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref529.putProperty(idChnl, idfsel);
|
||||
desc922.putReference(idnull, ref529);
|
||||
var idT = charIDToTypeID("T ");
|
||||
var ref530 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idTrsp = charIDToTypeID("Trsp");
|
||||
ref530.putEnumerated(idChnl, idChnl, idTrsp);
|
||||
desc922.putReference(idT, ref530);
|
||||
executeAction(idsetd, desc922, DialogModes.NO);
|
||||
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
var idIntr = charIDToTypeID("Intr");
|
||||
var desc846 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref639 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idMsk = charIDToTypeID("Msk ");
|
||||
ref639.putEnumerated(idChnl, idChnl, idMsk);
|
||||
desc846.putReference(idnull, ref639);
|
||||
var idWith = charIDToTypeID("With");
|
||||
var ref640 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref640.putProperty(idChnl, idfsel);
|
||||
desc846.putReference(idWith, ref640);
|
||||
executeAction(idIntr, desc846, DialogModes.NO);
|
||||
|
||||
|
||||
} catch (err) {}
|
||||
|
||||
try {
|
||||
// =======================================================
|
||||
var idIntW = charIDToTypeID("IntW");
|
||||
var desc787 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref572 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref572.putProperty(idChnl, idfsel);
|
||||
desc787.putReference(idnull, ref572);
|
||||
var idT = charIDToTypeID("T ");
|
||||
var ref573 = new ActionReference();
|
||||
var idPath = charIDToTypeID("Path");
|
||||
var idPath = charIDToTypeID("Path");
|
||||
var idvectorMask = stringIDToTypeID("vectorMask");
|
||||
ref573.putEnumerated(idPath, idPath, idvectorMask);
|
||||
var idLyr = charIDToTypeID("Lyr ");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref573.putEnumerated(idLyr, idOrdn, idTrgt);
|
||||
desc787.putReference(idT, ref573);
|
||||
var idVrsn = charIDToTypeID("Vrsn");
|
||||
desc787.putInteger(idVrsn, 1);
|
||||
var idvectorMaskParams = stringIDToTypeID("vectorMaskParams");
|
||||
desc787.putBoolean(idvectorMaskParams, true);
|
||||
executeAction(idIntW, desc787, DialogModes.NO);
|
||||
} catch (err) {}
|
||||
|
||||
|
||||
|
||||
if (tolerance >= 2) {
|
||||
|
||||
activeDocument.selection.expand(Math.floor(tolerance / 2))
|
||||
|
||||
}
|
||||
|
||||
|
||||
activeDocument.quickMaskMode = true;
|
||||
|
||||
|
||||
var idThrs = charIDToTypeID("Thrs");
|
||||
var desc479 = new ActionDescriptor();
|
||||
var idLvl = charIDToTypeID("Lvl ");
|
||||
desc479.putInteger(idLvl, 1);
|
||||
executeAction(idThrs, desc479, DialogModes.NO);
|
||||
|
||||
|
||||
|
||||
if (tolerance % 2 == 1) {
|
||||
|
||||
var idMtnB = charIDToTypeID("MtnB");
|
||||
var desc213 = new ActionDescriptor();
|
||||
var idAngl = charIDToTypeID("Angl");
|
||||
desc213.putInteger(idAngl, 0);
|
||||
var idDstn = charIDToTypeID("Dstn");
|
||||
var idPxl = charIDToTypeID("#Pxl");
|
||||
desc213.putUnitDouble(idDstn, idPxl, 1.000000);
|
||||
executeAction(idMtnB, desc213, DialogModes.NO);
|
||||
|
||||
// =======================================================
|
||||
var idMtnB = charIDToTypeID("MtnB");
|
||||
var desc214 = new ActionDescriptor();
|
||||
var idAngl = charIDToTypeID("Angl");
|
||||
desc214.putInteger(idAngl, 90);
|
||||
var idDstn = charIDToTypeID("Dstn");
|
||||
var idPxl = charIDToTypeID("#Pxl");
|
||||
desc214.putUnitDouble(idDstn, idPxl, 1.000000);
|
||||
executeAction(idMtnB, desc214, DialogModes.NO);
|
||||
|
||||
|
||||
// =======================================================
|
||||
var idThrs = charIDToTypeID("Thrs");
|
||||
var desc215 = new ActionDescriptor();
|
||||
var idLvl = charIDToTypeID("Lvl ");
|
||||
desc215.putInteger(idLvl, 1);
|
||||
executeAction(idThrs, desc215, DialogModes.NO);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
673
PSMARK代码块/PNG素材拆分图层.jsx
Normal file
673
PSMARK代码块/PNG素材拆分图层.jsx
Normal file
@@ -0,0 +1,673 @@
|
||||
// photoshopscripts.wordpress.com
|
||||
|
||||
////////////////////////////////////
|
||||
// Split to Layers 1.0 //
|
||||
// 2012, David Jensen //
|
||||
// //
|
||||
// With help from //
|
||||
// pfaffenbichler and xbytor //
|
||||
// at ps-scripts.com //
|
||||
////////////////////////////////////
|
||||
|
||||
#target photoshop
|
||||
|
||||
//更改以下 5 个值中的任何一个以自定义脚本的默认选项:
|
||||
|
||||
var showOptionsDialog = true; //设置为 false 以禁用对用户的提示.
|
||||
var tolerance = 2; // 将被忽略的透明像素的最大间隙,设置默认值.
|
||||
var confirmThreshold = 20; // 如果脚本要制作大量图层,提示用户确认这是可以的.
|
||||
var suffix = "-"; // 将此添加到新图层的图层名称中. 设置为空不添加.
|
||||
var addCount = true; // 在每个新层的末尾添加一个增量数字.
|
||||
|
||||
|
||||
///////////////////////////////////////
|
||||
///////////////////////////////////////
|
||||
///////////////////////////////////////
|
||||
///////////////////////////////////////
|
||||
///////////////////////////////////////
|
||||
var layerNamePreview=activeDocument.activeLayer.name + suffix;
|
||||
if (addCount === true){
|
||||
layerNamePreview += "1";
|
||||
}
|
||||
|
||||
var originalRulerUnits = app.preferences.rulerUnits;
|
||||
app.preferences.rulerUnits = Units.POINTS;
|
||||
|
||||
bounds = activeDocument.activeLayer.bounds
|
||||
var emptyLayer=false;
|
||||
if (Number(bounds[0]) == 0 && Number(bounds[1]) == 0 && Number(bounds[2]) == 0 && Number(bounds[3]) == 0) {emptyLayer = true};
|
||||
|
||||
try{
|
||||
if (activeDocument.activeLayer.kind != undefined && activeDocument.activeLayer.isBackgroundLayer == false && emptyLayer == false){
|
||||
|
||||
|
||||
app.doForcedProgress("PSMark-裁片分解","PSMark_main()");
|
||||
|
||||
}else{
|
||||
alert( "未选择支持的图层类型.");
|
||||
}
|
||||
}catch(err){
|
||||
alert(err)
|
||||
}
|
||||
|
||||
app.preferences.rulerUnits = originalRulerUnits;
|
||||
|
||||
|
||||
function PSMark_main()
|
||||
{
|
||||
app.activeDocument.suspendHistory("Separate", "main()");
|
||||
}
|
||||
|
||||
|
||||
function main() {
|
||||
|
||||
var ok=createDialog();
|
||||
if (ok===2){
|
||||
activeDocument.selection.deselect()
|
||||
return false;
|
||||
}
|
||||
baseLayer=activeDocument.activeLayer;
|
||||
activeDocument.quickMaskMode = false;
|
||||
activeDocument.selection.deselect()
|
||||
var layerName = activeDocument.activeLayer.name
|
||||
//if a selection can't be made, stop running the script
|
||||
|
||||
|
||||
var idCpTL = charIDToTypeID("CpTL");
|
||||
executeAction(idCpTL, undefined, DialogModes.NO);
|
||||
|
||||
activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER)
|
||||
try{
|
||||
var idDlt = charIDToTypeID( "Dlt " );
|
||||
var desc120 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID( "null" );
|
||||
var ref112 = new ActionReference();
|
||||
var idChnl = charIDToTypeID( "Chnl" );
|
||||
var idChnl = charIDToTypeID( "Chnl" );
|
||||
var idMsk = charIDToTypeID( "Msk " );
|
||||
ref112.putEnumerated( idChnl, idChnl, idMsk );
|
||||
desc120.putReference( idnull, ref112 );
|
||||
var idAply = charIDToTypeID( "Aply" );
|
||||
desc120.putBoolean( idAply, true );
|
||||
executeAction( idDlt, desc120, DialogModes.NO );
|
||||
}catch(e){}
|
||||
|
||||
|
||||
|
||||
activeDocument.activeLayer.name = layerName
|
||||
|
||||
baseLayer=activeDocument.activeLayer
|
||||
|
||||
|
||||
|
||||
makeSelection()
|
||||
|
||||
var idMk = charIDToTypeID("Mk ");
|
||||
var desc642 = new ActionDescriptor();
|
||||
var idNw = charIDToTypeID("Nw ");
|
||||
var idDcmn = charIDToTypeID("Dcmn");
|
||||
desc642.putClass(idNw, idDcmn);
|
||||
var idUsng = charIDToTypeID("Usng");
|
||||
var ref535 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref535.putEnumerated(idChnl, idOrdn, idTrgt);
|
||||
desc642.putReference(idUsng, ref535);
|
||||
executeAction(idMk, desc642, DialogModes.NO);
|
||||
|
||||
newDoc = activeDocument
|
||||
// =======================================================
|
||||
activeDocument.resizeImage("200%", "200%", undefined, ResampleMethod.NEARESTNEIGHBOR)
|
||||
|
||||
// =======================================================
|
||||
var idsetd = charIDToTypeID("setd");
|
||||
var desc934 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref535 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref535.putProperty(idChnl, idfsel);
|
||||
desc934.putReference(idnull, ref535);
|
||||
var idT = charIDToTypeID("T ");
|
||||
var ref536 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref536.putEnumerated(idChnl, idOrdn, idTrgt);
|
||||
desc934.putReference(idT, ref536);
|
||||
executeAction(idsetd, desc934, DialogModes.NO);
|
||||
|
||||
|
||||
var idMk = charIDToTypeID("Mk ");
|
||||
var desc403 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref288 = new ActionReference();
|
||||
var idPath = charIDToTypeID("Path");
|
||||
ref288.putClass(idPath);
|
||||
desc403.putReference(idnull, ref288);
|
||||
var idFrom = charIDToTypeID("From");
|
||||
var ref289 = new ActionReference();
|
||||
var idcsel = charIDToTypeID("csel");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref289.putProperty(idcsel, idfsel);
|
||||
desc403.putReference(idFrom, ref289);
|
||||
var idTlrn = charIDToTypeID("Tlrn");
|
||||
var idPxl = charIDToTypeID("#Pxl");
|
||||
desc403.putUnitDouble(idTlrn, idPxl, 0.500000);
|
||||
executeAction(idMk, desc403, DialogModes.NO);
|
||||
|
||||
var subPathsLength = activeDocument.pathItems[0].subPathItems.length
|
||||
|
||||
if (subPathsLength>confirmThreshold){
|
||||
var answer = confirm("基于"+subPathsLength+ "个拆分对象将创建图层. 你想继续吗?",true)
|
||||
if (answer === false){
|
||||
newDoc.close(SaveOptions.DONOTSAVECHANGES);
|
||||
activeDocument.quickMaskMode = false;
|
||||
activeDocument.selection.deselect();
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =======================================================
|
||||
activeDocument.resizeImage("50%", "50%", undefined, ResampleMethod.NEARESTNEIGHBOR)
|
||||
|
||||
var pathInfo = collectPathInfoFromDesc(activeDocument, activeDocument.pathItems[activeDocument.pathItems.length - 1])
|
||||
|
||||
// =======================================================
|
||||
newDoc.close(SaveOptions.DONOTSAVECHANGES)
|
||||
|
||||
// =======================================================
|
||||
activeDocument.quickMaskMode = false
|
||||
|
||||
// =======================================================
|
||||
//make channel
|
||||
// =======================================================
|
||||
var idMk = charIDToTypeID("Mk ");
|
||||
var desc6 = new ActionDescriptor();
|
||||
var idNw = charIDToTypeID("Nw ");
|
||||
var desc7 = new ActionDescriptor();
|
||||
var idNm = charIDToTypeID("Nm ");
|
||||
desc7.putString(idNm, "ContiguityMask");
|
||||
var idClrI = charIDToTypeID("ClrI");
|
||||
var idMskI = charIDToTypeID("MskI");
|
||||
var idMskA = charIDToTypeID("MskA");
|
||||
desc7.putEnumerated(idClrI, idMskI, idMskA);
|
||||
var idClr = charIDToTypeID("Clr ");
|
||||
var desc8 = new ActionDescriptor();
|
||||
var idRd = charIDToTypeID("Rd ");
|
||||
desc8.putDouble(idRd, 255.000000);
|
||||
var idGrn = charIDToTypeID("Grn ");
|
||||
desc8.putDouble(idGrn, 0.000000);
|
||||
var idBl = charIDToTypeID("Bl ");
|
||||
desc8.putDouble(idBl, 0.000000);
|
||||
var idRGBC = charIDToTypeID("RGBC");
|
||||
desc7.putObject(idClr, idRGBC, desc8);
|
||||
var idOpct = charIDToTypeID("Opct");
|
||||
desc7.putInteger(idOpct, 50);
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
desc6.putObject(idNw, idChnl, desc7);
|
||||
var idUsng = charIDToTypeID("Usng");
|
||||
var ref5 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref5.putProperty(idChnl, idfsel);
|
||||
desc6.putReference(idUsng, ref5);
|
||||
executeAction(idMk, desc6, DialogModes.NO);
|
||||
|
||||
|
||||
var layerCount = 1
|
||||
for (i = 0; i < subPathsLength; i++) {
|
||||
//deselect
|
||||
var idsetd = charIDToTypeID("setd");
|
||||
var desc279 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref137 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref137.putProperty(idChnl, idfsel);
|
||||
desc279.putReference(idnull, ref137);
|
||||
var idT = charIDToTypeID("T ");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idNone = charIDToTypeID("None");
|
||||
desc279.putEnumerated(idT, idOrdn, idNone);
|
||||
executeAction(idsetd, desc279, DialogModes.NO);
|
||||
///select alpha channel
|
||||
var idslct = charIDToTypeID("slct");
|
||||
var desc315 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref175 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
ref175.putName(idChnl, "ContiguityMask");
|
||||
desc315.putReference(idnull, ref175);
|
||||
executeAction(idslct, desc315, DialogModes.NO);
|
||||
//use magic wand
|
||||
var idsetd = charIDToTypeID("setd");
|
||||
var desc263 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref123 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref123.putProperty(idChnl, idfsel);
|
||||
desc263.putReference(idnull, ref123);
|
||||
var idT = charIDToTypeID("T ");
|
||||
var desc264 = new ActionDescriptor();
|
||||
var idHrzn = charIDToTypeID("Hrzn");
|
||||
var idRlt = charIDToTypeID("#Rlt");
|
||||
desc264.putUnitDouble(idHrzn, idRlt, pathInfo[i][0][0]);
|
||||
var idVrtc = charIDToTypeID("Vrtc");
|
||||
var idRlt = charIDToTypeID("#Rlt");
|
||||
|
||||
desc264.putUnitDouble(idVrtc, idRlt, pathInfo[i][0][1]);
|
||||
var idPnt = charIDToTypeID("Pnt ");
|
||||
desc263.putObject(idT, idPnt, desc264);
|
||||
var idTlrn = charIDToTypeID("Tlrn");
|
||||
desc263.putInteger(idTlrn, 1);
|
||||
executeAction(idsetd, desc263, DialogModes.NO);
|
||||
|
||||
var idslct = charIDToTypeID("slct");
|
||||
var desc346 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref205 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idRGB = charIDToTypeID("RGB ");
|
||||
ref205.putEnumerated(idChnl, idChnl, idRGB);
|
||||
desc346.putReference(idnull, ref205);
|
||||
var idMkVs = charIDToTypeID("MkVs");
|
||||
desc346.putBoolean(idMkVs, false);
|
||||
executeAction(idslct, desc346, DialogModes.NO);
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
// =======================================================
|
||||
var idCpTL = charIDToTypeID("CpTL");
|
||||
executeAction(idCpTL, undefined, DialogModes.NO);
|
||||
|
||||
try {
|
||||
var idrasterizeLayer = stringIDToTypeID("rasterizeLayer");
|
||||
var desc924 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref721 = new ActionReference();
|
||||
var idLyr = charIDToTypeID("Lyr ");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref721.putEnumerated(idLyr, idOrdn, idTrgt);
|
||||
desc924.putReference(idnull, ref721);
|
||||
var idWhat = charIDToTypeID("What");
|
||||
var idrasterizeItem = stringIDToTypeID("rasterizeItem");
|
||||
var idvectorMask = stringIDToTypeID("vectorMask");
|
||||
desc924.putEnumerated(idWhat, idrasterizeItem, idvectorMask);
|
||||
executeAction(idrasterizeLayer, desc924, DialogModes.NO);
|
||||
} catch (err) {}
|
||||
|
||||
try {
|
||||
var idIntr = charIDToTypeID("Intr");
|
||||
var desc864 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref658 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref658.putEnumerated(idChnl, idOrdn, idTrgt);
|
||||
desc864.putReference(idnull, ref658);
|
||||
var idWith = charIDToTypeID("With");
|
||||
var ref659 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref659.putProperty(idChnl, idfsel);
|
||||
desc864.putReference(idWith, ref659);
|
||||
executeAction(idIntr, desc864, DialogModes.NO);
|
||||
|
||||
// =======================================================
|
||||
var idDlt = charIDToTypeID("Dlt ");
|
||||
var desc865 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref660 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref660.putEnumerated(idChnl, idOrdn, idTrgt);
|
||||
desc865.putReference(idnull, ref660);
|
||||
executeAction(idDlt, desc865, DialogModes.NO);
|
||||
|
||||
// =======================================================
|
||||
var idMk = charIDToTypeID("Mk ");
|
||||
var desc866 = new ActionDescriptor();
|
||||
var idNw = charIDToTypeID("Nw ");
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
desc866.putClass(idNw, idChnl);
|
||||
var idAt = charIDToTypeID("At ");
|
||||
var ref661 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idMsk = charIDToTypeID("Msk ");
|
||||
ref661.putEnumerated(idChnl, idChnl, idMsk);
|
||||
desc866.putReference(idAt, ref661);
|
||||
var idUsng = charIDToTypeID("Usng");
|
||||
var idUsrM = charIDToTypeID("UsrM");
|
||||
var idRvlS = charIDToTypeID("RvlS");
|
||||
desc866.putEnumerated(idUsng, idUsrM, idRvlS);
|
||||
executeAction(idMk, desc866, DialogModes.NO);
|
||||
|
||||
} catch (err) {}
|
||||
|
||||
var finalSuffix=suffix;
|
||||
if (addCount===true)finalSuffix += layerCount;
|
||||
|
||||
|
||||
activeDocument.activeLayer.name = layerName + finalSuffix;
|
||||
layerCount++;
|
||||
|
||||
|
||||
activeDocument.activeLayer=baseLayer;
|
||||
} catch (e) {}
|
||||
}
|
||||
var idsetd = charIDToTypeID("setd");
|
||||
var desc1045 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref578 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref578.putProperty(idChnl, idfsel);
|
||||
desc1045.putReference(idnull, ref578);
|
||||
var idT = charIDToTypeID("T ");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idNone = charIDToTypeID("None");
|
||||
desc1045.putEnumerated(idT, idOrdn, idNone);
|
||||
executeAction(idsetd, desc1045, DialogModes.NO);
|
||||
|
||||
// =======================================================
|
||||
var idDlt = charIDToTypeID("Dlt ");
|
||||
var desc694 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref323 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
ref323.putName(idChnl, "ContiguityMask");
|
||||
desc694.putReference(idnull, ref323);
|
||||
executeAction(idDlt, desc694, DialogModes.NO);
|
||||
|
||||
|
||||
activeDocument.activeLayer.remove();
|
||||
|
||||
|
||||
|
||||
var idHd = charIDToTypeID("Hd ");
|
||||
var desc736 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var list22 = new ActionList();
|
||||
var ref541 = new ActionReference();
|
||||
var idLyr = charIDToTypeID("Lyr ");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref541.putEnumerated(idLyr, idOrdn, idTrgt);
|
||||
list22.putReference(ref541);
|
||||
desc736.putList(idnull, list22);
|
||||
executeAction(idHd, desc736, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
// pfaffenbichler and xbytor //
|
||||
// at ps-scripts.com //
|
||||
// created this function //
|
||||
function collectPathInfoFromDesc(myDocument, thePath) {
|
||||
var myDocument = app.activeDocument;
|
||||
|
||||
// based of functions from xbytor’s stdlib;
|
||||
var ref = new ActionReference();
|
||||
for (var l = 0; l < myDocument.pathItems.length; l++) {
|
||||
var thisPath = myDocument.pathItems[l];
|
||||
if (thisPath == thePath && thisPath.name == "Work Path") {
|
||||
ref.putProperty(cTID("Path"), cTID("WrPt"));
|
||||
};
|
||||
if (thisPath == thePath && thisPath.name != "Work Path" && thisPath.kind != PathKind.VECTORMASK) {
|
||||
ref.putIndex(cTID("Path"), l + 1);
|
||||
};
|
||||
if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {
|
||||
var idPath = charIDToTypeID("Path");
|
||||
var idPath = charIDToTypeID("Path");
|
||||
var idvectorMask = stringIDToTypeID("vectorMask");
|
||||
ref.putEnumerated(idPath, idPath, idvectorMask);
|
||||
};
|
||||
};
|
||||
var desc = app.executeActionGet(ref);
|
||||
var pname = desc.getString(cTID('PthN'));
|
||||
// create new array;
|
||||
var theArray = new Array;
|
||||
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
|
||||
// for subpathitems;
|
||||
for (var m = 0; m < pathComponents.count; m++) {
|
||||
var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
|
||||
// for subpathitem’s count;
|
||||
for (var n = 0; n < listKey.count; n++) {
|
||||
var points = listKey.getObjectValue(n).getList(sTID('points'));
|
||||
// get first point;
|
||||
var anchorObj = points.getObjectValue(0).getObjectValue(sTID("anchor"));
|
||||
var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
|
||||
var thisPoint = [anchor];
|
||||
theArray.push(thisPoint);
|
||||
};
|
||||
};
|
||||
// by xbytor, thanks to him;
|
||||
|
||||
|
||||
function cTID(s) {
|
||||
return cTID[s] || cTID[s] = app.charIDToTypeID(s);
|
||||
};
|
||||
|
||||
function sTID(s) {
|
||||
return sTID[s] || sTID[s] = app.stringIDToTypeID(s);
|
||||
};
|
||||
// reset;
|
||||
return theArray;
|
||||
};
|
||||
|
||||
|
||||
function makePreviewSelection(){
|
||||
makeSelection()
|
||||
app.refresh()
|
||||
activeDocument.quickMaskMode = false;
|
||||
}
|
||||
|
||||
function makeSelection(){
|
||||
try{
|
||||
|
||||
var idsetd = charIDToTypeID("setd");
|
||||
var desc922 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref529 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref529.putProperty(idChnl, idfsel);
|
||||
desc922.putReference(idnull, ref529);
|
||||
var idT = charIDToTypeID("T ");
|
||||
var ref530 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idTrsp = charIDToTypeID("Trsp");
|
||||
ref530.putEnumerated(idChnl, idChnl, idTrsp);
|
||||
desc922.putReference(idT, ref530);
|
||||
executeAction(idsetd, desc922, DialogModes.NO);
|
||||
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
var idIntr = charIDToTypeID("Intr");
|
||||
var desc846 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref639 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idMsk = charIDToTypeID("Msk ");
|
||||
ref639.putEnumerated(idChnl, idChnl, idMsk);
|
||||
desc846.putReference(idnull, ref639);
|
||||
var idWith = charIDToTypeID("With");
|
||||
var ref640 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref640.putProperty(idChnl, idfsel);
|
||||
desc846.putReference(idWith, ref640);
|
||||
executeAction(idIntr, desc846, DialogModes.NO);
|
||||
|
||||
|
||||
} catch (err) {}
|
||||
|
||||
try {
|
||||
// =======================================================
|
||||
var idIntW = charIDToTypeID("IntW");
|
||||
var desc787 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID("null");
|
||||
var ref572 = new ActionReference();
|
||||
var idChnl = charIDToTypeID("Chnl");
|
||||
var idfsel = charIDToTypeID("fsel");
|
||||
ref572.putProperty(idChnl, idfsel);
|
||||
desc787.putReference(idnull, ref572);
|
||||
var idT = charIDToTypeID("T ");
|
||||
var ref573 = new ActionReference();
|
||||
var idPath = charIDToTypeID("Path");
|
||||
var idPath = charIDToTypeID("Path");
|
||||
var idvectorMask = stringIDToTypeID("vectorMask");
|
||||
ref573.putEnumerated(idPath, idPath, idvectorMask);
|
||||
var idLyr = charIDToTypeID("Lyr ");
|
||||
var idOrdn = charIDToTypeID("Ordn");
|
||||
var idTrgt = charIDToTypeID("Trgt");
|
||||
ref573.putEnumerated(idLyr, idOrdn, idTrgt);
|
||||
desc787.putReference(idT, ref573);
|
||||
var idVrsn = charIDToTypeID("Vrsn");
|
||||
desc787.putInteger(idVrsn, 1);
|
||||
var idvectorMaskParams = stringIDToTypeID("vectorMaskParams");
|
||||
desc787.putBoolean(idvectorMaskParams, true);
|
||||
executeAction(idIntW, desc787, DialogModes.NO);
|
||||
} catch (err) {}
|
||||
|
||||
|
||||
|
||||
if (tolerance >= 2) {
|
||||
|
||||
activeDocument.selection.expand(Math.floor(tolerance / 2))
|
||||
|
||||
}
|
||||
|
||||
|
||||
activeDocument.quickMaskMode = true;
|
||||
|
||||
|
||||
var idThrs = charIDToTypeID("Thrs");
|
||||
var desc479 = new ActionDescriptor();
|
||||
var idLvl = charIDToTypeID("Lvl ");
|
||||
desc479.putInteger(idLvl, 1);
|
||||
executeAction(idThrs, desc479, DialogModes.NO);
|
||||
|
||||
|
||||
|
||||
if (tolerance % 2 == 1) {
|
||||
|
||||
var idMtnB = charIDToTypeID("MtnB");
|
||||
var desc213 = new ActionDescriptor();
|
||||
var idAngl = charIDToTypeID("Angl");
|
||||
desc213.putInteger(idAngl, 0);
|
||||
var idDstn = charIDToTypeID("Dstn");
|
||||
var idPxl = charIDToTypeID("#Pxl");
|
||||
desc213.putUnitDouble(idDstn, idPxl, 1.000000);
|
||||
executeAction(idMtnB, desc213, DialogModes.NO);
|
||||
|
||||
// =======================================================
|
||||
var idMtnB = charIDToTypeID("MtnB");
|
||||
var desc214 = new ActionDescriptor();
|
||||
var idAngl = charIDToTypeID("Angl");
|
||||
desc214.putInteger(idAngl, 90);
|
||||
var idDstn = charIDToTypeID("Dstn");
|
||||
var idPxl = charIDToTypeID("#Pxl");
|
||||
desc214.putUnitDouble(idDstn, idPxl, 1.000000);
|
||||
executeAction(idMtnB, desc214, DialogModes.NO);
|
||||
|
||||
|
||||
// =======================================================
|
||||
var idThrs = charIDToTypeID("Thrs");
|
||||
var desc215 = new ActionDescriptor();
|
||||
var idLvl = charIDToTypeID("Lvl ");
|
||||
desc215.putInteger(idLvl, 1);
|
||||
executeAction(idThrs, desc215, DialogModes.NO);
|
||||
}
|
||||
}
|
||||
|
||||
function createDialog(){
|
||||
|
||||
var dlg = new Window('dialog', 'PNG素材拆分图层');
|
||||
dlg.alignChildren ='left';
|
||||
|
||||
dlg.gap = dlg.add('group')
|
||||
dlg.gap.orientation= 'row';
|
||||
dlg.gap.txt=dlg.gap.add('statictext', undefined,'间隙大于多少时拆分?');
|
||||
dlg.gap.input=dlg.gap.add('edittext', undefined,tolerance);
|
||||
dlg.gap.input.preferredSize = [20,20];
|
||||
dlg.gap.txt2=dlg.gap.add('statictext', undefined,'像素');
|
||||
dlg.gap.btnPreview= dlg.gap.add('button', undefined,'蒙版预览');
|
||||
dlg.gap.btnPreview.preferredSize = [55,20]
|
||||
|
||||
dlg.naming = dlg.add('panel',undefined,'图层重命名')
|
||||
dlg.naming.alignChildren ='left';
|
||||
dlg.naming.suffix = dlg.naming.add('group')
|
||||
dlg.naming.suffix.orientation= 'row';
|
||||
dlg.naming.suffix.txt=dlg.naming.suffix.add('statictext', undefined,'后缀:');
|
||||
dlg.naming.suffix.input=dlg.naming.suffix.add('edittext', undefined,suffix);
|
||||
dlg.naming.suffix.input.preferredSize = [60,20];
|
||||
|
||||
dlg.naming.suffix.chkbox = dlg.naming.suffix.add('checkbox', undefined, '添加序号')
|
||||
dlg.naming.suffix.chkbox.value=addCount;
|
||||
|
||||
dlg.naming.txtPreview = dlg.naming.add('statictext', undefined, layerNamePreview)
|
||||
dlg.naming.txtPreview.preferredSize = [200,20];
|
||||
|
||||
dlg.btnPnl= dlg.add('group');
|
||||
dlg.btnPnl.alignment ='right';
|
||||
dlg.btnPnl.okBtn = dlg.btnPnl.add('button', undefined, '确定', {name:'ok'});
|
||||
dlg.btnPnl.okBtn.active=true;
|
||||
dlg.btnPnl.cancelBtn = dlg.btnPnl.add('button', undefined, '取消', {name:'cancel'});
|
||||
|
||||
dlg.naming.suffix.input.onChanging= function(){
|
||||
layerNamePreview=activeDocument.activeLayer.name + dlg.naming.suffix.input.text
|
||||
if (dlg.naming.suffix.chkbox.value === true){
|
||||
layerNamePreview += "1"
|
||||
}
|
||||
dlg.naming.txtPreview.text =layerNamePreview
|
||||
}
|
||||
dlg.naming.suffix.chkbox.onClick = function(){
|
||||
layerNamePreview=activeDocument.activeLayer.name + dlg.naming.suffix.input.text
|
||||
if (dlg.naming.suffix.chkbox.value === true){
|
||||
layerNamePreview += "1"
|
||||
}
|
||||
dlg.naming.txtPreview.text = layerNamePreview;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
dlg.gap.input.onChanging = function() {
|
||||
if (parseInt(dlg.gap.input.text) == 1){
|
||||
dlg.gap.txt2.text = '像素'
|
||||
}else{
|
||||
dlg.gap.txt2.text = '像素'
|
||||
}
|
||||
tolerance = parseInt (dlg.gap.input.text)
|
||||
}
|
||||
|
||||
dlg.gap.btnPreview.onClick = function() {
|
||||
makePreviewSelection()
|
||||
}
|
||||
|
||||
x=dlg.show();
|
||||
|
||||
tolerance = parseInt (dlg.gap.input.text)
|
||||
suffix = dlg.naming.suffix.input.text
|
||||
addCount=dlg.naming.suffix.chkbox.value
|
||||
|
||||
return x;
|
||||
}
|
||||
453
PSMARK代码块/PS智能对象换图ver1.2-UI(1).jsx
Normal file
453
PSMARK代码块/PS智能对象换图ver1.2-UI(1).jsx
Normal file
@@ -0,0 +1,453 @@
|
||||
|
||||
//PS智能对象换图
|
||||
|
||||
function 模特换衣功能(){
|
||||
|
||||
|
||||
var dialog = new Window("dialog");
|
||||
dialog.text = "模特批量替换";
|
||||
dialog.preferredSize.width = 400;
|
||||
dialog.preferredSize.height = 150;
|
||||
dialog.orientation = "column";
|
||||
dialog.alignChildren = ["center","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group");
|
||||
group1.orientation = "row";
|
||||
group1.alignChildren = ["left","center"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
var statictext1 = group1.add("statictext");
|
||||
statictext1.text = "模板文件";
|
||||
statictext1.justify = "center";
|
||||
|
||||
var edittext1 = group1.add("edittext");
|
||||
edittext1.preferredSize.width = 250;
|
||||
|
||||
var button1 = group1.add("button");
|
||||
button1.text = "选择文件";
|
||||
button1.justify = "center";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = dialog.add("group");
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var statictext2 = group2.add("statictext");
|
||||
statictext2.text = "素材目录";
|
||||
statictext2.justify = "center";
|
||||
|
||||
var edittext2 = group2.add("edittext");
|
||||
edittext2.preferredSize.width = 250;
|
||||
|
||||
var button2 = group2.add("button");
|
||||
button2.text = "选择目录";
|
||||
button2.justify = "center";
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = dialog.add("group");
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext3 = group3.add("statictext");
|
||||
statictext3.text = "导出目录";
|
||||
statictext3.justify = "center";
|
||||
|
||||
var edittext3 = group3.add("edittext");
|
||||
edittext3.preferredSize.width = 250;
|
||||
|
||||
var button3 = group3.add("button");
|
||||
button3.text = "选择目录";
|
||||
button3.justify = "center";
|
||||
|
||||
|
||||
var group5 = dialog.add("group");
|
||||
var cbox1 = group5.add("checkbox");
|
||||
cbox1.text = "是否遍历子文件夹素材";
|
||||
cbox1.value = true;
|
||||
|
||||
var cbox2 = group5.add("checkbox");
|
||||
cbox2.text = "是否保存文件结构";
|
||||
cbox2.value = true;
|
||||
|
||||
var cbox3 = group5.add("checkbox");
|
||||
cbox3.text = "切片导出";
|
||||
cbox3.value = false;
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = dialog.add("group");
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
var button4 = group4.add("button");
|
||||
button4.text = "执行";
|
||||
button4.justify = "center";
|
||||
|
||||
var button5 = group4.add("button");
|
||||
button5.text = "退出";
|
||||
button5.justify = "center";
|
||||
|
||||
|
||||
|
||||
//~ sPath = decodeURI(File($.fileName).path);
|
||||
//~ edittext1.text = sPath + "/模板/笨鸟跨境 圣诞袜模板 单边 加大-38.psd";
|
||||
//~ edittext2.text = sPath + "/替换图片子文件夹";
|
||||
//~ edittext3.text = sPath + "/导出目录";
|
||||
|
||||
|
||||
|
||||
button1.onClick = function()
|
||||
{
|
||||
|
||||
var inputFile= app.openDialog();
|
||||
if (inputFile != null)
|
||||
{
|
||||
edittext1.text = decodeURI(inputFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
button2.onClick = function()
|
||||
{
|
||||
|
||||
var inputFolder = Folder.selectDialog("请选择素材目录:");
|
||||
if (inputFolder != null)
|
||||
{
|
||||
edittext2.text = decodeURI(inputFolder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
button3.onClick = function()
|
||||
{
|
||||
|
||||
var inputFolder = Folder.selectDialog("请选择导出目录:");
|
||||
if (inputFolder != null)
|
||||
{
|
||||
edittext3.text = decodeURI(inputFolder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
button4.onClick = function()
|
||||
{
|
||||
模板路径 = edittext1.text;
|
||||
素材目录 = edittext2.text;
|
||||
导出目录 = edittext3.text;
|
||||
main(模板路径,素材目录,导出目录);
|
||||
}
|
||||
|
||||
button5.onClick = function()
|
||||
{
|
||||
|
||||
dialog.close();
|
||||
}
|
||||
|
||||
|
||||
function main(模板路径,素材目录,导出目录)
|
||||
{
|
||||
|
||||
|
||||
if(Folder(导出目录).exists==false){Folder(导出目录).create();}
|
||||
|
||||
var doc = app.open(File(模板路径));
|
||||
//~ 素材文件列表 = Folder(素材目录).getFiles("*.psd");
|
||||
|
||||
isSubFolders = cbox1.value;
|
||||
素材文件列表 = 遍历目录指定类型文件(素材目录,isSubFolders);
|
||||
|
||||
|
||||
alert("当前目录一共有"+素材文件列表.length+"个素材。","提示:");
|
||||
|
||||
try
|
||||
{
|
||||
lay_替换对象图层名 = "替换对象";
|
||||
lay_替换对象 = app.activeDocument.artLayers.getByName(lay_替换对象图层名);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
alert("未找到["+lay_替换对象图层名+"]智能对象图层!","提示:");
|
||||
}
|
||||
|
||||
app.activeDocument.activeLayer = lay_替换对象;
|
||||
|
||||
for(var i=0;i<素材文件列表.length;i++)
|
||||
{
|
||||
scpsd_path = 素材文件列表[i];
|
||||
//~ lay_替换对象.visible = false;
|
||||
|
||||
素材名 = decodeURI(File(scpsd_path).name.replace(/(?:\.[^.]*$|$)/, ''));
|
||||
|
||||
//替换内容
|
||||
var d = new ActionDescriptor();
|
||||
d.putPath(stringIDToTypeID("null"), new File(scpsd_path));
|
||||
executeAction(stringIDToTypeID("placedLayerReplaceContents"), d, DialogModes.NO);
|
||||
|
||||
if(cbox2.value) //保持结构
|
||||
{
|
||||
结构导出目录 = 导出目录+"\\" + getRelativePath(decodeURI(File(scpsd_path).path), 素材目录);
|
||||
|
||||
if(Folder(结构导出目录).exists==false){Folder(结构导出目录).create();}
|
||||
|
||||
保存路径 = 结构导出目录+"\\"+素材名+".jpg";
|
||||
$.writeln(保存路径);
|
||||
|
||||
if(cbox3.value) //按切片
|
||||
{
|
||||
//~ 按切片导出图片(结构导出目录,app.activeDocument.name.replace(/(?:\.[^.]*$|$)/, ''));
|
||||
按切片导出图片(结构导出目录,素材名);
|
||||
}
|
||||
else
|
||||
{
|
||||
保存JPG(保存路径);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cbox3.value) //按切片
|
||||
{
|
||||
//~ 按切片导出图片(导出目录,app.activeDocument.name.replace(/(?:\.[^.]*$|$)/, ''));
|
||||
按切片导出图片(导出目录,素材名);
|
||||
}
|
||||
else
|
||||
{
|
||||
保存JPG(导出目录+"\\"+素材名+".jpg");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
doc.close(SaveOptions.DONOTSAVECHANGES);
|
||||
alert("处理完成!","提示:");
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getRelativePath(targetPath, basePath)
|
||||
{
|
||||
var targetFile = new File(targetPath);
|
||||
var baseFolder = new Folder(basePath);
|
||||
|
||||
var relativePath = targetFile.getRelativeURI(baseFolder);
|
||||
|
||||
return decodeURI(relativePath); // 解码 URI 编码的路径
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 保存JPG(jpg_save_path)
|
||||
{
|
||||
// 以JPEG格式保存输出
|
||||
var jpegOptions = new JPEGSaveOptions();
|
||||
// 将jpeg质量设置得很低,使文件很小
|
||||
jpegOptions.quality = 12;
|
||||
|
||||
app.activeDocument.saveAs(new File(jpg_save_path), jpegOptions,true);
|
||||
}
|
||||
|
||||
|
||||
function 遍历目录指定类型文件(inputFolder,isSubFolders)
|
||||
{
|
||||
if(isSubFolders==undefined)
|
||||
{
|
||||
isSubFolders = true;
|
||||
}
|
||||
|
||||
all_files_list = [];
|
||||
if (inputFolder != null) {
|
||||
|
||||
filesArray = scanFolder(inputFolder);
|
||||
|
||||
if (filesArray.length > 0)
|
||||
{
|
||||
for (i = 0;i<filesArray.length;i++)
|
||||
{
|
||||
all_files_list.push(filesArray[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return all_files_list;
|
||||
|
||||
function scanFolder(folder)
|
||||
{
|
||||
|
||||
var filesArray = [],
|
||||
|
||||
fileList = Folder(folder).getFiles();
|
||||
var file;
|
||||
|
||||
|
||||
|
||||
for (var i = 0; i < fileList.length; i++) {
|
||||
|
||||
file = fileList[i];
|
||||
|
||||
if (file instanceof Folder)
|
||||
{
|
||||
if(isSubFolders==false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
filesArray = filesArray.concat(scanFolder(file));
|
||||
}
|
||||
|
||||
}
|
||||
else if (file instanceof File && file.name.match(/\.(jpg|tif|psd|png|)$/i))
|
||||
{
|
||||
|
||||
filesArray.push(file);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return filesArray;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 按切片导出图片(保存路径,替换词)
|
||||
{
|
||||
//~ alert(保存路径);
|
||||
var d = new ActionDescriptor();
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putEnumerated(charIDToTypeID("Op "), charIDToTypeID("SWOp"), charIDToTypeID("OpSa"));
|
||||
d1.putBoolean(charIDToTypeID("DIDr"), true);
|
||||
|
||||
d1.putPath(stringIDToTypeID("in"), new File(保存路径));
|
||||
|
||||
d1.putString(charIDToTypeID("ovFN"), 替换词+".jpg");
|
||||
|
||||
|
||||
d1.putEnumerated(stringIDToTypeID("format"), charIDToTypeID("IRFm"), stringIDToTypeID("JPEG"));
|
||||
d1.putBoolean(charIDToTypeID("Intr"), false);
|
||||
d1.putInteger(stringIDToTypeID("quality"), 80);
|
||||
d1.putInteger(charIDToTypeID("QChS"), 0);
|
||||
d1.putInteger(charIDToTypeID("QCUI"), 0);
|
||||
d1.putBoolean(charIDToTypeID("QChT"), false);
|
||||
d1.putBoolean(charIDToTypeID("QChV"), false);
|
||||
d1.putBoolean(stringIDToTypeID("optimized"), true);
|
||||
d1.putInteger(charIDToTypeID("Pass"), 1);
|
||||
d1.putDouble(stringIDToTypeID("blur"), 0);
|
||||
d1.putBoolean(charIDToTypeID("Mtt "), true);
|
||||
d1.putBoolean(charIDToTypeID("EICC"), false);
|
||||
d1.putInteger(charIDToTypeID("MttR"), 255);
|
||||
d1.putInteger(charIDToTypeID("MttG"), 255);
|
||||
d1.putInteger(charIDToTypeID("MttB"), 255);
|
||||
d1.putBoolean(charIDToTypeID("SHTM"), false);
|
||||
d1.putBoolean(charIDToTypeID("SImg"), true);
|
||||
d1.putEnumerated(charIDToTypeID("SWsl"), charIDToTypeID("STsl"), charIDToTypeID("SLAl"));
|
||||
d1.putEnumerated(charIDToTypeID("SWch"), charIDToTypeID("STch"), charIDToTypeID("CHDc"));
|
||||
d1.putEnumerated(charIDToTypeID("SWmd"), charIDToTypeID("STmd"), charIDToTypeID("MDCC"));
|
||||
d1.putBoolean(charIDToTypeID("ohXH"), false);
|
||||
d1.putBoolean(charIDToTypeID("ohIC"), true);
|
||||
d1.putBoolean(charIDToTypeID("ohAA"), true);
|
||||
d1.putBoolean(charIDToTypeID("ohQA"), true);
|
||||
d1.putBoolean(charIDToTypeID("ohCA"), false);
|
||||
d1.putBoolean(charIDToTypeID("ohIZ"), true);
|
||||
d1.putEnumerated(charIDToTypeID("ohTC"), charIDToTypeID("SToc"), charIDToTypeID("OC03"));
|
||||
d1.putEnumerated(charIDToTypeID("ohAC"), charIDToTypeID("SToc"), charIDToTypeID("OC03"));
|
||||
d1.putInteger(charIDToTypeID("ohIn"), -1);
|
||||
d1.putEnumerated(charIDToTypeID("ohLE"), charIDToTypeID("STle"), charIDToTypeID("LE03"));
|
||||
d1.putEnumerated(charIDToTypeID("ohEn"), charIDToTypeID("STen"), charIDToTypeID("EN00"));
|
||||
d1.putBoolean(charIDToTypeID("olCS"), false);
|
||||
d1.putEnumerated(charIDToTypeID("olEC"), charIDToTypeID("STst"), charIDToTypeID("ST00"));
|
||||
d1.putEnumerated(charIDToTypeID("olWH"), charIDToTypeID("STwh"), charIDToTypeID("WH01"));
|
||||
d1.putEnumerated(charIDToTypeID("olSV"), charIDToTypeID("STsp"), charIDToTypeID("SP04"));
|
||||
d1.putEnumerated(charIDToTypeID("olSH"), charIDToTypeID("STsp"), charIDToTypeID("SP04"));
|
||||
var list = new ActionList();
|
||||
var d2 = new ActionDescriptor();
|
||||
d2.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC00"));
|
||||
list.putObject(charIDToTypeID("SCnc"), d2);
|
||||
var d3 = new ActionDescriptor();
|
||||
d3.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC19"));
|
||||
list.putObject(charIDToTypeID("SCnc"), d3);
|
||||
var d4 = new ActionDescriptor();
|
||||
d4.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC28"));
|
||||
list.putObject(charIDToTypeID("SCnc"), d4);
|
||||
var d5 = new ActionDescriptor();
|
||||
d5.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC24"));
|
||||
list.putObject(charIDToTypeID("SCnc"), d5);
|
||||
var d6 = new ActionDescriptor();
|
||||
d6.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC24"));
|
||||
list.putObject(charIDToTypeID("SCnc"), d6);
|
||||
var d7 = new ActionDescriptor();
|
||||
d7.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC24"));
|
||||
list.putObject(charIDToTypeID("SCnc"), d7);
|
||||
d1.putList(charIDToTypeID("olNC"), list);
|
||||
d1.putBoolean(charIDToTypeID("obIA"), false);
|
||||
d1.putString(charIDToTypeID("obIP"), "");
|
||||
d1.putEnumerated(charIDToTypeID("obCS"), charIDToTypeID("STcs"), charIDToTypeID("CS01"));
|
||||
var list1 = new ActionList();
|
||||
var d8 = new ActionDescriptor();
|
||||
d8.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC01"));
|
||||
list1.putObject(charIDToTypeID("SCnc"), d8);
|
||||
var d9 = new ActionDescriptor();
|
||||
d9.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC20"));
|
||||
list1.putObject(charIDToTypeID("SCnc"), d9);
|
||||
var d10 = new ActionDescriptor();
|
||||
d10.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC02"));
|
||||
list1.putObject(charIDToTypeID("SCnc"), d10);
|
||||
var d11 = new ActionDescriptor();
|
||||
d11.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC19"));
|
||||
list1.putObject(charIDToTypeID("SCnc"), d11);
|
||||
var d12 = new ActionDescriptor();
|
||||
d12.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC06"));
|
||||
list1.putObject(charIDToTypeID("SCnc"), d12);
|
||||
var d13 = new ActionDescriptor();
|
||||
d13.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC24"));
|
||||
list1.putObject(charIDToTypeID("SCnc"), d13);
|
||||
var d14 = new ActionDescriptor();
|
||||
d14.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC24"));
|
||||
list1.putObject(charIDToTypeID("SCnc"), d14);
|
||||
var d15 = new ActionDescriptor();
|
||||
d15.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC24"));
|
||||
list1.putObject(charIDToTypeID("SCnc"), d15);
|
||||
var d16 = new ActionDescriptor();
|
||||
d16.putEnumerated(charIDToTypeID("ncTp"), charIDToTypeID("STnc"), charIDToTypeID("NC22"));
|
||||
list1.putObject(charIDToTypeID("SCnc"), d16);
|
||||
d1.putList(charIDToTypeID("ovNC"), list1);
|
||||
d1.putBoolean(charIDToTypeID("ovCM"), false);
|
||||
d1.putBoolean(charIDToTypeID("ovCW"), true);
|
||||
d1.putBoolean(charIDToTypeID("ovCU"), true);
|
||||
d1.putBoolean(charIDToTypeID("ovSF"), true);
|
||||
d1.putBoolean(charIDToTypeID("ovCB"), true);
|
||||
|
||||
|
||||
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("SaveForWeb"), d1);
|
||||
executeAction(stringIDToTypeID("export"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
340
PSMARK代码块/SO样打印拼贴加字.jsx
Normal file
340
PSMARK代码块/SO样打印拼贴加字.jsx
Normal file
@@ -0,0 +1,340 @@
|
||||
|
||||
|
||||
var dialog = new Window("dialog");
|
||||
dialog.text = "打印拼贴软件 使用前请看规则";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "S/O样自动连晒";
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "宽高设定(cm):";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = panel1.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var statictext2 = group2.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "宽度";
|
||||
|
||||
var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}');
|
||||
|
||||
edittext1.preferredSize.width = 60;
|
||||
|
||||
var statictext3 = group2.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "宽度";
|
||||
|
||||
var edittext2 = group2.add('edittext {properties: {name: "edittext2"}}');
|
||||
|
||||
edittext2.preferredSize.width = 60;
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = panel1.add("group", undefined, {name: "group3"});
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext4 = group3.add("statictext", undefined, undefined, {name: "statictext4"});
|
||||
statictext4.text = "字体属性:";
|
||||
|
||||
var dropdown1_array = ["文件名"];
|
||||
var dropdown1 = group3.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array});
|
||||
dropdown1.selection = 0;
|
||||
dropdown1.preferredSize.width = 100;
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = panel1.add("group", undefined, {name: "group4"});
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
var statictext5 = group4.add("statictext", undefined, undefined, {name: "statictext5"});
|
||||
statictext5.text = "字体方向:";
|
||||
|
||||
var dropdown2_array = ["以下对齐"];
|
||||
var dropdown2 = group4.add("dropdownlist", undefined, undefined, {name: "dropdown2", items: dropdown2_array});
|
||||
dropdown2.selection = 0;
|
||||
dropdown2.preferredSize.width = 100;
|
||||
|
||||
// GROUP5
|
||||
// ======
|
||||
var group5 = panel1.add("group", undefined, {name: "group5"});
|
||||
group5.orientation = "row";
|
||||
group5.alignChildren = ["left","center"];
|
||||
group5.spacing = 10;
|
||||
group5.margins = 0;
|
||||
|
||||
var statictext6 = group5.add("statictext", undefined, undefined, {name: "statictext6"});
|
||||
statictext6.text = "字体大小:";
|
||||
|
||||
var edittext3 = group5.add('edittext {properties: {name: "edittext3"}}');
|
||||
edittext3.text ="60"
|
||||
edittext3.preferredSize.width = 60;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
|
||||
var group6 = panel1.add("group", undefined, {name: "group6"});
|
||||
group6.orientation = "row";
|
||||
group6.alignChildren = ["left","center"];
|
||||
group6.spacing = 10;
|
||||
group6.margins = 0;
|
||||
|
||||
var statictext7 = group6.add("statictext", undefined, undefined, {name: "statictext7"});
|
||||
statictext7.text = "文件路径:";
|
||||
|
||||
var button1 = group6.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "输出文件夹目录";
|
||||
button1.preferredSize.width = 100;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var progressbar1 = group1.add("progressbar", undefined, undefined, {name: "progressbar1"});
|
||||
progressbar1.maxvalue = 100;
|
||||
progressbar1.value = 50;
|
||||
progressbar1.preferredSize.width = 50;
|
||||
progressbar1.preferredSize.height = 4;
|
||||
|
||||
// GROUP6
|
||||
// ======
|
||||
var group6 = dialog.add("group", undefined, {name: "group6"});
|
||||
group6.orientation = "column";
|
||||
group6.alignChildren = ["fill","top"];
|
||||
group6.spacing = 10;
|
||||
group6.margins = 0;
|
||||
|
||||
var ok = group6.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "执行";
|
||||
ok.alignment = ["center","top"];
|
||||
|
||||
var cancel = group6.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
cancel.alignment = ["fill","top"];
|
||||
|
||||
var button3 = group6.add("button", undefined, undefined, {name: "button3"});
|
||||
button3.text = "关于";
|
||||
button3.alignment = ["right","top"];
|
||||
|
||||
var button4 = group6.add("button", undefined, undefined, {name: "button4"});
|
||||
button4.text = "规则";
|
||||
button4.alignment = ["right","top"];
|
||||
|
||||
button1.onClick=function(){
|
||||
|
||||
button1.text =Folder.selectDialog ("输出文件夹目录").fsName;
|
||||
|
||||
}
|
||||
|
||||
|
||||
button3.onClick = function () {
|
||||
|
||||
alert("by jimi 2022.8.9 裁片自动排版软件18620223577",dialog.text+"----关于");
|
||||
}
|
||||
|
||||
button4.onClick = function () {
|
||||
|
||||
alert("须在D盘建立一个名为*输入*的文件夹",dialog.text+"----使用须知");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//处理函数
|
||||
ok .onClick=function(){
|
||||
|
||||
//~ //~ if (myEditText!="") {
|
||||
var myFolder=new Folder(button1.text)
|
||||
//打开文件夹中的每一个文件开始处理
|
||||
|
||||
var myFiles=myFolder.getFiles ("*.tif*")
|
||||
|
||||
|
||||
for(i=0 ;i< myFiles.length;i++){
|
||||
//开始处理每一个文件
|
||||
|
||||
//断判是文件格式
|
||||
if(myFiles[i] instanceof File)
|
||||
app.open(myFiles[i])
|
||||
|
||||
|
||||
var document =app.activeDocument
|
||||
//合并图层
|
||||
document.flatten()
|
||||
|
||||
|
||||
//预设图案
|
||||
|
||||
var 当前文档名称=activeDocument.name
|
||||
|
||||
|
||||
var idMk = charIDToTypeID( "Mk " );
|
||||
var desc14 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID( "null" );
|
||||
var ref3 = new ActionReference();
|
||||
var idPtrn = charIDToTypeID( "Ptrn" );
|
||||
ref3.putClass( idPtrn );
|
||||
desc14.putReference( idnull, ref3 );
|
||||
var idUsng = charIDToTypeID( "Usng" );
|
||||
var ref4 = new ActionReference();
|
||||
var idPrpr = charIDToTypeID( "Prpr" );
|
||||
var idfsel = charIDToTypeID( "fsel" );
|
||||
ref4.putProperty( idPrpr, idfsel );
|
||||
var idDcmn = charIDToTypeID( "Dcmn" );
|
||||
var idOrdn = charIDToTypeID( "Ordn" );
|
||||
var idTrgt = charIDToTypeID( "Trgt" );
|
||||
ref4.putEnumerated( idDcmn, idOrdn, idTrgt );
|
||||
desc14.putReference( idUsng, ref4 );
|
||||
var idNm = charIDToTypeID( "Nm " );
|
||||
desc14.putString( idNm, """当前文档名称""" );
|
||||
executeAction( idMk, desc14, DialogModes.NO );
|
||||
//
|
||||
|
||||
//重设宽高
|
||||
//记录宽高以调整宽高
|
||||
//-.../-.--/-.-./..-./..../-.--
|
||||
var sWidth=Number (edittext1.text); //宽;
|
||||
var sHeight=Number (edittext2.text); //宽;
|
||||
|
||||
var fontsz=Number (edittext3.text); //宽;
|
||||
//将图片裁切成指定宽高
|
||||
app.activeDocument.crop([UnitValue("0px"),UnitValue("0px"),UnitValue(sWidth,"cm"),UnitValue(sHeight,"cm")]);
|
||||
|
||||
|
||||
//填充当前文档图案
|
||||
var idMk = charIDToTypeID( "Mk " );
|
||||
var desc111 = new ActionDescriptor();
|
||||
var idnull = charIDToTypeID( "null" );
|
||||
var ref20 = new ActionReference();
|
||||
var idcontentLayer = stringIDToTypeID( "contentLayer" );
|
||||
ref20.putClass( idcontentLayer );
|
||||
desc111.putReference( idnull, ref20 );
|
||||
var idUsng = charIDToTypeID( "Usng" );
|
||||
var desc112 = new ActionDescriptor();
|
||||
var idType = charIDToTypeID( "Type" );
|
||||
var desc113 = new ActionDescriptor();
|
||||
var idPtrn = charIDToTypeID( "Ptrn" );
|
||||
var desc114 = new ActionDescriptor();
|
||||
var idNm = charIDToTypeID( "Nm " );
|
||||
desc114.putString( idNm, """当前文档名称""" );
|
||||
var idIdnt = charIDToTypeID( "Idnt" );
|
||||
desc114.putString( idIdnt, """当前文档名称""" );
|
||||
var idPtrn = charIDToTypeID( "Ptrn" );
|
||||
desc113.putObject( idPtrn, idPtrn, desc114 );
|
||||
var idpatternLayer = stringIDToTypeID( "patternLayer" );
|
||||
desc112.putObject( idType, idpatternLayer, desc113 );
|
||||
var idcontentLayer = stringIDToTypeID( "contentLayer" );
|
||||
desc111.putObject( idUsng, idcontentLayer, desc112 );
|
||||
executeAction( idMk, desc111, DialogModes.NO );
|
||||
|
||||
|
||||
|
||||
//记录字体大小并修改
|
||||
//r textsz= Number(dialog.group5.statictext6.edittext3.text); //宽;
|
||||
|
||||
//新建图层
|
||||
activeDocument.artLayers.add()
|
||||
//将新建图层变成文本图层
|
||||
activeDocument.activeLayer.kind=LayerKind.TEXT
|
||||
//将文本内容改为当前文档name
|
||||
activeDocument.activeLayer.textItem.contents=activeDocument.name
|
||||
//字体大小
|
||||
activeDocument.activeLayer.textItem.size= fontsz
|
||||
//文字字体
|
||||
activeDocument.activeLayer.textItem.font="微软雅黑"
|
||||
//文字层边界
|
||||
|
||||
|
||||
|
||||
x=activeDocument.width-activeDocument.activeLayer.bounds[2]
|
||||
//文字层边界
|
||||
y=activeDocument.activeLayer.bounds[1]
|
||||
//对齐
|
||||
|
||||
|
||||
|
||||
activeDocument.activeLayer.translate(x,-y)
|
||||
//偏移
|
||||
activeDocument.activeLayer.translate(UnitValue("-1cm"),UnitValue("+0.5cm"))
|
||||
|
||||
|
||||
//电白
|
||||
var myCopyLayer=activeDocument.activeLayer.duplicate (activeDocument.activeLayer,ElementPlacement.PLACEAFTER)
|
||||
|
||||
|
||||
|
||||
|
||||
myCopyLayer.rasterize(RasterizeType.ENTIRELAYER)
|
||||
|
||||
//T填充颜色参数
|
||||
var myColor=new SolidColor()
|
||||
myColor.rgb.red=255
|
||||
myColor.rgb.green=255
|
||||
myColor.rgb.blue=255
|
||||
|
||||
|
||||
activeDocument.activeLayer=myCopyLayer
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fillType=myColor
|
||||
|
||||
mode=ColorBlendMode.NORMAL
|
||||
oacity=100
|
||||
preserveTransparency=true
|
||||
|
||||
activeDocument.selection.fill(fillType,mode,oacity,preserveTransparency)
|
||||
|
||||
//白边
|
||||
activeDocument.activeLayer.applyMinimum(10)
|
||||
|
||||
|
||||
document.flatten()
|
||||
|
||||
|
||||
|
||||
//保存输出
|
||||
|
||||
//r CSyFolder=File(button2.text)
|
||||
|
||||
saveIn=File("d:/输入/"+activeDocument.name);
|
||||
tifSaveOpt = new TiffSaveOptions();
|
||||
tifSaveOpt.imageCompression = TIFFEncoding.TIFFLZW;
|
||||
tifSaveOpt.byteOrder = ByteOrder.IBM;
|
||||
asCopy=true
|
||||
app.activeDocument.saveAs(saveIn,tifSaveOpt,asCopy);
|
||||
|
||||
|
||||
|
||||
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
|
||||
}
|
||||
}
|
||||
dialog.show();
|
||||
|
||||
10
PSMARK代码块/ok的代码模块.jsx
Normal file
10
PSMARK代码块/ok的代码模块.jsx
Normal file
@@ -0,0 +1,10 @@
|
||||
function 执行动作(actionName, actionSetName) {
|
||||
try {
|
||||
app.doAction(actionName, actionSetName);
|
||||
} catch (e) {
|
||||
alert("动作调用出错: " + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 使用示例:
|
||||
执行动作("某个动作名称", "某个动作集名称");
|
||||
11
PSMARK代码块/位移.jsx
Normal file
11
PSMARK代码块/位移.jsx
Normal file
@@ -0,0 +1,11 @@
|
||||
function offset_47921752929688() //位移
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putInteger(stringIDToTypeID("horizontal"), 300);
|
||||
d.putInteger(stringIDToTypeID("vertical"), 300);
|
||||
d.putEnumerated(stringIDToTypeID("fill"), stringIDToTypeID("fillMode"), stringIDToTypeID("wrap"));
|
||||
executeAction(stringIDToTypeID("offset"), d, DialogModes.NO);
|
||||
|
||||
|
||||
}
|
||||
62
PSMARK代码块/保留历史记录.jsx
Normal file
62
PSMARK代码块/保留历史记录.jsx
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
function 历史记录保留() {
|
||||
|
||||
app.activeDocument.suspendHistory("历史记录保留", "历史记录保留()");
|
||||
}
|
||||
|
||||
function 历史记录保留() {
|
||||
|
||||
|
||||
主文档 = app.activeDocument;
|
||||
主文档名称 = 主文档.name;
|
||||
|
||||
// 遍历当前打开的文档
|
||||
for (var i = 0; i < app.documents.length; i++) {
|
||||
var document = app.documents[i];
|
||||
var documentName = document.name;
|
||||
|
||||
// 判断文档名称是否与主文档名称不相同
|
||||
if (documentName !== 主文档名称) {
|
||||
// 设置当前文档为活动文档
|
||||
app.activeDocument = document;
|
||||
取消选择()
|
||||
历史记录快照保留()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
app.activeDocument = 主文档
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 历史记录快照保留() //删除图层
|
||||
{
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("snapshotClass"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("historyState"), stringIDToTypeID("currentHistoryState"));
|
||||
d.putReference(stringIDToTypeID("from"), r1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 取消选择() //取消选择
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("to"), stringIDToTypeID("ordinal"), stringIDToTypeID("none"));
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
142
PSMARK代码块/关闭事件监听.jsx
Normal file
142
PSMARK代码块/关闭事件监听.jsx
Normal file
@@ -0,0 +1,142 @@
|
||||
|
||||
function 关闭事件监听(文件路径) {
|
||||
|
||||
try
|
||||
{
|
||||
arg_num = arguments.length;
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
arguments = []; //初始赋值为空
|
||||
}
|
||||
|
||||
eventName = "set";
|
||||
|
||||
//开启监听
|
||||
//enable_notifier(eventName,文件路径);
|
||||
//
|
||||
//取消监听
|
||||
disable_notifier(eventName,文件路径);
|
||||
|
||||
//这里进行监控调用事件
|
||||
if (arguments.length >= 2)
|
||||
{
|
||||
//alert(arguments.length);
|
||||
//~ alert(arguments[0],"动作参数1"); //动作描述符 AR
|
||||
//~ alert(arguments[1],"动作参数2"); //动作事件ID
|
||||
|
||||
|
||||
moveToGuideCenter();
|
||||
//main(arguments[0], arguments[1]);
|
||||
}
|
||||
|
||||
function moveToGuideCenter() {
|
||||
if (app.documents.length === 0 || !app.activeDocument.selection.bounds) {
|
||||
alert("没有打开的文档或没有有效的选区。");
|
||||
return;
|
||||
}
|
||||
|
||||
var doc = app.activeDocument;
|
||||
var guides = doc.guides;
|
||||
var xGuide = null;
|
||||
var yGuide = null;
|
||||
|
||||
// 找到 X 方向和 Y 方向上的参考线
|
||||
for (var i = 0; i < guides.length; i++) {
|
||||
var guide = guides[i];
|
||||
if (guide.direction === Direction.HORIZONTAL && yGuide === null) {
|
||||
yGuide = guide;
|
||||
} else if (guide.direction === Direction.VERTICAL && xGuide === null) {
|
||||
xGuide = guide;
|
||||
}
|
||||
}
|
||||
|
||||
if (xGuide === null || yGuide === null) {
|
||||
alert("必须确保存在一条水平和一条垂直参考线。");
|
||||
return;
|
||||
}
|
||||
|
||||
var intersectionX = xGuide.coordinate;
|
||||
var intersectionY = yGuide.coordinate;
|
||||
|
||||
var bounds = doc.selection.bounds;
|
||||
var xCenter = bounds[0] + (bounds[2] - bounds[0]) / 2;
|
||||
var yCenter = bounds[1] + (bounds[3] - bounds[1]) / 2;
|
||||
|
||||
var deltaX = intersectionX - xCenter;
|
||||
var deltaY = intersectionY - yCenter;
|
||||
|
||||
// 取消当前选区
|
||||
doc.selection.deselect();
|
||||
|
||||
// 移动选区图层
|
||||
var selectedLayer = doc.activeLayer;
|
||||
selectedLayer.translate(deltaX, deltaY);
|
||||
move_60275268554688()
|
||||
}
|
||||
|
||||
|
||||
|
||||
function move_60275268554688() // һ
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("previous"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("move"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function enable_notifier(event_name, script_name, event_class)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < app.notifiers.length; i++)
|
||||
{
|
||||
if (app.notifiers[i].event == event_name &&
|
||||
File(app.notifiers[i].eventFile).fsName.toLowerCase() == File(script_name).fsName.toLowerCase())
|
||||
{
|
||||
if (!app.notifiersEnabled) app.notifiersEnabled = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
app.notifiers.add(event_name, File(script_name), event_class);
|
||||
app.notifiersEnabled = true;
|
||||
return true;
|
||||
}
|
||||
catch (e) { _alert(e); return false; }
|
||||
}
|
||||
|
||||
|
||||
function disable_notifier(event_name, script_name, event_class)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ret = false;
|
||||
|
||||
for (var i = 0; i < app.notifiers.length; i++)
|
||||
{
|
||||
if (app.notifiers[i].event == event_name &&
|
||||
File(app.notifiers[i].eventFile).fsName.toLowerCase() == File(script_name).fsName.toLowerCase())
|
||||
{
|
||||
app.notifiers[i].remove();
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!app.notifiers.length) app.notifiersEnabled = false;
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch (e) { _alert(e); return false; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
37
PSMARK代码块/写入json文件.jsx
Normal file
37
PSMARK代码块/写入json文件.jsx
Normal file
@@ -0,0 +1,37 @@
|
||||
app.preferences.rulerUnits = Units.MM;
|
||||
var doc = app.activeDocument;
|
||||
var 扩展毫米数 = 80;
|
||||
|
||||
// 获取文档中的所有图层
|
||||
var allLayers = doc.layers;
|
||||
|
||||
// 创建一个数组来存储子图层的名称
|
||||
var 子图层名称数组 = [];
|
||||
|
||||
// 循环遍历所有图层
|
||||
for (var i = 0; i < allLayers.length; i++) {
|
||||
// 检查图层是否是图层组
|
||||
if (allLayers[i] instanceof LayerSet && allLayers[i].name === "填充底图") {
|
||||
// 获取图层组中的所有子图层
|
||||
var subLayers = allLayers[i].layers;
|
||||
|
||||
// 将子图层的名称添加到数组中,并在名称后面加上"-填充底图"
|
||||
for (var j = 0; j < subLayers.length; j++) {
|
||||
子图层名称数组.push('"' + subLayers[j].name + '-填充底图"');
|
||||
}
|
||||
|
||||
// 手动创建JSON格式的字符串
|
||||
var jsonStr = '[' + 子图层名称数组.join(', ') + ']';
|
||||
|
||||
// 创建一个文件对象指向桌面
|
||||
var desktop = Folder.desktop;
|
||||
var file = new File(desktop + "/子图层名称.json");
|
||||
|
||||
// 打开文件,写入JSON字符串,然后关闭文件
|
||||
file.open('w');
|
||||
file.write(jsonStr);
|
||||
file.close();
|
||||
|
||||
alert("子图层名称已保存到桌面的JSON文件中!");
|
||||
}
|
||||
}
|
||||
12
PSMARK代码块/切换主文档.jsx
Normal file
12
PSMARK代码块/切换主文档.jsx
Normal file
@@ -0,0 +1,12 @@
|
||||
function switchToDocument(docName) {
|
||||
var docs = app.documents;
|
||||
for (var i = 0; i < docs.length; i++) {
|
||||
if (docs[i].name == docName) {
|
||||
app.activeDocument = docs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 使用示例
|
||||
switchToDocument("xxx.psd");
|
||||
42
PSMARK代码块/删除图层.jsx
Normal file
42
PSMARK代码块/删除图层.jsx
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
function 删除图层3()
|
||||
{
|
||||
app.activeDocument.suspendHistory("delete layer", "删除图层2()");
|
||||
}
|
||||
|
||||
|
||||
function 删除图层2()
|
||||
{
|
||||
图层选择()
|
||||
删除图层()
|
||||
}
|
||||
function 图层选择() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("layer"), "图层 2");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(3);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
function 删除图层() //删除图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var list = new ActionList();
|
||||
list.putInteger(3);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("delete"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
31
PSMARK代码块/判断字体函数.jsx
Normal file
31
PSMARK代码块/判断字体函数.jsx
Normal file
@@ -0,0 +1,31 @@
|
||||
function 缩小字体图层至文档一半() {
|
||||
var 文档 = app.activeDocument;
|
||||
var 字体图层 = null;
|
||||
|
||||
// 遍历文档中的图层以找到名为"字体"的图层
|
||||
for (var i = 0; i < 文档.artLayers.length; i++) {
|
||||
if (文档.artLayers[i].name === "字体") {
|
||||
字体图层 = 文档.artLayers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (字体图层 !== null) {
|
||||
// 获取文档的宽度的一半
|
||||
var 目标宽度 = 文档.width / 2;
|
||||
|
||||
// 获取图层的当前宽度
|
||||
var 图层宽度 = 字体图层.bounds[2] - 字体图层.bounds[0];
|
||||
|
||||
// 计算缩放比例
|
||||
var 缩放比例 = 目标宽度 / 图层宽度 * 100;
|
||||
|
||||
// 缩放图层
|
||||
字体图层.resize(缩放比例, 缩放比例, AnchorPosition.MIDDLECENTER);
|
||||
} else {
|
||||
alert("未找到名为'字体'的图层");
|
||||
}
|
||||
}
|
||||
|
||||
// 调用函数
|
||||
缩小字体图层至文档一半();
|
||||
189
PSMARK代码块/加字函数.jsx
Normal file
189
PSMARK代码块/加字函数.jsx
Normal file
@@ -0,0 +1,189 @@
|
||||
创建并处理文本图层();
|
||||
|
||||
|
||||
function 创建并处理文本图层() {
|
||||
// 新建图层
|
||||
var textLayer = activeDocument.artLayers.add();
|
||||
|
||||
// 将新建图层变成文本图层
|
||||
textLayer.kind = LayerKind.TEXT;
|
||||
|
||||
// 将文本内容改为当前文档name
|
||||
textLayer.textItem.contents = activeDocument.name;
|
||||
|
||||
// 字体大小固定值
|
||||
var 固定字体大小 = 30; // 例如,30像素
|
||||
textLayer.textItem.size = 固定字体大小;
|
||||
|
||||
// 文字字体固定值
|
||||
textLayer.textItem.font = "微软雅黑";
|
||||
|
||||
// 计算并调整文本位置
|
||||
var x = activeDocument.width - textLayer.bounds[2];
|
||||
var y = textLayer.bounds[1];
|
||||
textLayer.translate(x, -y);
|
||||
|
||||
// 偏移
|
||||
textLayer.translate(UnitValue("-1cm"), UnitValue("+0.5cm"));
|
||||
|
||||
// 复制并栅格化图层
|
||||
var copyLayer = textLayer.duplicate();
|
||||
copyLayer.rasterize(RasterizeType.ENTIRELAYER);
|
||||
|
||||
// 设置固定颜色值
|
||||
var 固定颜色 = new SolidColor();
|
||||
固定颜色.rgb.red = 255; // 红色分量
|
||||
固定颜色.rgb.green = 255; // 绿色分量
|
||||
固定颜色.rgb.blue = 255; // 蓝色分量
|
||||
|
||||
activeDocument.activeLayer = copyLayer;
|
||||
activeDocument.selection.fill(固定颜色, ColorBlendMode.NORMAL, 100, true);
|
||||
|
||||
// 白边
|
||||
activeDocument.activeLayer.applyMinimum(10);
|
||||
后移一层()
|
||||
向上选择()
|
||||
向下合并()
|
||||
名称更改字体()
|
||||
缩小字体图层至文档一半()
|
||||
多选背景()
|
||||
底对齐()
|
||||
水平居中对齐()
|
||||
}
|
||||
|
||||
// 调用函数
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 后移一层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("previous"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("move"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 向上选择() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("forwardEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(19);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
function 向下合并() //向下合并
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 名称更改字体() //名称更改
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putString(stringIDToTypeID("name"), "字体");
|
||||
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("layer"), d1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 缩小字体图层至文档一半() {
|
||||
var 文档 = app.activeDocument;
|
||||
var 字体图层 = null;
|
||||
|
||||
// 遍历文档中的图层以找到名为"字体"的图层
|
||||
for (var i = 0; i < 文档.artLayers.length; i++) {
|
||||
if (文档.artLayers[i].name === "字体") {
|
||||
字体图层 = 文档.artLayers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (字体图层 !== null) {
|
||||
// 获取文档的宽度的一半
|
||||
var 目标宽度 = 文档.width / 2;
|
||||
|
||||
// 获取图层的当前宽度
|
||||
var 图层宽度 = 字体图层.bounds[2] - 字体图层.bounds[0];
|
||||
|
||||
// 计算缩放比例
|
||||
var 缩放比例 = 目标宽度 / 图层宽度 * 100;
|
||||
|
||||
// 缩放图层
|
||||
字体图层.resize(缩放比例, 缩放比例, AnchorPosition.MIDDLECENTER);
|
||||
} else {
|
||||
alert("未找到名为'字体'的图层");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function 多选背景() //自由变换
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("layer"), "背景");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(1);
|
||||
list.putInteger(13);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 底对齐() //底对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSBottoms"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 水平居中对齐() //水平居中对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSCentersH"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
124
PSMARK代码块/取消监听.jsx
Normal file
124
PSMARK代码块/取消监听.jsx
Normal file
@@ -0,0 +1,124 @@
|
||||
function 取消事件监听() {
|
||||
|
||||
try
|
||||
{
|
||||
arg_num = arguments.length;
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
arguments = []; //初始赋值为空
|
||||
}
|
||||
|
||||
eventName = "set";
|
||||
|
||||
//开启监听
|
||||
//enable_notifier(eventName, $.fileName);
|
||||
|
||||
//取消监听
|
||||
disable_notifier(eventName, $.fileName);
|
||||
|
||||
//这里进行监控调用事件
|
||||
if (arguments.length >= 2)
|
||||
{
|
||||
//alert(arguments.length);
|
||||
//~ alert(arguments[0],"动作参数1"); //动作描述符 AR
|
||||
//~ alert(arguments[1],"动作参数2"); //动作事件ID
|
||||
|
||||
//alert("事件名:"+typeIDToStringID(arguments[1])+"\n"+"事件ID:"+arguments[1],"提示:");
|
||||
moveToGuideCenter();
|
||||
//main(arguments[0], arguments[1]);
|
||||
}
|
||||
|
||||
function moveToGuideCenter() {
|
||||
if (app.documents.length === 0 || !app.activeDocument.selection.bounds) {
|
||||
alert("没有打开的文档或没有有效的选区。");
|
||||
return;
|
||||
}
|
||||
|
||||
var doc = app.activeDocument;
|
||||
var guides = doc.guides;
|
||||
var xGuide = null;
|
||||
var yGuide = null;
|
||||
|
||||
// 找到 X 方向和 Y 方向上的参考线
|
||||
for (var i = 0; i < guides.length; i++) {
|
||||
var guide = guides[i];
|
||||
if (guide.direction === Direction.HORIZONTAL && yGuide === null) {
|
||||
yGuide = guide;
|
||||
} else if (guide.direction === Direction.VERTICAL && xGuide === null) {
|
||||
xGuide = guide;
|
||||
}
|
||||
}
|
||||
|
||||
if (xGuide === null || yGuide === null) {
|
||||
alert("必须确保存在一条水平和一条垂直参考线。");
|
||||
return;
|
||||
}
|
||||
|
||||
var intersectionX = xGuide.coordinate;
|
||||
var intersectionY = yGuide.coordinate;
|
||||
|
||||
var bounds = doc.selection.bounds;
|
||||
var xCenter = bounds[0] + (bounds[2] - bounds[0]) / 2;
|
||||
var yCenter = bounds[1] + (bounds[3] - bounds[1]) / 2;
|
||||
|
||||
var deltaX = intersectionX - xCenter;
|
||||
var deltaY = intersectionY - yCenter;
|
||||
|
||||
// 取消当前选区
|
||||
doc.selection.deselect();
|
||||
|
||||
// 移动选区图层
|
||||
var selectedLayer = doc.activeLayer;
|
||||
selectedLayer.translate(deltaX, deltaY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function enable_notifier(event_name, script_name, event_class)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < app.notifiers.length; i++)
|
||||
{
|
||||
if (app.notifiers[i].event == event_name &&
|
||||
File(app.notifiers[i].eventFile).fsName.toLowerCase() == File(script_name).fsName.toLowerCase())
|
||||
{
|
||||
if (!app.notifiersEnabled) app.notifiersEnabled = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
app.notifiers.add(event_name, File(script_name), event_class);
|
||||
app.notifiersEnabled = true;
|
||||
return true;
|
||||
}
|
||||
catch (e) { _alert(e); return false; }
|
||||
}
|
||||
|
||||
|
||||
function disable_notifier(event_name, script_name, event_class)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ret = false;
|
||||
|
||||
for (var i = 0; i < app.notifiers.length; i++)
|
||||
{
|
||||
if (app.notifiers[i].event == event_name &&
|
||||
File(app.notifiers[i].eventFile).fsName.toLowerCase() == File(script_name).fsName.toLowerCase())
|
||||
{
|
||||
app.notifiers[i].remove();
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!app.notifiers.length) app.notifiersEnabled = false;
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch (e) { _alert(e); return false; }
|
||||
}
|
||||
}
|
||||
15
PSMARK代码块/图层选择.jsx
Normal file
15
PSMARK代码块/图层选择.jsx
Normal file
@@ -0,0 +1,15 @@
|
||||
function 图层选择(sizelayername)
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("layer"), sizelayername);
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(10);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
62
PSMARK代码块/图案填充.jsx
Normal file
62
PSMARK代码块/图案填充.jsx
Normal file
@@ -0,0 +1,62 @@
|
||||
var desktop = Folder.desktop;
|
||||
var file = new File(desktop + "/名称数据.json");
|
||||
if (file.open('r')) {
|
||||
var content = file.read();
|
||||
file.close();
|
||||
|
||||
// 移除双引号
|
||||
var content1 = content.replace(/"/g, '');
|
||||
|
||||
// 移除[]并使用逗号分割字符串
|
||||
var 名称数组 = content1.replace(/^\s*\[|\]\s*$/g, '').split(',');
|
||||
|
||||
for (var k = 0; k < 名称数组.length; k++) {
|
||||
var 名称 = 名称数组[k].replace(/^\s+|\s+$/g, ''); // 使用正则替代trim函数移除前后空格
|
||||
alert(名称);
|
||||
var matches = 名称.match(/\(([^)]+)\)/);
|
||||
if (matches) {
|
||||
var 图案名称 = matches[1];
|
||||
var 素材填充 = app.activeDocument.layerSets.getByName("填充底图").layers.getByName(图案名称);
|
||||
app.activeDocument.activeLayer = 素材填充;
|
||||
载入选区();
|
||||
填充图案(名称);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alert("找不到名称数据文件查看是否写入!");
|
||||
}
|
||||
|
||||
|
||||
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("channel"), stringIDToTypeID("transparencyEnum"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 填充图案(名称) //新建图案填充图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("contentLayer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
var d2 = new ActionDescriptor();
|
||||
var d3 = new ActionDescriptor();
|
||||
d3.putString(stringIDToTypeID("name"), 名称);
|
||||
|
||||
d2.putObject(stringIDToTypeID("pattern"), stringIDToTypeID("pattern"), d3);
|
||||
d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("patternLayer"), d2);
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("contentLayer"), d1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
24
PSMARK代码块/存储psd.jsx
Normal file
24
PSMARK代码块/存储psd.jsx
Normal file
@@ -0,0 +1,24 @@
|
||||
function saveAsPSD(saveFolder) {
|
||||
var doc = app.activeDocument; // 获取当前文档
|
||||
|
||||
if (doc == null) {
|
||||
alert("没有打开的文档!");
|
||||
return;
|
||||
}
|
||||
|
||||
var fileName = doc.name.replace(/\.[^\.]+$/, ''); // 移除文件扩展名
|
||||
var saveFile = File(saveFolder + "/" + fileName + ".psd"); // 创建保存路径
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putBoolean(stringIDToTypeID("maximizeCompatibility"), true);
|
||||
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("photoshop35Format"), d1);
|
||||
d.putPath(stringIDToTypeID("in"), new File(saveFile));
|
||||
d.putInteger(stringIDToTypeID("documentID"), 2027);
|
||||
d.putBoolean(stringIDToTypeID("lowerCase"), true);
|
||||
d.putEnumerated(stringIDToTypeID("saveStage"), stringIDToTypeID("saveStageType"), stringIDToTypeID("saveSucceeded"));
|
||||
executeAction(stringIDToTypeID("save"), d, DialogModes.NO);
|
||||
|
||||
|
||||
}
|
||||
|
||||
996
PSMARK代码块/定位码快速换图.jsx
Normal file
996
PSMARK代码块/定位码快速换图.jsx
Normal file
@@ -0,0 +1,996 @@
|
||||
function 定位码批量化替换外链新(){
|
||||
|
||||
var dialog = new Window("dialog");
|
||||
dialog.text = "定位码批量快速换图 ";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.preferredSize.width = 183;
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "文件夹选择";
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "大货齐码裁片模板路径:";
|
||||
|
||||
var button1 = panel1.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "路径选择";
|
||||
button1.preferredSize.width = 300;
|
||||
|
||||
var statictext2 = panel1.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "待套花样路径选择:";
|
||||
|
||||
var button2 = panel1.add("button", undefined, undefined, {name: "button2"});
|
||||
button2.text = "路径选择";
|
||||
button2.preferredSize.width = 300;
|
||||
|
||||
|
||||
var statictext3 = panel1.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "缓存切片裁片路径选择:";
|
||||
|
||||
var button3 = panel1.add("button", undefined, undefined, {name: "button3"});
|
||||
button3.text = "路径选择";
|
||||
button3.preferredSize.width = 300;
|
||||
|
||||
var statictext4= panel1.add("statictext", undefined, undefined, {name: "statictext4"});
|
||||
statictext4.text = "大货成品路径选择:";
|
||||
|
||||
var button4 = panel1.add("button", undefined, undefined, {name: "button4"});
|
||||
button4.text = "路径选择";
|
||||
button4.preferredSize.width = 300;
|
||||
|
||||
// PANEL2
|
||||
// ======
|
||||
var panel2 = panel1.add("panel", undefined, undefined, {name: "panel2"});
|
||||
panel2.text = "款号修改:";
|
||||
panel2.orientation = "column";
|
||||
panel2.alignChildren = ["left","top"];
|
||||
panel2.spacing = 10;
|
||||
panel2.margins = 10;
|
||||
|
||||
|
||||
|
||||
// PANEL4
|
||||
// ======
|
||||
|
||||
|
||||
var statictext11 = panel2.add("statictext", undefined, undefined, {name: "statictext11"});
|
||||
statictext11.text = "是否拼合裁片组:";
|
||||
|
||||
var checkbox1 =panel2.add("checkbox", undefined, undefined, {name: "checkbox1"});
|
||||
checkbox1.value = true;
|
||||
checkbox1.text = "拼合";
|
||||
|
||||
|
||||
|
||||
var statictext13 = panel2.add("statictext", undefined, undefined, {name: "statictext13"});
|
||||
statictext13.text = "存储位置:";
|
||||
|
||||
var checkbox3 =panel2.add("checkbox", undefined, undefined, {name: "checkbox3"});
|
||||
checkbox3.value = false;
|
||||
checkbox3.text = "模板位置";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = dialog.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "column";
|
||||
group2.alignChildren = ["fill","top"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var ok = group2.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "执行";
|
||||
|
||||
var cancel = group2.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
|
||||
var button8 = group2.add("button", undefined, undefined, {name: "button8"});
|
||||
button8.text = "关于我们";
|
||||
|
||||
button1.onClick=function(){
|
||||
|
||||
button1.text =Folder.selectDialog ("大货齐码裁片模板路径:").fsName;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
button2.onClick=function(){
|
||||
|
||||
button2.text =Folder.selectDialog ("待套花样路径选择:").fsName;
|
||||
|
||||
}
|
||||
button3.onClick=function(){
|
||||
|
||||
button3.text =Folder.selectDialog ("缓存切片裁片路径选择:").fsName;
|
||||
|
||||
|
||||
}
|
||||
button4.onClick=function(){
|
||||
|
||||
button4.text =Folder.selectDialog ("大货成品路径选择:").fsName;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
button8.onClick = function () {
|
||||
|
||||
alert("自由花型工作室 17520145271 脚本开发 裁片排版 花型开发 ",dialog.text+"----关于我们");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ok .onClick=function(){
|
||||
|
||||
|
||||
var 大货齐码裁片模板路径 = new Folder(button1.text);
|
||||
var 待套花样路径选择 =new Folder(button2.text);
|
||||
var 大货文件存放位置 =new Folder(button4.text);
|
||||
var 缓存切片裁片路径选择 = new Folder(button3.text);
|
||||
|
||||
var myFiles1 =大货齐码裁片模板路径.getFiles("*.tif*");
|
||||
var myFiles2 =待套花样路径选择.getFiles("*.tif*");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for (var i = 0; i <myFiles2.length; i++)
|
||||
{
|
||||
|
||||
app.open(myFiles2[i])
|
||||
文档名称1=activeDocument.name.replace(/(?:\.[^.]*$|$)/, '');
|
||||
var 大货成品文件夹 =文档名称1
|
||||
//花样标准化(80);
|
||||
// 文档另存(缓存切片裁片路径选择);
|
||||
花样图层导出为TIF透明底(缓存切片裁片路径选择)
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES)
|
||||
|
||||
|
||||
var parentFolderPath =大货文件存放位置
|
||||
var folderNames = 文档名称1
|
||||
|
||||
var folderPath = parentFolderPath + "/" + 文档名称1;
|
||||
var folderObj = new Folder(folderPath);
|
||||
$.writeln(folderObj);
|
||||
folderObj.create();
|
||||
|
||||
|
||||
for (var j = 0; j <myFiles1.length; j++) {
|
||||
app.open(myFiles1[j])
|
||||
|
||||
|
||||
更换当前文档裁片组外链(缓存切片裁片路径选择);
|
||||
// 图层选择();
|
||||
// app.activeDocument.activeLayer.textItem.contents = 文档名称1;
|
||||
选择裁片图层();
|
||||
|
||||
// if (checkbox1.value == true) {
|
||||
合并图层();
|
||||
预设图案填充(缓存切片裁片路径选择)
|
||||
|
||||
|
||||
|
||||
另存为(folderObj,文档名称1)
|
||||
|
||||
|
||||
|
||||
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 预设图案填充(缓存切片裁片路径选择)
|
||||
{
|
||||
|
||||
var file = new File(缓存切片裁片路径选择 + "/名称数据.json");
|
||||
if (file.open('r')) {
|
||||
var content = file.read();
|
||||
file.close();
|
||||
|
||||
// 移除双引号
|
||||
var content1 = content.replace(/"/g, '');
|
||||
|
||||
// 移除[]并使用逗号分割字符串
|
||||
var 名称数组 = content1.replace(/^\s*\[|\]\s*$/g, '').split(',');
|
||||
|
||||
for (var k = 0; k < 名称数组.length; k++) {
|
||||
var 名称 = 名称数组[k].replace(/^\s+|\s+$/g, ''); // 使用正则替代trim函数移除前后空格
|
||||
//alert(名称);
|
||||
var matches = 名称.match(/\(([^)]+)\)/);
|
||||
if (matches) {
|
||||
var 图案名称 = matches[1];
|
||||
var 素材填充 = app.activeDocument.layerSets.getByName("填充底图").layers.getByName(图案名称);
|
||||
app.activeDocument.activeLayer = 素材填充;
|
||||
载入选区();
|
||||
填充图案(名称);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alert("找不到名称数据文件查看是否写入!");
|
||||
}
|
||||
|
||||
|
||||
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("channel"), stringIDToTypeID("transparencyEnum"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 填充图案(名称) //新建图案填充图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("contentLayer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
var d2 = new ActionDescriptor();
|
||||
var d3 = new ActionDescriptor();
|
||||
d3.putString(stringIDToTypeID("name"), 名称);
|
||||
|
||||
d2.putObject(stringIDToTypeID("pattern"), stringIDToTypeID("pattern"), d3);
|
||||
d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("patternLayer"), d2);
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("contentLayer"), d1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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("channel"), stringIDToTypeID("transparencyEnum"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 填充图案(图案名称) //新建图案填充图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("contentLayer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
var d2 = new ActionDescriptor();
|
||||
var d3 = new ActionDescriptor();
|
||||
d3.putString(stringIDToTypeID("name"), 图案名称);
|
||||
d3.putString(stringIDToTypeID("ID"), 图案名称);
|
||||
d2.putObject(stringIDToTypeID("pattern"), stringIDToTypeID("pattern"), d3);
|
||||
d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("patternLayer"), d2);
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("contentLayer"), d1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 花样图层导出为TIF透明底(导出目录) {
|
||||
|
||||
app.preferences.rulerUnits = Units.MM;
|
||||
var doc = app.activeDocument;
|
||||
var 扩展毫米数=80
|
||||
|
||||
// 获取文档中的所有图层
|
||||
var allLayers = doc.layers;
|
||||
var 名称数组 = [];
|
||||
// 循环遍历所有图层
|
||||
for (var i = 0; i < allLayers.length; i++) {
|
||||
// 检查图层是否是图层组
|
||||
if (allLayers[i] instanceof LayerSet) {
|
||||
// 获取图层组中的所有子图层
|
||||
subLayers = allLayers[i].layers;
|
||||
图层组名称=allLayers[i].name
|
||||
文档名称=app.activeDocument.name
|
||||
文档名称去除后缀 = 文档名称.replace(/\.[^\.]+$/, "");
|
||||
// 检查图层组是否包含子图层
|
||||
if (subLayers.length > 0) {
|
||||
// 获取图层组中最后一个子图层的名称
|
||||
var lastSubLayer = subLayers[subLayers.length - 1];
|
||||
var lastSubLayerName = lastSubLayer.name;
|
||||
FastSubLayer = subLayers[0];
|
||||
FastSubLayername= FastSubLayer.name
|
||||
// 输出图层组名称和最后一个子图层的名称
|
||||
|
||||
|
||||
if (图层组名称 === "填充底图") {
|
||||
for (var y = 0; y < subLayers.length; y++) {
|
||||
// alert(subLayers[j].name);
|
||||
填充底图组内部循环名称 = subLayers[y].name
|
||||
填充底图循环素材 = app.activeDocument.layerSets.getByName("填充底图").layers.getByName(填充底图组内部循环名称);
|
||||
app.activeDocument.activeLayer = 填充底图循环素材;
|
||||
新建文档()
|
||||
// 合并图层()
|
||||
载入选区()
|
||||
裁剪()
|
||||
名称=文档名称去除后缀+"-("+填充底图组内部循环名称 +")-填充底图"
|
||||
名称数组.push('"' + 名称 + '"');
|
||||
制作图案预设(名称)
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
app.activeDocument=doc
|
||||
// 执行某一个操作(例如,设置图层组的可见性)
|
||||
// alert("测试")
|
||||
}
|
||||
|
||||
|
||||
// 手动创建JSON格式的字符串
|
||||
var jsonStr = '[' + 名称数组.join(', ') + ']';
|
||||
|
||||
// 创建一个文件对象指向桌面
|
||||
|
||||
var file = new File(导出目录 + "/名称数据.json");
|
||||
|
||||
// 打开文件,写入JSON字符串,然后关闭文件
|
||||
file.open('w');
|
||||
file.write(jsonStr);
|
||||
file.close();
|
||||
|
||||
} else {
|
||||
// 执行别的操作(例如,隐藏其他图层组)
|
||||
|
||||
|
||||
|
||||
空白裁片模板 = app.activeDocument.layerSets.getByName(图层组名称).layers.getByName(lastSubLayerName);
|
||||
app.activeDocument.activeLayer = 空白裁片模板;
|
||||
新建图层()
|
||||
app.activeDocument.activeLayer.name="最大白边值"
|
||||
裁片边界 = lastSubLayer.bounds;
|
||||
扩展值 = 毫米转像素(扩展毫米数); //50cm
|
||||
裁片边界_左 = 毫米转像素(裁片边界[0]) - 扩展值;
|
||||
|
||||
裁片边界_上 = 毫米转像素(裁片边界[1]) - 扩展值;
|
||||
裁片边界_右 = 毫米转像素(裁片边界[2]) + 扩展值;
|
||||
裁片边界_下 = 毫米转像素(裁片边界[3]) + 扩展值;
|
||||
|
||||
var selRegion = [
|
||||
[裁片边界_左,裁片边界_上],
|
||||
[裁片边界_右,裁片边界_上],
|
||||
[裁片边界_右,裁片边界_下],
|
||||
[裁片边界_左,裁片边界_下]
|
||||
];
|
||||
app.activeDocument.selection.select(selRegion, SelectionType.REPLACE);
|
||||
背景切换();
|
||||
恢复白底();
|
||||
填充();
|
||||
隐藏图层();
|
||||
裁片图层组 = app.activeDocument.layerSets.getByName(图层组名称)
|
||||
app.activeDocument.activeLayer = 裁片图层组 ;
|
||||
新建文档()
|
||||
空白裁片模板 = app.activeDocument.layerSets.getByName(图层组名称).layers.getByName(lastSubLayerName);
|
||||
app.activeDocument.activeLayer = 空白裁片模板;
|
||||
删除图层()
|
||||
最大白边值=app.activeDocument.layerSets.getByName(图层组名称).layers.getByName("最大白边值");
|
||||
app.activeDocument.activeLayer = 最大白边值;
|
||||
app.activeDocument.crop(最大白边值.bounds, 0);
|
||||
// 保存为TIF
|
||||
var 文件路径 = 导出目录 + "/" + 图层组名称 + ".tif";
|
||||
tiffOptions = new TiffSaveOptions();
|
||||
app.activeDocument.saveAs(new File(文件路径), tiffOptions);
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
app.activeDocument=doc
|
||||
最大白边值=app.activeDocument.layerSets.getByName(图层组名称).layers.getByName(FastSubLayername);
|
||||
app.activeDocument.activeLayer = 最大白边值;
|
||||
//上移图层()
|
||||
多选图层()
|
||||
转换为智能对象()
|
||||
添加图层蒙版()
|
||||
// 向下合并()
|
||||
转换为智能对象()
|
||||
// 重新链接到文件(文件路径)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
function 恢复白底() //删除图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putProperty(stringIDToTypeID("color"), stringIDToTypeID("colors"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("exchange"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 制作图案预设(名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("pattern"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
|
||||
r1.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("using"), r1);
|
||||
d.putString(stringIDToTypeID("name"), 名称);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 合并图层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 背景切换() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putProperty(stringIDToTypeID("color"), stringIDToTypeID("colors"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("reset"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 裁剪() //裁剪
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putBoolean(stringIDToTypeID("delete"), true);
|
||||
executeAction(stringIDToTypeID("crop"), d, DialogModes.NO);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 重新链接到文件(文件路径) //重新链接到文件
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putPath(stringIDToTypeID("null"), new File(文件路径));
|
||||
d.putInteger(stringIDToTypeID("layerID"), 94);
|
||||
executeAction(stringIDToTypeID("placedLayerRelinkToFile"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 转换为智能对象() //转换为智能对象
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("newPlacedLayer"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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("channel"), stringIDToTypeID("transparencyEnum"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 向下合并() //向下合并
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 添加图层蒙版() //添加图层蒙版
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putClass(stringIDToTypeID("new"), stringIDToTypeID("channel"));
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("mask"));
|
||||
d.putReference(stringIDToTypeID("at"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("userMaskEnabled"), stringIDToTypeID("revealSelection"));
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function 上移图层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("forwardEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(11);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 毫米转像素(毫米)
|
||||
{
|
||||
//厘米转像素
|
||||
doc_w = app.activeDocument.width;
|
||||
//用户设定的厘米数 支持小数
|
||||
user_mm = UnitValue(毫米,"mm");
|
||||
user_px = user_mm.as("px")*app.activeDocument.resolution/72;
|
||||
return user_px;
|
||||
}
|
||||
|
||||
|
||||
function 删除图层() //删除图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var list = new ActionList();
|
||||
list.putInteger(22);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("delete"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 多选图层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("layer"), "最大白边值");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelectionContinuous"));
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
|
||||
list.putInteger(115);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
function 新建图层() //新建图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("layer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putBoolean(stringIDToTypeID("group"), true);
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("layer"), d1);
|
||||
d.putInteger(stringIDToTypeID("layerID"), 22);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 填充() //填充
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("fillContents"), stringIDToTypeID("foregroundColor"));
|
||||
d.putUnitDouble(stringIDToTypeID("opacity"), stringIDToTypeID("percentUnit"), 100);
|
||||
d.putEnumerated(stringIDToTypeID("mode"), stringIDToTypeID("blendMode"), stringIDToTypeID("normal"));
|
||||
executeAction(stringIDToTypeID("fill"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
function 隐藏图层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var list = new ActionList();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
list.putReference(r);
|
||||
d.putList(stringIDToTypeID("null"), list);
|
||||
executeAction(stringIDToTypeID("hide"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 新建文档() //复制图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("document"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("using"), r1);
|
||||
d.putInteger(stringIDToTypeID("version"), 5);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 更换当前文档裁片组外链(缓存切片裁片路径选择)
|
||||
{
|
||||
try
|
||||
{
|
||||
裁片组 = app.activeDocument.layerSets.getByName("裁片").layers;
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
alert("找不到裁片组");
|
||||
|
||||
}
|
||||
|
||||
for(var k=0;k<裁片组.length;k++)
|
||||
{
|
||||
裁片 = 裁片组[k];
|
||||
app.activeDocument.activeLayer = 裁片;
|
||||
if(裁片.kind == LayerKind.SMARTOBJECT)
|
||||
{
|
||||
更换链接智能对象路径(缓存切片裁片路径选择);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function 更换链接智能对象路径(缓存切片裁片路径选择)
|
||||
{
|
||||
//获取当前图层外链的智能对象路径
|
||||
//先获取链接的文件名
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
//~ r.putName(charIDToTypeID("Lyr "), "◆左袖口"); //按名称查找
|
||||
descLayer = executeActionGet(r);
|
||||
res = descLayer.getObjectValue(stringIDToTypeID("smartObject"));
|
||||
|
||||
链接文件名 = res.getString(stringIDToTypeID("fileReference"));
|
||||
//$.writeln(链接文件名);
|
||||
|
||||
//~ 链接文件路径 = res.getPath(stringIDToTypeID("link"));
|
||||
//~ $.writeln(链接文件路径);
|
||||
|
||||
图片路径 = 缓存切片裁片路径选择 + "/" + 链接文件名;
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putPath(stringIDToTypeID("null"), new File(图片路径));
|
||||
executeAction(stringIDToTypeID("placedLayerRelinkToFile"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 另存为(folderObj,文档名称1)
|
||||
{
|
||||
文档名称=activeDocument.name.replace(/(?:\.[^.]*$|$)/, '');
|
||||
saveIn=File(folderObj+ "/"+文档名称1+"-"+文档名称);
|
||||
tifSaveOpt = new TiffSaveOptions();
|
||||
tifSaveOpt.imageCompression = TIFFEncoding.TIFFLZW;
|
||||
tifSaveOpt.byteOrder = ByteOrder.IBM;
|
||||
asCopy=true
|
||||
app.activeDocument.saveAs(saveIn,tifSaveOpt,asCopy);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 图层选择() //a
|
||||
{
|
||||
try {
|
||||
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(74);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
}
|
||||
catch (e) {
|
||||
//alert("找不到款号图层",dialog.text+"----关于");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
function 合并图层() //合并图层
|
||||
{
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 选择裁片图层() //
|
||||
{
|
||||
try {
|
||||
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(74);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
}
|
||||
catch (e) {
|
||||
alert("找不到裁片图层",dialog.text+"----关于");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 存储在原来位置(myFolder)
|
||||
{
|
||||
tiffOptions = new TiffSaveOptions();
|
||||
|
||||
try
|
||||
{
|
||||
app.activeDocument.saveAs(new File(文件路径), tiffOptions);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
alert(文件太大无法保存)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function 花样标准化(扩展毫米数)
|
||||
{
|
||||
var 扩展毫米数=80
|
||||
app.preferences.rulerUnits = Units.MM;
|
||||
|
||||
裁片组 = app.activeDocument.layerSets;
|
||||
|
||||
for(var z=0;z<裁片组.length;z++)
|
||||
{
|
||||
当前裁片组 = 裁片组[z];
|
||||
花样图层 = 当前裁片组.layers[0];
|
||||
裁片图层 = 当前裁片组.layers[1];
|
||||
|
||||
裁片边界 = 裁片图层.bounds;
|
||||
//~ alert(毫米转像素(50))
|
||||
//~ 扩展值 = 毫米转像素(50); //50cm
|
||||
扩展值 = 毫米转像素(扩展毫米数); //50cm
|
||||
裁片边界_左 = 毫米转像素(裁片边界[0]) - 扩展值;
|
||||
裁片边界_上 = 毫米转像素(裁片边界[1]) - 扩展值;
|
||||
裁片边界_右 = 毫米转像素(裁片边界[2]) + 扩展值;
|
||||
裁片边界_下 = 毫米转像素(裁片边界[3]) + 扩展值;
|
||||
|
||||
|
||||
//左上右下点XY坐标
|
||||
var selRegion = [
|
||||
[裁片边界_左,裁片边界_上],
|
||||
[裁片边界_右,裁片边界_上],
|
||||
[裁片边界_右,裁片边界_下],
|
||||
[裁片边界_左,裁片边界_下]
|
||||
];
|
||||
|
||||
app.activeDocument.activeLayer = 花样图层;
|
||||
app.activeDocument.selection.select(selRegion, SelectionType.REPLACE);
|
||||
按选区添加蒙版();
|
||||
|
||||
//制作一个白底衬底图
|
||||
//新建一个图层
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("layer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putInteger(stringIDToTypeID("layerID"), 198);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
白底图层 = app.activeDocument.activeLayer;
|
||||
白底图层.name = "白底";
|
||||
|
||||
app.activeDocument.selection.select(selRegion, SelectionType.REPLACE);
|
||||
|
||||
var c = new SolidColor();
|
||||
c.rgb.hexValue = "FFFFFF";
|
||||
app.activeDocument.selection.fill(c);
|
||||
|
||||
花样图层.grouped = false;
|
||||
白底图层.move(花样图层,ElementPlacement.PLACEAFTER);
|
||||
|
||||
|
||||
app.activeDocument.activeLayer = 花样图层;
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("layer"), "白底");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelectionContinuous"));
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
app.activeDocument.activeLayer.merge(); //合并当前选择图层
|
||||
app.activeDocument.activeLayer.grouped = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 毫米转像素(毫米)
|
||||
{
|
||||
//厘米转像素
|
||||
doc_w = app.activeDocument.width;
|
||||
//用户设定的厘米数 支持小数
|
||||
user_mm = UnitValue(毫米,"mm");
|
||||
user_px = user_mm.as("px")*app.activeDocument.resolution/72;
|
||||
return user_px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 按选区添加蒙版() //先创建出选区 然后按选区添加出一个蒙版
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putClass(stringIDToTypeID("new"), stringIDToTypeID("channel"));
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("mask"));
|
||||
d.putReference(stringIDToTypeID("at"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("userMaskEnabled"), stringIDToTypeID("revealSelection"));
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 文档另存(缓存切片裁片路径选择){
|
||||
|
||||
var 导出目录 =缓存切片裁片路径选择;
|
||||
var 裁片组 = app.activeDocument.layerSets;
|
||||
|
||||
|
||||
|
||||
for(var i=0;i<裁片组.length;i++)
|
||||
{
|
||||
|
||||
app.activeDocument.duplicate("temp");
|
||||
|
||||
复制文档裁片组 = app.activeDocument.layerSets;
|
||||
当前裁片组 = 复制文档裁片组[i];
|
||||
当前裁片组名 = 当前裁片组.name;
|
||||
花样图层 = 当前裁片组.layers[0];
|
||||
裁片图层 = 当前裁片组.layers[1];
|
||||
|
||||
app.activeDocument.activeLayer = 花样图层;
|
||||
//把花样图层导出
|
||||
花样图层.grouped = false; //取消图层链接
|
||||
|
||||
仅当前图层可见();
|
||||
|
||||
//按花样图层大小裁剪文档
|
||||
app.activeDocument.crop(花样图层.bounds,0);
|
||||
|
||||
//拼合图像只保留花样图层
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("flattenImage"), d, DialogModes.NO);
|
||||
|
||||
//保存为TIF
|
||||
var 文件路径 = 导出目录 + "/" + 当前裁片组名 + ".tif";
|
||||
tiffOptions = new TiffSaveOptions();
|
||||
app.activeDocument.saveAs(new File(文件路径), tiffOptions);
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 仅当前图层可见()
|
||||
{
|
||||
var d = new ActionDescriptor();
|
||||
var list = new ActionList();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
list.putReference(r);
|
||||
d.putList(stringIDToTypeID("null"), list);
|
||||
d.putBoolean(stringIDToTypeID("toggleOptionsPalette"), true);
|
||||
executeAction(stringIDToTypeID("show"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
569
PSMARK代码块/定位码快速超链接.jsx
Normal file
569
PSMARK代码块/定位码快速超链接.jsx
Normal file
@@ -0,0 +1,569 @@
|
||||
|
||||
|
||||
|
||||
function 快速定位码链接() {
|
||||
|
||||
app.activeDocument.suspendHistory("快速定位码链接", "花样图层导出()");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 花样图层导出() {
|
||||
var 导出目录 = Folder.selectDialog("选择外链素材目录");
|
||||
if (!导出目录) {
|
||||
alert("未选择导出目录。操作已取消。");
|
||||
return;
|
||||
}
|
||||
花样图层导出为TIF透明底(导出目录)
|
||||
// 花样图层导出为TIF(导出目录);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 花样图层导出为TIF透明底(导出目录) {
|
||||
|
||||
app.preferences.rulerUnits = Units.MM;
|
||||
var doc = app.activeDocument;
|
||||
var 扩展毫米数=80
|
||||
|
||||
// 获取文档中的所有图层
|
||||
var allLayers = doc.layers;
|
||||
|
||||
var 名称数组 = [];
|
||||
// 循环遍历所有图层
|
||||
for (var i = 0; i < allLayers.length; i++) {
|
||||
// 检查图层是否是图层组
|
||||
if (allLayers[i] instanceof LayerSet) {
|
||||
// 获取图层组中的所有子图层
|
||||
subLayers = allLayers[i].layers;
|
||||
图层组名称=allLayers[i].name
|
||||
文档名称=app.activeDocument.name
|
||||
文档名称去除后缀 = 文档名称.replace(/\.[^\.]+$/, "");
|
||||
// 检查图层组是否包含子图层
|
||||
if (subLayers.length > 0) {
|
||||
// 获取图层组中最后一个子图层的名称
|
||||
var lastSubLayer = subLayers[subLayers.length - 1];
|
||||
var lastSubLayerName = lastSubLayer.name;
|
||||
var lastSubLayerName = lastSubLayer.name;
|
||||
FastSubLayer = subLayers[0];
|
||||
FastSubLayername= FastSubLayer.name
|
||||
|
||||
//alert(SastSubLayerName)
|
||||
// 输出图层组名称和最后一个子图层的名称
|
||||
|
||||
|
||||
if (图层组名称 === "填充底图") {
|
||||
for (var j = 0; j < subLayers.length; j++) {
|
||||
// alert(subLayers[j].name);
|
||||
填充底图组内部循环名称 = subLayers[j].name
|
||||
填充底图循环素材 = app.activeDocument.layerSets.getByName("填充底图").layers.getByName(填充底图组内部循环名称);
|
||||
app.activeDocument.activeLayer = 填充底图循环素材;
|
||||
新建文档()
|
||||
// 合并图层()
|
||||
载入选区()
|
||||
裁剪()
|
||||
名称=文档名称去除后缀+"-("+填充底图组内部循环名称 +")-填充底图"
|
||||
名称数组.push('"' + 名称 + '"');
|
||||
制作图案预设(名称)
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
app.activeDocument=doc
|
||||
// 执行某一个操作(例如,设置图层组的可见性)
|
||||
// alert("测试")
|
||||
}
|
||||
|
||||
|
||||
// 手动创建JSON格式的字符串
|
||||
var jsonStr = '[' + 名称数组.join(', ') + ']';
|
||||
|
||||
// 创建一个文件对象指向桌面
|
||||
|
||||
var file = new File(导出目录 + "/名称数据.json");
|
||||
|
||||
// 打开文件,写入JSON字符串,然后关闭文件
|
||||
file.open('w');
|
||||
file.write(jsonStr);
|
||||
file.close();
|
||||
|
||||
} else {
|
||||
// 执行别的操作(例如,隐藏其他图层组)
|
||||
|
||||
|
||||
|
||||
空白裁片模板 = app.activeDocument.layerSets.getByName(图层组名称).layers.getByName(lastSubLayerName);
|
||||
app.activeDocument.activeLayer = 空白裁片模板;
|
||||
新建图层()
|
||||
app.activeDocument.activeLayer.name="最大白边值"
|
||||
裁片边界 = lastSubLayer.bounds;
|
||||
扩展值 = 毫米转像素(扩展毫米数); //50cm
|
||||
裁片边界_左 = 毫米转像素(裁片边界[0]) - 扩展值;
|
||||
|
||||
裁片边界_上 = 毫米转像素(裁片边界[1]) - 扩展值;
|
||||
裁片边界_右 = 毫米转像素(裁片边界[2]) + 扩展值;
|
||||
裁片边界_下 = 毫米转像素(裁片边界[3]) + 扩展值;
|
||||
|
||||
var selRegion = [
|
||||
[裁片边界_左,裁片边界_上],
|
||||
[裁片边界_右,裁片边界_上],
|
||||
[裁片边界_右,裁片边界_下],
|
||||
[裁片边界_左,裁片边界_下]
|
||||
];
|
||||
app.activeDocument.selection.select(selRegion, SelectionType.REPLACE);
|
||||
背景切换();
|
||||
恢复白底();
|
||||
填充();
|
||||
隐藏图层();
|
||||
裁片图层组 = app.activeDocument.layerSets.getByName(图层组名称)
|
||||
app.activeDocument.activeLayer = 裁片图层组 ;
|
||||
新建文档()
|
||||
空白裁片模板 = app.activeDocument.layerSets.getByName(图层组名称).layers.getByName(lastSubLayerName);
|
||||
app.activeDocument.activeLayer = 空白裁片模板;
|
||||
删除图层()
|
||||
最大白边值=app.activeDocument.layerSets.getByName(图层组名称).layers.getByName("最大白边值");
|
||||
app.activeDocument.activeLayer = 最大白边值;
|
||||
app.activeDocument.crop(最大白边值.bounds, 0);
|
||||
|
||||
// 保存为TIF
|
||||
var 文件路径 = 导出目录 + "/" + 图层组名称 + ".tif";
|
||||
tiffOptions = new TiffSaveOptions();
|
||||
app.activeDocument.saveAs(new File(文件路径), tiffOptions);
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
app.activeDocument=doc
|
||||
最大白边值=app.activeDocument.layerSets.getByName(图层组名称).layers.getByName(FastSubLayername);
|
||||
app.activeDocument.activeLayer = 最大白边值;
|
||||
//上移图层()
|
||||
多选图层()
|
||||
转换为智能对象()
|
||||
释放剪贴蒙版()
|
||||
栅格化图层()
|
||||
选择下一图层()
|
||||
新建图层()
|
||||
背景切换();
|
||||
恢复白底();
|
||||
填充();
|
||||
选择上一图层()
|
||||
添加图层蒙版()
|
||||
向下合并()
|
||||
转换为智能对象()
|
||||
重新链接到文件(文件路径)
|
||||
创建剪贴蒙版()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
function 恢复白底() //删除图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putProperty(stringIDToTypeID("color"), stringIDToTypeID("colors"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("exchange"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 创建剪贴蒙版() //创建剪贴蒙版
|
||||
|
||||
{
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("groupEvent"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 制作图案预设(名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("pattern"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
|
||||
r1.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("using"), r1);
|
||||
d.putString(stringIDToTypeID("name"), 名称);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function mergeLayersNew_72799682617188() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 合并图层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 背景切换() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putProperty(stringIDToTypeID("color"), stringIDToTypeID("colors"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("reset"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 图层可见性show() //图层可见性
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var list = new ActionList();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
list.putReference(r);
|
||||
d.putList(stringIDToTypeID("null"), list);
|
||||
executeAction(stringIDToTypeID("show"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 裁剪() //裁剪
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putBoolean(stringIDToTypeID("delete"), true);
|
||||
executeAction(stringIDToTypeID("crop"), d, DialogModes.NO);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 重新链接到文件(文件路径) //重新链接到文件
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putPath(stringIDToTypeID("null"), new File(文件路径));
|
||||
d.putInteger(stringIDToTypeID("layerID"), 94);
|
||||
executeAction(stringIDToTypeID("placedLayerRelinkToFile"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 转换为智能对象() //转换为智能对象
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("newPlacedLayer"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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("channel"), stringIDToTypeID("transparencyEnum"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 向下合并() //向下合并
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 添加图层蒙版() //添加图层蒙版
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putClass(stringIDToTypeID("new"), stringIDToTypeID("channel"));
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("mask"));
|
||||
d.putReference(stringIDToTypeID("at"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("userMaskEnabled"), stringIDToTypeID("revealSelection"));
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function 上移图层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("forwardEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(11);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 毫米转像素(毫米)
|
||||
{
|
||||
//厘米转像素
|
||||
doc_w = app.activeDocument.width;
|
||||
//用户设定的厘米数 支持小数
|
||||
user_mm = UnitValue(毫米,"mm");
|
||||
user_px = user_mm.as("px")*app.activeDocument.resolution/72;
|
||||
return user_px;
|
||||
}
|
||||
|
||||
|
||||
function 删除图层() //删除图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var list = new ActionList();
|
||||
list.putInteger(22);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("delete"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 多选图层(SastSubLayerName) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("layer"), "最大白边值");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelectionContinuous"));
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
|
||||
list.putInteger(115);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
function 新建图层() //新建图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("layer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putBoolean(stringIDToTypeID("group"), true);
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("layer"), d1);
|
||||
d.putInteger(stringIDToTypeID("layerID"), 22);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 释放剪贴蒙版() //释放剪贴蒙版
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("ungroup"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 添加图层蒙版() //添加图层蒙版
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putClass(stringIDToTypeID("new"), stringIDToTypeID("channel"));
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("mask"));
|
||||
d.putReference(stringIDToTypeID("at"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("userMaskEnabled"), stringIDToTypeID("revealSelection"));
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 向下合并() //向下合并
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 栅格化图层() //栅格化图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("rasterizeLayer"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 选择下一图层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("backwardEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(314);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 选择上一图层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("forwardEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(369);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
function 新建图层() //新建图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("layer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putInteger(stringIDToTypeID("layerID"), 373);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 恢复白底() //删除图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putProperty(stringIDToTypeID("color"), stringIDToTypeID("colors"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("exchange"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 背景切换() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putProperty(stringIDToTypeID("color"), stringIDToTypeID("colors"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("reset"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 填充() //填充
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("fillContents"), stringIDToTypeID("foregroundColor"));
|
||||
d.putUnitDouble(stringIDToTypeID("opacity"), stringIDToTypeID("percentUnit"), 100);
|
||||
d.putEnumerated(stringIDToTypeID("mode"), stringIDToTypeID("blendMode"), stringIDToTypeID("normal"));
|
||||
executeAction(stringIDToTypeID("fill"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 填充() //填充
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("fillContents"), stringIDToTypeID("foregroundColor"));
|
||||
d.putUnitDouble(stringIDToTypeID("opacity"), stringIDToTypeID("percentUnit"), 100);
|
||||
d.putEnumerated(stringIDToTypeID("mode"), stringIDToTypeID("blendMode"), stringIDToTypeID("normal"));
|
||||
executeAction(stringIDToTypeID("fill"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
function 隐藏图层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var list = new ActionList();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
list.putReference(r);
|
||||
d.putList(stringIDToTypeID("null"), list);
|
||||
executeAction(stringIDToTypeID("hide"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 新建文档() //复制图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("document"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("using"), r1);
|
||||
d.putInteger(stringIDToTypeID("version"), 5);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
30
PSMARK代码块/对齐居中方式.jsx
Normal file
30
PSMARK代码块/对齐居中方式.jsx
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
底对齐()
|
||||
水平居中对齐()
|
||||
function 底对齐() //底对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSBottoms"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 水平居中对齐() //水平居中对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSCentersH"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
124
PSMARK代码块/开启事件监听.jsx
Normal file
124
PSMARK代码块/开启事件监听.jsx
Normal file
@@ -0,0 +1,124 @@
|
||||
function 开启事件监听() {
|
||||
|
||||
try
|
||||
{
|
||||
arg_num = arguments.length;
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
arguments = []; //初始赋值为空
|
||||
}
|
||||
|
||||
eventName = "set";
|
||||
|
||||
//开启监听
|
||||
enable_notifier(eventName, $.fileName);
|
||||
alert("开启成功")
|
||||
//取消监听
|
||||
//disable_notifier(eventName, $.fileName);
|
||||
|
||||
//这里进行监控调用事件
|
||||
if (arguments.length >= 2)
|
||||
{
|
||||
//alert(arguments.length);
|
||||
//~ alert(arguments[0],"动作参数1"); //动作描述符 AR
|
||||
//~ alert(arguments[1],"动作参数2"); //动作事件ID
|
||||
|
||||
//alert("事件名:"+typeIDToStringID(arguments[1])+"\n"+"事件ID:"+arguments[1],"提示:");
|
||||
moveToGuideCenter();
|
||||
//main(arguments[0], arguments[1]);
|
||||
}
|
||||
|
||||
function moveToGuideCenter() {
|
||||
if (app.documents.length === 0 || !app.activeDocument.selection.bounds) {
|
||||
alert("没有打开的文档或没有有效的选区。");
|
||||
return;
|
||||
}
|
||||
|
||||
var doc = app.activeDocument;
|
||||
var guides = doc.guides;
|
||||
var xGuide = null;
|
||||
var yGuide = null;
|
||||
|
||||
// 找到 X 方向和 Y 方向上的参考线
|
||||
for (var i = 0; i < guides.length; i++) {
|
||||
var guide = guides[i];
|
||||
if (guide.direction === Direction.HORIZONTAL && yGuide === null) {
|
||||
yGuide = guide;
|
||||
} else if (guide.direction === Direction.VERTICAL && xGuide === null) {
|
||||
xGuide = guide;
|
||||
}
|
||||
}
|
||||
|
||||
if (xGuide === null || yGuide === null) {
|
||||
alert("必须确保存在一条水平和一条垂直参考线。");
|
||||
return;
|
||||
}
|
||||
|
||||
var intersectionX = xGuide.coordinate;
|
||||
var intersectionY = yGuide.coordinate;
|
||||
|
||||
var bounds = doc.selection.bounds;
|
||||
var xCenter = bounds[0] + (bounds[2] - bounds[0]) / 2;
|
||||
var yCenter = bounds[1] + (bounds[3] - bounds[1]) / 2;
|
||||
|
||||
var deltaX = intersectionX - xCenter;
|
||||
var deltaY = intersectionY - yCenter;
|
||||
|
||||
// 取消当前选区
|
||||
doc.selection.deselect();
|
||||
|
||||
// 移动选区图层
|
||||
var selectedLayer = doc.activeLayer;
|
||||
selectedLayer.translate(deltaX, deltaY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function enable_notifier(event_name, script_name, event_class)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < app.notifiers.length; i++)
|
||||
{
|
||||
if (app.notifiers[i].event == event_name &&
|
||||
File(app.notifiers[i].eventFile).fsName.toLowerCase() == File(script_name).fsName.toLowerCase())
|
||||
{
|
||||
if (!app.notifiersEnabled) app.notifiersEnabled = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
app.notifiers.add(event_name, File(script_name), event_class);
|
||||
app.notifiersEnabled = true;
|
||||
return true;
|
||||
}
|
||||
catch (e) { _alert(e); return false; }
|
||||
}
|
||||
|
||||
|
||||
function disable_notifier(event_name, script_name, event_class)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ret = false;
|
||||
|
||||
for (var i = 0; i < app.notifiers.length; i++)
|
||||
{
|
||||
if (app.notifiers[i].event == event_name &&
|
||||
File(app.notifiers[i].eventFile).fsName.toLowerCase() == File(script_name).fsName.toLowerCase())
|
||||
{
|
||||
app.notifiers[i].remove();
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!app.notifiers.length) app.notifiersEnabled = false;
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch (e) { _alert(e); return false; }
|
||||
}
|
||||
}
|
||||
51
PSMARK代码块/批量建立蒙蔽.jsx
Normal file
51
PSMARK代码块/批量建立蒙蔽.jsx
Normal file
@@ -0,0 +1,51 @@
|
||||
function 删除图层3()
|
||||
{
|
||||
app.activeDocument.suspendHistory("Establish a mask", "批量建立蒙版()");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 批量建立蒙版(){
|
||||
|
||||
var doc = app.activeDocument; // 获取当前文档
|
||||
// 遍历所有图层
|
||||
for (var i = 0; i < doc.artLayers.length; i++) {
|
||||
var layer = doc.artLayers[i];
|
||||
// alert(layer.name); // 显示图层名称
|
||||
var layname=layer.name
|
||||
var 图层名称选择 = app.activeDocument.layers.getByName(layname);
|
||||
app.activeDocument.activeLayer = 图层名称选择;
|
||||
载入选区();
|
||||
添加图层蒙版();
|
||||
}
|
||||
|
||||
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("channel"), stringIDToTypeID("transparencyEnum"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 添加图层蒙版() //添加图层蒙版
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putClass(stringIDToTypeID("new"), stringIDToTypeID("channel"));
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("mask"));
|
||||
d.putReference(stringIDToTypeID("at"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("userMaskEnabled"), stringIDToTypeID("revealSelection"));
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
18
PSMARK代码块/批量换图.jsx
Normal file
18
PSMARK代码块/批量换图.jsx
Normal file
@@ -0,0 +1,18 @@
|
||||
// 获取Photoshop的当前文档
|
||||
var 当前文档 = app.activeDocument;
|
||||
|
||||
try {
|
||||
// 获取名为"贴图位置"的图层组
|
||||
var layerSet = 当前文档.layerSets.getByName("贴图位置");
|
||||
|
||||
// 遍历图层组中的每个图层
|
||||
for (var i = 0; i < layerSet.artLayers.length; i++) {
|
||||
var layer = layerSet.artLayers[i];
|
||||
|
||||
// 在这里执行对每个图层的操作
|
||||
// 例如,打印图层的名字
|
||||
alert("图层名: " + layer.name);
|
||||
}
|
||||
} catch (e) {
|
||||
alert("发生错误或找不到图层组: " + e);
|
||||
}
|
||||
16
PSMARK代码块/拼合所有文档.jsx
Normal file
16
PSMARK代码块/拼合所有文档.jsx
Normal file
@@ -0,0 +1,16 @@
|
||||
function 删除图层3()
|
||||
{
|
||||
app.activeDocument.suspendHistory("Combine all masks", "拼合所有蒙版()");
|
||||
}
|
||||
|
||||
|
||||
function 拼合所有蒙版() //拼合所有蒙版
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("e805a6ee-6d75-4b62-b6fe-f5873b5fdf20"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
8
PSMARK代码块/新的名称还回.jsx
Normal file
8
PSMARK代码块/新的名称还回.jsx
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
function 名称重新赋予(layername,angle,size) //
|
||||
{
|
||||
var doc = app.activeDocument;
|
||||
var selectedLayer = doc.activeLayer;
|
||||
selectedLayer.name =layername+"-"+"Mark"+"_"+angle+"_"+size
|
||||
}
|
||||
//layername+"-"+"Mark"+"_"+angle+"_"+size
|
||||
55
PSMARK代码块/新的图案填充.jsx
Normal file
55
PSMARK代码块/新的图案填充.jsx
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
// 找到图层组后,显示文件夹选择框
|
||||
var 文件夹 = Folder.selectDialog("请选择要打开文件的文件夹");
|
||||
|
||||
if (文件夹) {
|
||||
var 文件列表 = 文件夹.getFiles();
|
||||
for (var i = 0; i < 文件列表.length; i++) {
|
||||
var 文件 = 文件列表[i];
|
||||
// 确保文件是图像文件
|
||||
if (文件 instanceof File && 文件.name.match(/\.(jpg|jpeg|png|gif|psd)$/i)) {
|
||||
原始文档 = app.activeDocument;
|
||||
app.open(文件);
|
||||
图像大小();
|
||||
预设图案(当前文档名称);
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
app.activeDocument =原始文档;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 图像大小() //图像大小
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putUnitDouble(stringIDToTypeID("resolution"), stringIDToTypeID("densityUnit"), 200);
|
||||
d.putBoolean(stringIDToTypeID("scaleStyles"), true);
|
||||
d.putBoolean(stringIDToTypeID("constrainProportions"), true);
|
||||
d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("nearestNeighbor"));
|
||||
executeAction(stringIDToTypeID("imageSize"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 预设图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("pattern"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
|
||||
r1.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("using"), r1);
|
||||
d.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
45
PSMARK代码块/新的排序图层顺序改名.jsx
Normal file
45
PSMARK代码块/新的排序图层顺序改名.jsx
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
|
||||
function 图层排序改名(){
|
||||
|
||||
var doc = app.activeDocument;
|
||||
|
||||
// 函数:获取图层的面积
|
||||
function getLayerArea(layer) {
|
||||
var bounds = layer.bounds;
|
||||
var width = bounds[2].value - bounds[0].value;
|
||||
var height = bounds[3].value - bounds[1].value;
|
||||
return width * height;
|
||||
}
|
||||
|
||||
// 创建一个包含所有图层及其面积的数组
|
||||
var layers = [];
|
||||
for (var i = 0; i < doc.layers.length; i++) {
|
||||
var layer = doc.layers[i];
|
||||
var area = getLayerArea(layer);
|
||||
layers.push({ layer: layer, area: area });
|
||||
}
|
||||
|
||||
// 按面积对图层进行排序
|
||||
layers.sort(function(a, b) {
|
||||
return b.area - a.area; // 从大到小排序
|
||||
});
|
||||
|
||||
// 正则表达式,用于移除图层名称中的最后一个字符
|
||||
var regex = /(.+)-\d+$/;
|
||||
|
||||
// 重新排列图层,并重命名
|
||||
for (var i = 0; i < layers.length; i++) {
|
||||
// 移动图层到文档顶部
|
||||
layers[i].layer.move(doc, ElementPlacement.PLACEATBEGINNING);
|
||||
|
||||
// 获取原始图层名称,并使用正则表达式处理
|
||||
var originalName = layers[i].layer.name;
|
||||
var newName = originalName.replace(regex, "$1");
|
||||
|
||||
// 添加新的排序编号
|
||||
layers[i].layer.name = newName + "-" + (i + 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
216
PSMARK代码块/新的模特换图.jsx
Normal file
216
PSMARK代码块/新的模特换图.jsx
Normal file
@@ -0,0 +1,216 @@
|
||||
// 弹出文件夹选择框
|
||||
模特换图()
|
||||
function 模特换图(){
|
||||
建立快照()
|
||||
var folder = Folder.selectDialog("请选择一个文件夹");
|
||||
var 模特文档 = app.activeDocument;
|
||||
|
||||
if (folder) {
|
||||
// 在选择的文件夹中创建一个新的子文件夹
|
||||
var targetFolder = new Folder(folder.fullName + "/模特图生成");
|
||||
if (!targetFolder.exists) {
|
||||
targetFolder.create();
|
||||
}
|
||||
|
||||
var files = folder.getFiles();
|
||||
|
||||
// 获取“贴图位置”图层组中的所有图层名称
|
||||
var layerSet = 模特文档.layerSets.getByName("贴图位置");
|
||||
var layerNames = [];
|
||||
for (var j = 0; j < layerSet.artLayers.length; j++) {
|
||||
layerNames.push(layerSet.artLayers[j].name);
|
||||
}
|
||||
|
||||
// 遍历并尝试打开每个文件
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var file = files[i];
|
||||
if (file instanceof File) {
|
||||
try {
|
||||
app.open(file);
|
||||
app.activeDocument.flatten()
|
||||
var 当前文档 = app.activeDocument;
|
||||
var 当前文档名称 = 当前文档.name;
|
||||
图像大小();
|
||||
预设图案(当前文档名称);
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
app.activeDocument = 模特文档;
|
||||
var 水平增量 = 200;
|
||||
var 垂直增量 = 300;
|
||||
var 水平基数 = 200;
|
||||
var 垂直基数 = 300;
|
||||
// 遍历“贴图位置”图层组中的每个图层
|
||||
for (var k = 0; k < layerNames.length; k++) {
|
||||
var layname = layerNames[k];
|
||||
var 贴图位置 = app.activeDocument.layerSets.getByName("贴图位置").layers.getByName(layname);
|
||||
app.activeDocument.activeLayer = 贴图位置;
|
||||
载入选区();
|
||||
填充图案(当前文档名称);
|
||||
栅格化图层()
|
||||
取消链接蒙版()
|
||||
var 水平 = 水平基数 + 水平增量 * k;
|
||||
var 垂直 = 垂直基数 + 垂直增量 * k;
|
||||
位移(水平, 垂直);
|
||||
}
|
||||
|
||||
var saveFile = new File(targetFolder.fullName + "/" + file.name.replace(/\.[^\.]+$/, "") + ".tif");
|
||||
var tiffSaveOptions = new TiffSaveOptions();
|
||||
tiffSaveOptions.imageCompression = TIFFEncoding.NONE; // 或者根据需要设置其他压缩选项
|
||||
tiffSaveOptions.alphaChannels = true;
|
||||
tiffSaveOptions.layers = true;
|
||||
app.activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
|
||||
|
||||
// 关闭当前文档
|
||||
历史记录回退到快照1()
|
||||
} catch (e) {
|
||||
alert("无法打开文件: " + file.name + "\n错误信息: " + e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
alert("换图完成")
|
||||
} else {
|
||||
alert("没有选择文件夹");
|
||||
}
|
||||
|
||||
// 其他函数保持不变
|
||||
|
||||
|
||||
function generateRandomNumber(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 图像大小() //图像大小
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putUnitDouble(stringIDToTypeID("resolution"), stringIDToTypeID("densityUnit"), 150);
|
||||
d.putBoolean(stringIDToTypeID("scaleStyles"), true);
|
||||
d.putBoolean(stringIDToTypeID("constrainProportions"), true);
|
||||
d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("nearestNeighbor"));
|
||||
executeAction(stringIDToTypeID("imageSize"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 取消链接蒙版() //取消链接蒙版
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putBoolean(stringIDToTypeID("userMaskLinked"), false);
|
||||
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("layer"), d1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 栅格化图层() //栅格化图层
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("rasterizeLayer"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 预设图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("pattern"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
|
||||
r1.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("using"), r1);
|
||||
d.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
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("channel"), stringIDToTypeID("transparencyEnum"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 填充图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("contentLayer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
var d2 = new ActionDescriptor();
|
||||
var d3 = new ActionDescriptor();
|
||||
d3.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
|
||||
d2.putObject(stringIDToTypeID("pattern"), stringIDToTypeID("pattern"), d3);
|
||||
d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("patternLayer"), d2);
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("contentLayer"), d1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 位移(水平,垂直) //位移
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putInteger(stringIDToTypeID("horizontal"), 水平);
|
||||
d.putInteger(stringIDToTypeID("vertical"), 垂直);
|
||||
d.putEnumerated(stringIDToTypeID("fill"), stringIDToTypeID("fillMode"), stringIDToTypeID("wrap"));
|
||||
executeAction(stringIDToTypeID("offset"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 历史记录回退到快照1() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("snapshotClass"), "快照 1");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 建立快照() //打开
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("snapshotClass"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("historyState"), stringIDToTypeID("currentHistoryState"));
|
||||
d.putReference(stringIDToTypeID("from"), r1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
}
|
||||
363
PSMARK代码块/新的米样拼贴(11.15).jsx
Normal file
363
PSMARK代码块/新的米样拼贴(11.15).jsx
Normal file
@@ -0,0 +1,363 @@
|
||||
// 设置单位为像素
|
||||
自动米样拼贴()
|
||||
function 自动米样拼贴(){
|
||||
|
||||
var dialog = new Window("dialog");
|
||||
|
||||
|
||||
dialog.text = "SO自动米样拼贴";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "源图像";
|
||||
panel1.preferredSize.width = 388;
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "使用:";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = panel1.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var button1 = group2.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "选取";
|
||||
|
||||
var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}');
|
||||
edittext1.text = "[选择图像文件夹]";
|
||||
edittext1.preferredSize.width = 300;
|
||||
|
||||
// PANEL2
|
||||
// ======
|
||||
var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});
|
||||
panel2.text = "SO小样文档";
|
||||
panel2.preferredSize.height = 160;
|
||||
panel2.orientation = "column";
|
||||
panel2.alignChildren = ["left","top"];
|
||||
panel2.spacing = 10;
|
||||
panel2.margins = 10;
|
||||
|
||||
var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "设定:";
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = panel2.add("group", undefined, {name: "group3"});
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "幅宽(cm):";
|
||||
|
||||
var edittext2 = group3.add('edittext {properties: {name: "edittext2"}}');
|
||||
edittext2.preferredSize.width = 100;
|
||||
|
||||
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = panel2.add("group", undefined, {name: "group4"});
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
// GROUP5
|
||||
// ======
|
||||
var group5 = group1.add("group", undefined, {name: "group5"});
|
||||
group5.orientation = "row";
|
||||
group5.alignChildren = ["left","center"];
|
||||
group5.spacing = 10;
|
||||
group5.margins = 0;
|
||||
|
||||
// PANEL3
|
||||
// ======
|
||||
|
||||
|
||||
// GROUP7
|
||||
// ======
|
||||
var group7 = dialog.add("group", undefined, {name: "group7"});
|
||||
group7.orientation = "column";
|
||||
group7.alignChildren = ["fill","top"];
|
||||
group7.spacing = 10;
|
||||
group7.margins = 0;
|
||||
|
||||
var ok = group7.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "确认";
|
||||
|
||||
var cancel = group7.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var dialog = new Window("dialog");
|
||||
dialog.text = "SO自动米样拼贴";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "源图像";
|
||||
panel1.preferredSize.width = 388;
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "使用:";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = panel1.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var button1 = group2.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "选取";
|
||||
|
||||
var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}');
|
||||
edittext1.text = "[选择图像文件夹]";
|
||||
edittext1.preferredSize.width = 300;
|
||||
|
||||
// PANEL2
|
||||
// ======
|
||||
var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});
|
||||
panel2.text = "SO小样文档拼贴";
|
||||
panel2.preferredSize.height = 160;
|
||||
panel2.orientation = "column";
|
||||
panel2.alignChildren = ["left","top"];
|
||||
panel2.spacing = 10;
|
||||
panel2.margins = 10;
|
||||
|
||||
var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "设定:";
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = panel2.add("group", undefined, {name: "group3"});
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "幅宽(cm):";
|
||||
|
||||
var edittext2 = group3.add('edittext {properties: {name: "edittext2"}}');
|
||||
edittext2.preferredSize.width = 100;
|
||||
|
||||
|
||||
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = panel2.add("group", undefined, {name: "group4"});
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
// GROUP5
|
||||
// ======
|
||||
var group5 = group1.add("group", undefined, {name: "group5"});
|
||||
group5.orientation = "row";
|
||||
group5.alignChildren = ["left","center"];
|
||||
group5.spacing = 10;
|
||||
group5.margins = 0;
|
||||
|
||||
// PANEL3
|
||||
// ======
|
||||
|
||||
|
||||
// GROUP7
|
||||
// ======
|
||||
var group7 = dialog.add("group", undefined, {name: "group7"});
|
||||
group7.orientation = "column";
|
||||
group7.alignChildren = ["fill","top"];
|
||||
group7.spacing = 10;
|
||||
group7.margins = 0;
|
||||
|
||||
var ok = group7.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "确认";
|
||||
|
||||
var cancel = group7.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
|
||||
|
||||
|
||||
|
||||
button1.onClick = function () {
|
||||
// 打开文件夹选择对话框
|
||||
var selectedFolder = Folder.selectDialog("选择图像文件夹");
|
||||
|
||||
// 检查用户是否取消了选择
|
||||
if (selectedFolder) {
|
||||
// 将选择的文件夹路径显示在输入框中
|
||||
edittext1.text = selectedFolder.fsName;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
ok.onClick = function () {
|
||||
app.preferences.rulerUnits = Units.PIXELS;
|
||||
//function 创建拼贴图(导入文件夹路径, 文档宽度厘米) {
|
||||
|
||||
// 假设这些值是从某处获取或者用户输入的
|
||||
var 导入文件夹路径 =new Folder (edittext1.text);
|
||||
var 文档宽度厘米 = Number(edittext2.text);
|
||||
var 文档高度厘米 = 6000; // 例如,50厘米
|
||||
var 分辨率 = 150; // 分辨率设置为150 DPI
|
||||
|
||||
// 转换厘米到像素
|
||||
var 厘米到像素的转换系数 = 2.54;
|
||||
var 文档宽度像素 = 文档宽度厘米 / 厘米到像素的转换系数 * 分辨率;
|
||||
var 文档高度像素 = 文档高度厘米 / 厘米到像素的转换系数 * 分辨率;
|
||||
|
||||
var 导入文件夹 = new Folder(导入文件夹路径);
|
||||
var 文件列表 = 导入文件夹.getFiles("*.*");
|
||||
var 文件名数组 = new Array();
|
||||
var 文件宽度数组 = new Array();
|
||||
var 文件高度数组 = new Array();
|
||||
|
||||
|
||||
// 读取文件列表并获取文件信息
|
||||
for (var 索引1 = 0; 索引1 < 文件列表.length; 索引1++) {
|
||||
var 文档 = app.open(文件列表[索引1]);
|
||||
文件名数组[索引1] = 文档.fullName;
|
||||
文件宽度数组[索引1] = parseInt(文档.width);
|
||||
文件高度数组[索引1] = parseInt(文档.height);
|
||||
文档.close();
|
||||
}
|
||||
|
||||
// 根据高度对文件进行排序
|
||||
for (var 索引1 = 文件高度数组.length - 1; 索引1 > 0; --索引1) {
|
||||
for (var 索引2 = 0; 索引2 < 索引1; ++索引2) {
|
||||
if (文件高度数组[索引2] > 文件高度数组[索引2 + 1])
|
||||
交换数组元素(索引2, 索引2 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
function 交换数组元素(索引1, 索引2) {
|
||||
var 临时 = 文件高度数组[索引1];
|
||||
文件高度数组[索引1] = 文件高度数组[索引2];
|
||||
文件高度数组[索引2] = 临时;
|
||||
|
||||
var 临时2 = 文件宽度数组[索引1];
|
||||
文件宽度数组[索引1] = 文件宽度数组[索引2];
|
||||
文件宽度数组[索引2] = 临时2;
|
||||
|
||||
var 临时3 = 文件名数组[索引1];
|
||||
文件名数组[索引1] = 文件名数组[索引2];
|
||||
文件名数组[索引2] = 临时3;
|
||||
}
|
||||
|
||||
// 创建新文档并添加图片
|
||||
var 新文档 = app.documents.add(文档宽度像素, 文档高度像素, 分辨率, "拼贴", NewDocumentMode.CMYK, DocumentFill.WHITE);
|
||||
var 当前顶部 = 0;
|
||||
var 当前左侧 = 0;
|
||||
for (var 索引1 = 0; 索引1 < 文件名数组.length; 索引1++) {
|
||||
var 文档 = app.open(文件名数组[索引1]);
|
||||
文档.selection.selectAll();
|
||||
文档.selection.copy();
|
||||
文档.close();
|
||||
|
||||
if ((当前左侧 + 文件宽度数组[索引1]) > 文档宽度像素) {
|
||||
当前左侧 = 0;
|
||||
当前顶部 += 文件高度数组[索引1 - 1];
|
||||
}
|
||||
|
||||
var 边界 = [
|
||||
[当前左侧, 当前顶部],
|
||||
[当前左侧 + 文件宽度数组[索引1], 当前顶部],
|
||||
[当前左侧 + 文件宽度数组[索引1], 当前顶部 + 文件高度数组[索引1]],
|
||||
[当前左侧, 当前顶部 + 文件高度数组[索引1]]
|
||||
];
|
||||
新文档.selection.select(边界, SelectionType.REPLACE, 0, true);
|
||||
新文档.paste();
|
||||
当前左侧 += 文件宽度数组[索引1];
|
||||
}
|
||||
|
||||
// 选择输出文件夹并保存图片
|
||||
var 输出文件夹 = new Folder(edittext1.text + "/拼贴");
|
||||
if (!输出文件夹.exists) 输出文件夹.create();
|
||||
|
||||
// 设置TIFF保存选项
|
||||
var tiffSaveOptions = new TiffSaveOptions();
|
||||
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW; // 使用LZW压缩
|
||||
tiffSaveOptions.byteOrder = ByteOrder.IBM; // 设置字节顺序为IBM(大端序)
|
||||
|
||||
// 定义保存的文件路径和名称
|
||||
var 文件 = new File(输出文件夹 + "/combined.tif");
|
||||
|
||||
// 保存当前文档为TIFF格式
|
||||
新文档.saveAs(文件, tiffSaveOptions, true, Extension.LOWERCASE);
|
||||
裁切透明像素();
|
||||
|
||||
// 关闭文档,不保存更改
|
||||
//新文档.close(SaveOptions.DONOTSAVECHANGES);
|
||||
dialog.close();
|
||||
alert("拼贴完成")
|
||||
|
||||
}
|
||||
|
||||
function 裁切透明像素() {
|
||||
var 文档 = app.activeDocument; // 获取当前活动的文档
|
||||
|
||||
// 裁切透明像素
|
||||
// TrimType.TOPLEFT 表示从图像的左上角开始裁切
|
||||
// 第二个参数 true 表示裁切顶部的透明像素
|
||||
// 第三个参数 true 表示裁切左侧的透明像素
|
||||
// 第四个参数 true 表示裁切底部的透明像素
|
||||
// 第五个参数 true 表示裁切右侧的透明像素
|
||||
文档.trim(TrimType.TOPLEFT, true, true, true, true);
|
||||
}
|
||||
|
||||
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
459
PSMARK代码块/新的米样拼贴.jsx
Normal file
459
PSMARK代码块/新的米样拼贴.jsx
Normal file
@@ -0,0 +1,459 @@
|
||||
|
||||
|
||||
var dialog = new Window("dialog");
|
||||
|
||||
dialog.text = "S/O样自动连晒";
|
||||
//dialog.text = "SO自动米样拼贴";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "源图像";
|
||||
panel1.preferredSize.width = 388;
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "使用:";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = panel1.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var button1 = group2.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "选取";
|
||||
|
||||
var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}');
|
||||
edittext1.text = "[选择图像文件夹]";
|
||||
edittext1.preferredSize.width = 300;
|
||||
|
||||
// PANEL2
|
||||
// ======
|
||||
var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});
|
||||
panel2.text = "SO小样文档";
|
||||
panel2.preferredSize.height = 160;
|
||||
panel2.orientation = "column";
|
||||
panel2.alignChildren = ["left","top"];
|
||||
panel2.spacing = 10;
|
||||
panel2.margins = 10;
|
||||
|
||||
var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "设定:";
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = panel2.add("group", undefined, {name: "group3"});
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "宽度(cm):";
|
||||
|
||||
var edittext2 = group3.add('edittext {properties: {name: "edittext2"}}');
|
||||
edittext2.preferredSize.width = 100;
|
||||
|
||||
var statictext4 = group3.add("statictext", undefined, undefined, {name: "statictext4"});
|
||||
statictext4.text = "高度(cm):";
|
||||
|
||||
var edittext3 = group3.add('edittext {properties: {name: "edittext3"}}');
|
||||
edittext3.preferredSize.width = 100;
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = panel2.add("group", undefined, {name: "group4"});
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
// GROUP5
|
||||
// ======
|
||||
var group5 = group1.add("group", undefined, {name: "group5"});
|
||||
group5.orientation = "row";
|
||||
group5.alignChildren = ["left","center"];
|
||||
group5.spacing = 10;
|
||||
group5.margins = 0;
|
||||
|
||||
// PANEL3
|
||||
// ======
|
||||
|
||||
|
||||
// GROUP7
|
||||
// ======
|
||||
var group7 = dialog.add("group", undefined, {name: "group7"});
|
||||
group7.orientation = "column";
|
||||
group7.alignChildren = ["fill","top"];
|
||||
group7.spacing = 10;
|
||||
group7.margins = 0;
|
||||
|
||||
var ok = group7.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "确认";
|
||||
|
||||
var cancel = group7.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
button1.onClick = function () {
|
||||
// 打开文件夹选择对话框
|
||||
var selectedFolder = Folder.selectDialog("选择图像文件夹");
|
||||
|
||||
// 检查用户是否取消了选择
|
||||
if (selectedFolder) {
|
||||
// 将选择的文件夹路径显示在输入框中
|
||||
edittext1.text = selectedFolder.fsName;
|
||||
}
|
||||
};
|
||||
|
||||
ok.onClick = function () {
|
||||
app.preferences.rulerUnits = Units.PIXELS;
|
||||
var 素材图片文件夹 = new Folder(edittext1.text);
|
||||
var 遍历tiff = 素材图片文件夹.getFiles("*.*");
|
||||
|
||||
// 新建文件夹
|
||||
var 新文件夹 = new Folder(edittext1.text + "/SO小样拼贴");
|
||||
新文件夹.create();
|
||||
var 新加字文件夹 = new Folder(edittext1.text + "/SO小样拼贴加字");
|
||||
新加字文件夹.create();
|
||||
|
||||
|
||||
宽度=Number (edittext2.text);
|
||||
高度=Number (edittext3.text);
|
||||
|
||||
|
||||
for (var i = 0; i < 遍历tiff.length; i++) {
|
||||
if (遍历tiff[i] instanceof File) {
|
||||
app.open(遍历tiff[i]);
|
||||
app.activeDocument.flatten();
|
||||
var 当前文档 = app.activeDocument;
|
||||
var 当前文档名称 = 当前文档.name;
|
||||
图像大小()
|
||||
预设图案(当前文档名称);
|
||||
app.activeDocument.crop([UnitValue("0px"), UnitValue("0px"), UnitValue(宽度, "cm"), UnitValue(高度, "cm")]);
|
||||
填充图案(当前文档名称);
|
||||
app.activeDocument.flatten();
|
||||
画布扩展()
|
||||
// 保存新的图像文件到新建的文件夹中
|
||||
var 保存路径 = 新文件夹 + "/" + 当前文档名称;
|
||||
var tifSaveOpt = new TiffSaveOptions();
|
||||
tifSaveOpt.imageCompression = TIFFEncoding.TIFFLZW;
|
||||
tifSaveOpt.byteOrder = ByteOrder.IBM;
|
||||
var asCopy = true;
|
||||
app.activeDocument.saveAs(new File(保存路径), tifSaveOpt, asCopy);
|
||||
创建并处理文本图层();
|
||||
app.activeDocument.flatten();
|
||||
var 保存路径 = 新加字文件夹 + "/" + 当前文档名称;
|
||||
var tifSaveOpt = new TiffSaveOptions();
|
||||
tifSaveOpt.imageCompression = TIFFEncoding.TIFFLZW;
|
||||
tifSaveOpt.byteOrder = ByteOrder.IBM;
|
||||
var asCopy = true;
|
||||
app.activeDocument.saveAs(new File(保存路径), tifSaveOpt, asCopy);
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
alert("小样连晒完成")
|
||||
// 创建并保存拼贴图像(新文件夹, 幅宽)
|
||||
};
|
||||
|
||||
|
||||
|
||||
function 预设图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("pattern"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
|
||||
r1.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("using"), r1);
|
||||
d.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 填充图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("contentLayer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
var d2 = new ActionDescriptor();
|
||||
var d3 = new ActionDescriptor();
|
||||
d3.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
|
||||
d2.putObject(stringIDToTypeID("pattern"), stringIDToTypeID("pattern"), d3);
|
||||
d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("patternLayer"), d2);
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("contentLayer"), d1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 图像大小()
|
||||
{
|
||||
var d = new ActionDescriptor();
|
||||
d.putUnitDouble(stringIDToTypeID("resolution"), stringIDToTypeID("densityUnit"), 150);
|
||||
d.putBoolean(stringIDToTypeID("scaleStyles"), true);
|
||||
d.putBoolean(stringIDToTypeID("constrainProportions"), true);
|
||||
d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("automaticInterpolation"));
|
||||
executeAction(stringIDToTypeID("imageSize"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 画布扩展() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putBoolean(stringIDToTypeID("relative"), true);
|
||||
d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("distanceUnit"), 14.4);
|
||||
d.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("distanceUnit"), 14.4);
|
||||
d.putEnumerated(stringIDToTypeID("horizontal"), stringIDToTypeID("horizontalLocation"), stringIDToTypeID("center"));
|
||||
d.putEnumerated(stringIDToTypeID("vertical"), stringIDToTypeID("verticalLocation"), stringIDToTypeID("center"));
|
||||
d.putEnumerated(stringIDToTypeID("canvasExtensionColorType"), stringIDToTypeID("canvasExtensionColorType"), stringIDToTypeID("color"));
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putDouble(stringIDToTypeID("red"), 255);
|
||||
d1.putDouble(stringIDToTypeID("green"), 255);
|
||||
d1.putDouble(stringIDToTypeID("blue"), 255);
|
||||
d.putObject(stringIDToTypeID("canvasExtensionColor"), stringIDToTypeID("RGBColor"), d1);
|
||||
executeAction(stringIDToTypeID("canvasSize"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 创建并处理文本图层() {
|
||||
// 新建图层
|
||||
var textLayer = activeDocument.artLayers.add();
|
||||
|
||||
// 将新建图层变成文本图层
|
||||
textLayer.kind = LayerKind.TEXT;
|
||||
|
||||
// 将文本内容改为当前文档name
|
||||
textLayer.textItem.contents = activeDocument.name;
|
||||
|
||||
// 字体大小固定值
|
||||
var 固定字体大小 = 30; // 例如,30像素
|
||||
textLayer.textItem.size = 固定字体大小;
|
||||
|
||||
// 文字字体固定值
|
||||
textLayer.textItem.font = "微软雅黑";
|
||||
|
||||
// 计算并调整文本位置
|
||||
var x = activeDocument.width - textLayer.bounds[2];
|
||||
var y = textLayer.bounds[1];
|
||||
textLayer.translate(x, -y);
|
||||
|
||||
// 偏移
|
||||
textLayer.translate(UnitValue("-1cm"), UnitValue("+0.5cm"));
|
||||
|
||||
// 复制并栅格化图层
|
||||
var copyLayer = textLayer.duplicate();
|
||||
copyLayer.rasterize(RasterizeType.ENTIRELAYER);
|
||||
|
||||
// 设置固定颜色值
|
||||
var 固定颜色 = new SolidColor();
|
||||
固定颜色.rgb.red = 255; // 红色分量
|
||||
固定颜色.rgb.green = 255; // 绿色分量
|
||||
固定颜色.rgb.blue = 255; // 蓝色分量
|
||||
|
||||
activeDocument.activeLayer = copyLayer;
|
||||
activeDocument.selection.fill(固定颜色, ColorBlendMode.NORMAL, 100, true);
|
||||
|
||||
// 白边
|
||||
activeDocument.activeLayer.applyMinimum(10);
|
||||
后移一层()
|
||||
向上选择()
|
||||
向下合并()
|
||||
名称更改字体()
|
||||
缩小字体图层至文档一半()
|
||||
多选背景()
|
||||
底对齐()
|
||||
水平居中对齐()
|
||||
}
|
||||
|
||||
// 调用函数
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 后移一层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("previous"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("move"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 向上选择() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("forwardEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(19);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
function 向下合并() //向下合并
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 名称更改字体() //名称更改
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putString(stringIDToTypeID("name"), "字体");
|
||||
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("layer"), d1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 缩小字体图层至文档一半() {
|
||||
var 文档 = app.activeDocument;
|
||||
var 字体图层 = null;
|
||||
|
||||
// 遍历文档中的图层以找到名为"字体"的图层
|
||||
for (var i = 0; i < 文档.artLayers.length; i++) {
|
||||
if (文档.artLayers[i].name === "字体") {
|
||||
字体图层 = 文档.artLayers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (字体图层 !== null) {
|
||||
// 获取文档的宽度的一半
|
||||
var 目标宽度 = 文档.width / 2;
|
||||
|
||||
// 获取图层的当前宽度
|
||||
var 图层宽度 = 字体图层.bounds[2] - 字体图层.bounds[0];
|
||||
|
||||
// 计算缩放比例
|
||||
var 缩放比例 = 目标宽度 / 图层宽度 * 100;
|
||||
|
||||
// 缩放图层
|
||||
字体图层.resize(缩放比例, 缩放比例, AnchorPosition.MIDDLECENTER);
|
||||
} else {
|
||||
alert("未找到名为'字体'的图层");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function 多选背景() //自由变换
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("layer"), "背景");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(1);
|
||||
list.putInteger(13);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 底对齐() //底对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSBottoms"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 水平居中对齐() //水平居中对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSCentersH"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 设置单位为像素
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
dialog.show();
|
||||
|
||||
489
PSMARK代码块/新的米样缩放.jsx
Normal file
489
PSMARK代码块/新的米样缩放.jsx
Normal file
@@ -0,0 +1,489 @@
|
||||
新的米样缩放()
|
||||
|
||||
|
||||
|
||||
function 新的米样缩放()
|
||||
{
|
||||
var dialog = new Window("dialog");
|
||||
|
||||
dialog.text = "S/O样自动缩放";
|
||||
//dialog.text = "SO自动米样拼贴";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "源图像";
|
||||
panel1.preferredSize.width = 388;
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "使用:";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = panel1.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var button1 = group2.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "选取";
|
||||
|
||||
var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}');
|
||||
edittext1.text = "[选择图像文件夹]";
|
||||
edittext1.preferredSize.width = 300;
|
||||
|
||||
// PANEL2
|
||||
// ======
|
||||
var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});
|
||||
panel2.text = "SO小样文档";
|
||||
panel2.preferredSize.height = 160;
|
||||
panel2.orientation = "column";
|
||||
panel2.alignChildren = ["left","top"];
|
||||
panel2.spacing = 10;
|
||||
panel2.margins = 10;
|
||||
|
||||
var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "设定:";
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = panel2.add("group", undefined, {name: "group3"});
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "宽度(cm):";
|
||||
|
||||
var edittext2 = group3.add('edittext {properties: {name: "edittext2"}}');
|
||||
edittext2.preferredSize.width = 100;
|
||||
|
||||
var statictext4 = group3.add("statictext", undefined, undefined, {name: "statictext4"});
|
||||
statictext4.text = "高度(cm):";
|
||||
|
||||
var edittext3 = group3.add('edittext {properties: {name: "edittext3"}}');
|
||||
edittext3.preferredSize.width = 100;
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = panel2.add("group", undefined, {name: "group4"});
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
// GROUP5
|
||||
// ======
|
||||
var group5 = group1.add("group", undefined, {name: "group5"});
|
||||
group5.orientation = "row";
|
||||
group5.alignChildren = ["left","center"];
|
||||
group5.spacing = 10;
|
||||
group5.margins = 0;
|
||||
|
||||
// PANEL3
|
||||
// ======
|
||||
|
||||
|
||||
// GROUP7
|
||||
// ======
|
||||
var group7 = dialog.add("group", undefined, {name: "group7"});
|
||||
group7.orientation = "column";
|
||||
group7.alignChildren = ["fill","top"];
|
||||
group7.spacing = 10;
|
||||
group7.margins = 0;
|
||||
|
||||
var ok = group7.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "确认";
|
||||
|
||||
var cancel = group7.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
button1.onClick = function () {
|
||||
// 打开文件夹选择对话框
|
||||
var selectedFolder = Folder.selectDialog("选择图像文件夹");
|
||||
|
||||
// 检查用户是否取消了选择
|
||||
if (selectedFolder) {
|
||||
// 将选择的文件夹路径显示在输入框中
|
||||
edittext1.text = selectedFolder.fsName;
|
||||
}
|
||||
};
|
||||
|
||||
ok.onClick = function () {
|
||||
app.preferences.rulerUnits = Units.PIXELS;
|
||||
var 素材图片文件夹 = new Folder(edittext1.text);
|
||||
var 遍历tiff = 素材图片文件夹.getFiles("*.*");
|
||||
|
||||
// 新建文件夹
|
||||
var 新文件夹 = new Folder(edittext1.text + "/SO小样拼贴");
|
||||
新文件夹.create();
|
||||
var 新加字文件夹 = new Folder(edittext1.text + "/SO小样拼贴加字");
|
||||
新加字文件夹.create();
|
||||
|
||||
|
||||
宽度=Number (edittext2.text);
|
||||
高度=Number (edittext3.text);
|
||||
|
||||
|
||||
for (var i = 0; i < 遍历tiff.length; i++) {
|
||||
if (遍历tiff[i] instanceof File) {
|
||||
app.open(遍历tiff[i]);
|
||||
app.activeDocument.flatten();
|
||||
var 当前文档 = app.activeDocument;
|
||||
var 当前文档名称 = 当前文档.name;
|
||||
resizeImageToCm(宽度, 高度,200);
|
||||
/*
|
||||
图像大小()
|
||||
预设图案(当前文档名称);
|
||||
app.activeDocument.crop([UnitValue("0px"), UnitValue("0px"), UnitValue(宽度, "cm"), UnitValue(高度, "cm")]);
|
||||
填充图案(当前文档名称);
|
||||
app.activeDocument.flatten();
|
||||
画布扩展()
|
||||
*/
|
||||
// 保存新的图像文件到新建的文件夹中
|
||||
var 保存路径 = 新文件夹 + "/" + 当前文档名称;
|
||||
var tifSaveOpt = new TiffSaveOptions();
|
||||
tifSaveOpt.imageCompression = TIFFEncoding.TIFFLZW;
|
||||
tifSaveOpt.byteOrder = ByteOrder.IBM;
|
||||
var asCopy = true;
|
||||
app.activeDocument.saveAs(new File(保存路径), tifSaveOpt, asCopy);
|
||||
创建并处理文本图层();
|
||||
app.activeDocument.flatten();
|
||||
var 保存路径 = 新加字文件夹 + "/" + 当前文档名称;
|
||||
var tifSaveOpt = new TiffSaveOptions();
|
||||
tifSaveOpt.imageCompression = TIFFEncoding.TIFFLZW;
|
||||
tifSaveOpt.byteOrder = ByteOrder.IBM;
|
||||
var asCopy = true;
|
||||
app.activeDocument.saveAs(new File(保存路径), tifSaveOpt, asCopy);
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//alert("小样连晒完成")
|
||||
dialog.close();
|
||||
// 创建并保存拼贴图像(新文件夹, 幅宽)
|
||||
};
|
||||
|
||||
|
||||
function resizeImageToCm(widthCm, heightCm, resolution) {
|
||||
// 将厘米转换为像素
|
||||
var widthInPixels = widthCm * (resolution / 2.54);
|
||||
var heightInPixels = heightCm * (resolution / 2.54);
|
||||
|
||||
// 调整图像大小
|
||||
app.activeDocument.resizeImage(widthInPixels, heightInPixels, resolution, ResampleMethod.NEARESTNEIGHBOR);
|
||||
}
|
||||
|
||||
// 使用示例:将图像大小调整为 10cm x 15cm,分辨率为 300 像素/英寸
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 预设图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("pattern"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
|
||||
r1.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("using"), r1);
|
||||
d.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 填充图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("contentLayer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
var d2 = new ActionDescriptor();
|
||||
var d3 = new ActionDescriptor();
|
||||
d3.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
|
||||
d2.putObject(stringIDToTypeID("pattern"), stringIDToTypeID("pattern"), d3);
|
||||
d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("patternLayer"), d2);
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("contentLayer"), d1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 图像大小() //图像大小
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putUnitDouble(stringIDToTypeID("resolution"), stringIDToTypeID("densityUnit"), 200);
|
||||
d.putBoolean(stringIDToTypeID("scaleStyles"), true);
|
||||
d.putBoolean(stringIDToTypeID("constrainProportions"), true);
|
||||
d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("nearestNeighbor"));
|
||||
executeAction(stringIDToTypeID("imageSize"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 画布扩展() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putBoolean(stringIDToTypeID("relative"), true);
|
||||
d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("distanceUnit"), 14.4);
|
||||
d.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("distanceUnit"), 14.4);
|
||||
d.putEnumerated(stringIDToTypeID("horizontal"), stringIDToTypeID("horizontalLocation"), stringIDToTypeID("center"));
|
||||
d.putEnumerated(stringIDToTypeID("vertical"), stringIDToTypeID("verticalLocation"), stringIDToTypeID("center"));
|
||||
d.putEnumerated(stringIDToTypeID("canvasExtensionColorType"), stringIDToTypeID("canvasExtensionColorType"), stringIDToTypeID("color"));
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putDouble(stringIDToTypeID("red"), 255);
|
||||
d1.putDouble(stringIDToTypeID("green"), 255);
|
||||
d1.putDouble(stringIDToTypeID("blue"), 255);
|
||||
d.putObject(stringIDToTypeID("canvasExtensionColor"), stringIDToTypeID("RGBColor"), d1);
|
||||
executeAction(stringIDToTypeID("canvasSize"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 创建并处理文本图层() {
|
||||
// 新建图层
|
||||
var textLayer = activeDocument.artLayers.add();
|
||||
|
||||
// 将新建图层变成文本图层
|
||||
textLayer.kind = LayerKind.TEXT;
|
||||
|
||||
// 将文本内容改为当前文档name
|
||||
textLayer.textItem.contents = activeDocument.name;
|
||||
|
||||
// 字体大小固定值
|
||||
var 固定字体大小 = 30; // 例如,30像素
|
||||
textLayer.textItem.size = 固定字体大小;
|
||||
|
||||
// 文字字体固定值
|
||||
textLayer.textItem.font = "微软雅黑";
|
||||
|
||||
// 计算并调整文本位置
|
||||
var x = activeDocument.width - textLayer.bounds[2];
|
||||
var y = textLayer.bounds[1];
|
||||
textLayer.translate(x, -y);
|
||||
|
||||
// 偏移
|
||||
textLayer.translate(UnitValue("-1cm"), UnitValue("+0.5cm"));
|
||||
|
||||
// 复制并栅格化图层
|
||||
var copyLayer = textLayer.duplicate();
|
||||
copyLayer.rasterize(RasterizeType.ENTIRELAYER);
|
||||
|
||||
// 设置固定颜色值
|
||||
var 固定颜色 = new SolidColor();
|
||||
固定颜色.rgb.red = 255; // 红色分量
|
||||
固定颜色.rgb.green = 255; // 绿色分量
|
||||
固定颜色.rgb.blue = 255; // 蓝色分量
|
||||
|
||||
activeDocument.activeLayer = copyLayer;
|
||||
activeDocument.selection.fill(固定颜色, ColorBlendMode.NORMAL, 100, true);
|
||||
|
||||
// 白边
|
||||
activeDocument.activeLayer.applyMinimum(10);
|
||||
后移一层()
|
||||
向上选择()
|
||||
向下合并()
|
||||
名称更改字体()
|
||||
缩小字体图层至文档一半()
|
||||
多选背景()
|
||||
底对齐()
|
||||
水平居中对齐()
|
||||
}
|
||||
|
||||
// 调用函数
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 后移一层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("previous"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("move"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 向上选择() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("forwardEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(19);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
function 向下合并() //向下合并
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 名称更改字体() //名称更改
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putString(stringIDToTypeID("name"), "字体");
|
||||
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("layer"), d1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 缩小字体图层至文档一半() {
|
||||
var 文档 = app.activeDocument;
|
||||
var 字体图层 = null;
|
||||
|
||||
// 遍历文档中的图层以找到名为"字体"的图层
|
||||
for (var i = 0; i < 文档.artLayers.length; i++) {
|
||||
if (文档.artLayers[i].name === "字体") {
|
||||
字体图层 = 文档.artLayers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (字体图层 !== null) {
|
||||
// 获取文档的宽度的一半
|
||||
var 目标宽度 = 文档.width / 2;
|
||||
|
||||
// 获取图层的当前宽度
|
||||
var 图层宽度 = 字体图层.bounds[2] - 字体图层.bounds[0];
|
||||
|
||||
// 计算缩放比例
|
||||
var 缩放比例 = 目标宽度 / 图层宽度 * 100;
|
||||
|
||||
// 缩放图层
|
||||
字体图层.resize(缩放比例, 缩放比例, AnchorPosition.MIDDLECENTER);
|
||||
} else {
|
||||
alert("未找到名为'字体'的图层");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function 多选背景() //自由变换
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("layer"), "背景");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(1);
|
||||
list.putInteger(13);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 底对齐() //底对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSBottoms"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 水平居中对齐() //水平居中对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSCentersH"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 设置单位为像素
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
|
||||
461
PSMARK代码块/新的米样连晒.jsx
Normal file
461
PSMARK代码块/新的米样连晒.jsx
Normal file
@@ -0,0 +1,461 @@
|
||||
|
||||
|
||||
var dialog = new Window("dialog");
|
||||
|
||||
dialog.text = "S/O样自动连晒";
|
||||
//dialog.text = "SO自动米样拼贴";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "源图像";
|
||||
panel1.preferredSize.width = 388;
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "使用:";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = panel1.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var button1 = group2.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "选取";
|
||||
|
||||
var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}');
|
||||
edittext1.text = "[选择图像文件夹]";
|
||||
edittext1.preferredSize.width = 300;
|
||||
|
||||
// PANEL2
|
||||
// ======
|
||||
var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});
|
||||
panel2.text = "SO小样文档";
|
||||
panel2.preferredSize.height = 160;
|
||||
panel2.orientation = "column";
|
||||
panel2.alignChildren = ["left","top"];
|
||||
panel2.spacing = 10;
|
||||
panel2.margins = 10;
|
||||
|
||||
var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "设定:";
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = panel2.add("group", undefined, {name: "group3"});
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "宽度(cm):";
|
||||
|
||||
var edittext2 = group3.add('edittext {properties: {name: "edittext2"}}');
|
||||
edittext2.preferredSize.width = 100;
|
||||
|
||||
var statictext4 = group3.add("statictext", undefined, undefined, {name: "statictext4"});
|
||||
statictext4.text = "高度(cm):";
|
||||
|
||||
var edittext3 = group3.add('edittext {properties: {name: "edittext3"}}');
|
||||
edittext3.preferredSize.width = 100;
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = panel2.add("group", undefined, {name: "group4"});
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
// GROUP5
|
||||
// ======
|
||||
var group5 = group1.add("group", undefined, {name: "group5"});
|
||||
group5.orientation = "row";
|
||||
group5.alignChildren = ["left","center"];
|
||||
group5.spacing = 10;
|
||||
group5.margins = 0;
|
||||
|
||||
// PANEL3
|
||||
// ======
|
||||
|
||||
|
||||
// GROUP7
|
||||
// ======
|
||||
var group7 = dialog.add("group", undefined, {name: "group7"});
|
||||
group7.orientation = "column";
|
||||
group7.alignChildren = ["fill","top"];
|
||||
group7.spacing = 10;
|
||||
group7.margins = 0;
|
||||
|
||||
var ok = group7.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "确认";
|
||||
|
||||
var cancel = group7.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
button1.onClick = function () {
|
||||
// 打开文件夹选择对话框
|
||||
var selectedFolder = Folder.selectDialog("选择图像文件夹");
|
||||
|
||||
// 检查用户是否取消了选择
|
||||
if (selectedFolder) {
|
||||
// 将选择的文件夹路径显示在输入框中
|
||||
edittext1.text = selectedFolder.fsName;
|
||||
}
|
||||
};
|
||||
|
||||
ok.onClick = function () {
|
||||
app.preferences.rulerUnits = Units.PIXELS;
|
||||
var 素材图片文件夹 = new Folder(edittext1.text);
|
||||
var 遍历tiff = 素材图片文件夹.getFiles("*.*");
|
||||
|
||||
// 新建文件夹
|
||||
var 新文件夹 = new Folder(edittext1.text + "/SO小样拼贴");
|
||||
新文件夹.create();
|
||||
var 新加字文件夹 = new Folder(edittext1.text + "/SO小样拼贴加字");
|
||||
新加字文件夹.create();
|
||||
|
||||
|
||||
宽度=Number (edittext2.text);
|
||||
高度=Number (edittext3.text);
|
||||
|
||||
|
||||
for (var i = 0; i < 遍历tiff.length; i++) {
|
||||
if (遍历tiff[i] instanceof File) {
|
||||
app.open(遍历tiff[i]);
|
||||
app.activeDocument.flatten();
|
||||
var 当前文档 = app.activeDocument;
|
||||
var 当前文档名称 = 当前文档.name;
|
||||
图像大小()
|
||||
预设图案(当前文档名称);
|
||||
app.activeDocument.crop([UnitValue("0px"), UnitValue("0px"), UnitValue(宽度, "cm"), UnitValue(高度, "cm")]);
|
||||
填充图案(当前文档名称);
|
||||
app.activeDocument.flatten();
|
||||
画布扩展()
|
||||
// 保存新的图像文件到新建的文件夹中
|
||||
var 保存路径 = 新文件夹 + "/" + 当前文档名称;
|
||||
var tifSaveOpt = new TiffSaveOptions();
|
||||
tifSaveOpt.imageCompression = TIFFEncoding.TIFFLZW;
|
||||
tifSaveOpt.byteOrder = ByteOrder.IBM;
|
||||
var asCopy = true;
|
||||
app.activeDocument.saveAs(new File(保存路径), tifSaveOpt, asCopy);
|
||||
创建并处理文本图层();
|
||||
app.activeDocument.flatten();
|
||||
var 保存路径 = 新加字文件夹 + "/" + 当前文档名称;
|
||||
var tifSaveOpt = new TiffSaveOptions();
|
||||
tifSaveOpt.imageCompression = TIFFEncoding.TIFFLZW;
|
||||
tifSaveOpt.byteOrder = ByteOrder.IBM;
|
||||
var asCopy = true;
|
||||
app.activeDocument.saveAs(new File(保存路径), tifSaveOpt, asCopy);
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
alert("小样连晒完成")
|
||||
// 创建并保存拼贴图像(新文件夹, 幅宽)
|
||||
};
|
||||
|
||||
|
||||
|
||||
function 预设图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("pattern"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
|
||||
r1.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("using"), r1);
|
||||
d.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 填充图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("contentLayer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
var d2 = new ActionDescriptor();
|
||||
var d3 = new ActionDescriptor();
|
||||
d3.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
|
||||
d2.putObject(stringIDToTypeID("pattern"), stringIDToTypeID("pattern"), d3);
|
||||
d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("patternLayer"), d2);
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("contentLayer"), d1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 图像大小() //图像大小
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putUnitDouble(stringIDToTypeID("resolution"), stringIDToTypeID("densityUnit"), 200);
|
||||
d.putBoolean(stringIDToTypeID("scaleStyles"), true);
|
||||
d.putBoolean(stringIDToTypeID("constrainProportions"), true);
|
||||
d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("nearestNeighbor"));
|
||||
executeAction(stringIDToTypeID("imageSize"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 画布扩展() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putBoolean(stringIDToTypeID("relative"), true);
|
||||
d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("distanceUnit"), 14.4);
|
||||
d.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("distanceUnit"), 14.4);
|
||||
d.putEnumerated(stringIDToTypeID("horizontal"), stringIDToTypeID("horizontalLocation"), stringIDToTypeID("center"));
|
||||
d.putEnumerated(stringIDToTypeID("vertical"), stringIDToTypeID("verticalLocation"), stringIDToTypeID("center"));
|
||||
d.putEnumerated(stringIDToTypeID("canvasExtensionColorType"), stringIDToTypeID("canvasExtensionColorType"), stringIDToTypeID("color"));
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putDouble(stringIDToTypeID("red"), 255);
|
||||
d1.putDouble(stringIDToTypeID("green"), 255);
|
||||
d1.putDouble(stringIDToTypeID("blue"), 255);
|
||||
d.putObject(stringIDToTypeID("canvasExtensionColor"), stringIDToTypeID("RGBColor"), d1);
|
||||
executeAction(stringIDToTypeID("canvasSize"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 创建并处理文本图层() {
|
||||
// 新建图层
|
||||
var textLayer = activeDocument.artLayers.add();
|
||||
|
||||
// 将新建图层变成文本图层
|
||||
textLayer.kind = LayerKind.TEXT;
|
||||
|
||||
// 将文本内容改为当前文档name
|
||||
textLayer.textItem.contents = activeDocument.name;
|
||||
|
||||
// 字体大小固定值
|
||||
var 固定字体大小 = 30; // 例如,30像素
|
||||
textLayer.textItem.size = 固定字体大小;
|
||||
|
||||
// 文字字体固定值
|
||||
textLayer.textItem.font = "微软雅黑";
|
||||
|
||||
// 计算并调整文本位置
|
||||
var x = activeDocument.width - textLayer.bounds[2];
|
||||
var y = textLayer.bounds[1];
|
||||
textLayer.translate(x, -y);
|
||||
|
||||
// 偏移
|
||||
textLayer.translate(UnitValue("-1cm"), UnitValue("+0.5cm"));
|
||||
|
||||
// 复制并栅格化图层
|
||||
var copyLayer = textLayer.duplicate();
|
||||
copyLayer.rasterize(RasterizeType.ENTIRELAYER);
|
||||
|
||||
// 设置固定颜色值
|
||||
var 固定颜色 = new SolidColor();
|
||||
固定颜色.rgb.red = 255; // 红色分量
|
||||
固定颜色.rgb.green = 255; // 绿色分量
|
||||
固定颜色.rgb.blue = 255; // 蓝色分量
|
||||
|
||||
activeDocument.activeLayer = copyLayer;
|
||||
activeDocument.selection.fill(固定颜色, ColorBlendMode.NORMAL, 100, true);
|
||||
|
||||
// 白边
|
||||
activeDocument.activeLayer.applyMinimum(10);
|
||||
后移一层()
|
||||
向上选择()
|
||||
向下合并()
|
||||
名称更改字体()
|
||||
缩小字体图层至文档一半()
|
||||
多选背景()
|
||||
底对齐()
|
||||
水平居中对齐()
|
||||
}
|
||||
|
||||
// 调用函数
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 后移一层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("previous"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("move"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 向上选择() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("forwardEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(19);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
function 向下合并() //向下合并
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 名称更改字体() //名称更改
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putString(stringIDToTypeID("name"), "字体");
|
||||
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("layer"), d1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 缩小字体图层至文档一半() {
|
||||
var 文档 = app.activeDocument;
|
||||
var 字体图层 = null;
|
||||
|
||||
// 遍历文档中的图层以找到名为"字体"的图层
|
||||
for (var i = 0; i < 文档.artLayers.length; i++) {
|
||||
if (文档.artLayers[i].name === "字体") {
|
||||
字体图层 = 文档.artLayers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (字体图层 !== null) {
|
||||
// 获取文档的宽度的一半
|
||||
var 目标宽度 = 文档.width / 2;
|
||||
|
||||
// 获取图层的当前宽度
|
||||
var 图层宽度 = 字体图层.bounds[2] - 字体图层.bounds[0];
|
||||
|
||||
// 计算缩放比例
|
||||
var 缩放比例 = 目标宽度 / 图层宽度 * 100;
|
||||
|
||||
// 缩放图层
|
||||
字体图层.resize(缩放比例, 缩放比例, AnchorPosition.MIDDLECENTER);
|
||||
} else {
|
||||
alert("未找到名为'字体'的图层");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function 多选背景() //自由变换
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("layer"), "背景");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(1);
|
||||
list.putInteger(13);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 底对齐() //底对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSBottoms"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 水平居中对齐() //水平居中对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSCentersH"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 设置单位为像素
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
dialog.show();
|
||||
|
||||
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);
|
||||
}
|
||||
367
PSMARK代码块/米样拼图.jsx
Normal file
367
PSMARK代码块/米样拼图.jsx
Normal file
@@ -0,0 +1,367 @@
|
||||
|
||||
自动米样拼贴()
|
||||
|
||||
|
||||
// 设置单位为像素
|
||||
|
||||
function 自动米样拼贴(){
|
||||
|
||||
var dialog = new Window("dialog");
|
||||
|
||||
|
||||
dialog.text = "SO自动米样拼贴";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "源图像";
|
||||
panel1.preferredSize.width = 388;
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "使用:";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = panel1.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var button1 = group2.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "选取";
|
||||
|
||||
var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}');
|
||||
edittext1.text = "[选择图像文件夹]";
|
||||
edittext1.preferredSize.width = 300;
|
||||
|
||||
// PANEL2
|
||||
// ======
|
||||
var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});
|
||||
panel2.text = "SO小样文档";
|
||||
panel2.preferredSize.height = 160;
|
||||
panel2.orientation = "column";
|
||||
panel2.alignChildren = ["left","top"];
|
||||
panel2.spacing = 10;
|
||||
panel2.margins = 10;
|
||||
|
||||
var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "设定:";
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = panel2.add("group", undefined, {name: "group3"});
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "幅宽(cm):";
|
||||
|
||||
var edittext2 = group3.add('edittext {properties: {name: "edittext2"}}');
|
||||
edittext2.preferredSize.width = 100;
|
||||
|
||||
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = panel2.add("group", undefined, {name: "group4"});
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
// GROUP5
|
||||
// ======
|
||||
var group5 = group1.add("group", undefined, {name: "group5"});
|
||||
group5.orientation = "row";
|
||||
group5.alignChildren = ["left","center"];
|
||||
group5.spacing = 10;
|
||||
group5.margins = 0;
|
||||
|
||||
// PANEL3
|
||||
// ======
|
||||
|
||||
|
||||
// GROUP7
|
||||
// ======
|
||||
var group7 = dialog.add("group", undefined, {name: "group7"});
|
||||
group7.orientation = "column";
|
||||
group7.alignChildren = ["fill","top"];
|
||||
group7.spacing = 10;
|
||||
group7.margins = 0;
|
||||
|
||||
var ok = group7.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "确认";
|
||||
|
||||
var cancel = group7.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var dialog = new Window("dialog");
|
||||
dialog.text = "SO自动米样拼贴";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "源图像";
|
||||
panel1.preferredSize.width = 388;
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "使用:";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = panel1.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var button1 = group2.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "选取";
|
||||
|
||||
var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}');
|
||||
edittext1.text = "[选择图像文件夹]";
|
||||
edittext1.preferredSize.width = 300;
|
||||
|
||||
// PANEL2
|
||||
// ======
|
||||
var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});
|
||||
panel2.text = "SO小样文档拼贴";
|
||||
panel2.preferredSize.height = 160;
|
||||
panel2.orientation = "column";
|
||||
panel2.alignChildren = ["left","top"];
|
||||
panel2.spacing = 10;
|
||||
panel2.margins = 10;
|
||||
|
||||
var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "设定:";
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = panel2.add("group", undefined, {name: "group3"});
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "幅宽(cm):";
|
||||
|
||||
var edittext2 = group3.add('edittext {properties: {name: "edittext2"}}');
|
||||
edittext2.preferredSize.width = 100;
|
||||
|
||||
|
||||
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = panel2.add("group", undefined, {name: "group4"});
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
// GROUP5
|
||||
// ======
|
||||
var group5 = group1.add("group", undefined, {name: "group5"});
|
||||
group5.orientation = "row";
|
||||
group5.alignChildren = ["left","center"];
|
||||
group5.spacing = 10;
|
||||
group5.margins = 0;
|
||||
|
||||
// PANEL3
|
||||
// ======
|
||||
|
||||
|
||||
// GROUP7
|
||||
// ======
|
||||
var group7 = dialog.add("group", undefined, {name: "group7"});
|
||||
group7.orientation = "column";
|
||||
group7.alignChildren = ["fill","top"];
|
||||
group7.spacing = 10;
|
||||
group7.margins = 0;
|
||||
|
||||
var ok = group7.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "确认";
|
||||
|
||||
var cancel = group7.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
|
||||
|
||||
|
||||
|
||||
button1.onClick = function () {
|
||||
// 打开文件夹选择对话框
|
||||
var selectedFolder = Folder.selectDialog("选择图像文件夹");
|
||||
|
||||
// 检查用户是否取消了选择
|
||||
if (selectedFolder) {
|
||||
// 将选择的文件夹路径显示在输入框中
|
||||
edittext1.text = selectedFolder.fsName;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
ok.onClick = function () {
|
||||
app.preferences.rulerUnits = Units.PIXELS;
|
||||
//function 创建拼贴图(导入文件夹路径, 文档宽度厘米) {
|
||||
|
||||
// 假设这些值是从某处获取或者用户输入的
|
||||
var 导入文件夹路径 =new Folder (edittext1.text);
|
||||
var 文档宽度厘米 = Number(edittext2.text);
|
||||
var 文档高度厘米 = 600; // 例如,50厘米
|
||||
var 分辨率 = 200; // 分辨率设置为150 DPI
|
||||
|
||||
// 转换厘米到像素
|
||||
var 厘米到像素的转换系数 = 2.54;
|
||||
var 文档宽度像素 = 文档宽度厘米 / 厘米到像素的转换系数 * 分辨率;
|
||||
var 文档高度像素 = 文档高度厘米 / 厘米到像素的转换系数 * 分辨率;
|
||||
|
||||
var 导入文件夹 = new Folder(导入文件夹路径);
|
||||
var 文件列表 = 导入文件夹.getFiles("*.*");
|
||||
var 文件名数组 = new Array();
|
||||
var 文件宽度数组 = new Array();
|
||||
var 文件高度数组 = new Array();
|
||||
|
||||
|
||||
// 读取文件列表并获取文件信息
|
||||
for (var 索引1 = 0; 索引1 < 文件列表.length; 索引1++) {
|
||||
var 文档 = app.open(文件列表[索引1]);
|
||||
文件名数组[索引1] = 文档.fullName;
|
||||
文件宽度数组[索引1] = parseInt(文档.width);
|
||||
文件高度数组[索引1] = parseInt(文档.height);
|
||||
文档.close();
|
||||
}
|
||||
|
||||
// 根据高度对文件进行排序
|
||||
for (var 索引1 = 文件高度数组.length - 1; 索引1 > 0; --索引1) {
|
||||
for (var 索引2 = 0; 索引2 < 索引1; ++索引2) {
|
||||
if (文件高度数组[索引2] > 文件高度数组[索引2 + 1])
|
||||
交换数组元素(索引2, 索引2 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
function 交换数组元素(索引1, 索引2) {
|
||||
var 临时 = 文件高度数组[索引1];
|
||||
文件高度数组[索引1] = 文件高度数组[索引2];
|
||||
文件高度数组[索引2] = 临时;
|
||||
|
||||
var 临时2 = 文件宽度数组[索引1];
|
||||
文件宽度数组[索引1] = 文件宽度数组[索引2];
|
||||
文件宽度数组[索引2] = 临时2;
|
||||
|
||||
var 临时3 = 文件名数组[索引1];
|
||||
文件名数组[索引1] = 文件名数组[索引2];
|
||||
文件名数组[索引2] = 临时3;
|
||||
}
|
||||
|
||||
// 创建新文档并添加图片
|
||||
var 新文档 = app.documents.add(文档宽度像素, 文档高度像素, 分辨率, "拼贴", NewDocumentMode.CMYK, DocumentFill.WHITE);
|
||||
var 当前顶部 = 0;
|
||||
var 当前左侧 = 0;
|
||||
for (var 索引1 = 0; 索引1 < 文件名数组.length; 索引1++) {
|
||||
var 文档 = app.open(文件名数组[索引1]);
|
||||
文档.selection.selectAll();
|
||||
文档.selection.copy();
|
||||
文档.close();
|
||||
|
||||
if ((当前左侧 + 文件宽度数组[索引1]) > 文档宽度像素) {
|
||||
当前左侧 = 0;
|
||||
当前顶部 += 文件高度数组[索引1 - 1];
|
||||
}
|
||||
|
||||
var 边界 = [
|
||||
[当前左侧, 当前顶部],
|
||||
[当前左侧 + 文件宽度数组[索引1], 当前顶部],
|
||||
[当前左侧 + 文件宽度数组[索引1], 当前顶部 + 文件高度数组[索引1]],
|
||||
[当前左侧, 当前顶部 + 文件高度数组[索引1]]
|
||||
];
|
||||
新文档.selection.select(边界, SelectionType.REPLACE, 0, true);
|
||||
新文档.paste();
|
||||
当前左侧 += 文件宽度数组[索引1];
|
||||
}
|
||||
|
||||
// 选择输出文件夹并保存图片
|
||||
var 输出文件夹 = new Folder(edittext1.text + "/拼贴");
|
||||
if (!输出文件夹.exists) 输出文件夹.create();
|
||||
|
||||
// 设置TIFF保存选项
|
||||
var tiffSaveOptions = new TiffSaveOptions();
|
||||
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW; // 使用LZW压缩
|
||||
tiffSaveOptions.byteOrder = ByteOrder.IBM; // 设置字节顺序为IBM(大端序)
|
||||
|
||||
// 定义保存的文件路径和名称
|
||||
var 文件 = new File(输出文件夹 + "/combined.tif");
|
||||
|
||||
// 保存当前文档为TIFF格式
|
||||
新文档.saveAs(文件, tiffSaveOptions, true, Extension.LOWERCASE);
|
||||
裁切透明像素();
|
||||
|
||||
// 关闭文档,不保存更改
|
||||
//新文档.close(SaveOptions.DONOTSAVECHANGES);
|
||||
dialog.close();
|
||||
alert("拼贴完成")
|
||||
|
||||
}
|
||||
|
||||
function 裁切透明像素() {
|
||||
var 文档 = app.activeDocument; // 获取当前活动的文档
|
||||
|
||||
// 裁切透明像素
|
||||
// TrimType.TOPLEFT 表示从图像的左上角开始裁切
|
||||
// 第二个参数 true 表示裁切顶部的透明像素
|
||||
// 第三个参数 true 表示裁切左侧的透明像素
|
||||
// 第四个参数 true 表示裁切底部的透明像素
|
||||
// 第五个参数 true 表示裁切右侧的透明像素
|
||||
文档.trim(TrimType.TOPLEFT, true, true, true, true);
|
||||
}
|
||||
|
||||
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
497
PSMARK代码块/米样缩放.jsx
Normal file
497
PSMARK代码块/米样缩放.jsx
Normal file
@@ -0,0 +1,497 @@
|
||||
|
||||
|
||||
|
||||
|
||||
新的米样缩放()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 新的米样缩放()
|
||||
{
|
||||
var dialog = new Window("dialog");
|
||||
|
||||
dialog.text = "S/O样自动缩放";
|
||||
//dialog.text = "SO自动米样拼贴";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "源图像";
|
||||
panel1.preferredSize.width = 388;
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "使用:";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = panel1.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var button1 = group2.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "选取";
|
||||
|
||||
var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}');
|
||||
edittext1.text = "[选择图像文件夹]";
|
||||
edittext1.preferredSize.width = 300;
|
||||
|
||||
// PANEL2
|
||||
// ======
|
||||
var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});
|
||||
panel2.text = "SO小样文档";
|
||||
panel2.preferredSize.height = 160;
|
||||
panel2.orientation = "column";
|
||||
panel2.alignChildren = ["left","top"];
|
||||
panel2.spacing = 10;
|
||||
panel2.margins = 10;
|
||||
|
||||
var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "设定:";
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = panel2.add("group", undefined, {name: "group3"});
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "宽度(cm):";
|
||||
|
||||
var edittext2 = group3.add('edittext {properties: {name: "edittext2"}}');
|
||||
edittext2.preferredSize.width = 100;
|
||||
|
||||
var statictext4 = group3.add("statictext", undefined, undefined, {name: "statictext4"});
|
||||
statictext4.text = "高度(cm):";
|
||||
|
||||
var edittext3 = group3.add('edittext {properties: {name: "edittext3"}}');
|
||||
edittext3.preferredSize.width = 100;
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = panel2.add("group", undefined, {name: "group4"});
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
// GROUP5
|
||||
// ======
|
||||
var group5 = group1.add("group", undefined, {name: "group5"});
|
||||
group5.orientation = "row";
|
||||
group5.alignChildren = ["left","center"];
|
||||
group5.spacing = 10;
|
||||
group5.margins = 0;
|
||||
|
||||
// PANEL3
|
||||
// ======
|
||||
|
||||
|
||||
// GROUP7
|
||||
// ======
|
||||
var group7 = dialog.add("group", undefined, {name: "group7"});
|
||||
group7.orientation = "column";
|
||||
group7.alignChildren = ["fill","top"];
|
||||
group7.spacing = 10;
|
||||
group7.margins = 0;
|
||||
|
||||
var ok = group7.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "确认";
|
||||
|
||||
var cancel = group7.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
button1.onClick = function () {
|
||||
// 打开文件夹选择对话框
|
||||
var selectedFolder = Folder.selectDialog("选择图像文件夹");
|
||||
|
||||
// 检查用户是否取消了选择
|
||||
if (selectedFolder) {
|
||||
// 将选择的文件夹路径显示在输入框中
|
||||
edittext1.text = selectedFolder.fsName;
|
||||
}
|
||||
};
|
||||
|
||||
ok.onClick = function () {
|
||||
app.preferences.rulerUnits = Units.PIXELS;
|
||||
var 素材图片文件夹 = new Folder(edittext1.text);
|
||||
var 遍历tiff = 素材图片文件夹.getFiles("*.*");
|
||||
|
||||
// 新建文件夹
|
||||
var 新文件夹 = new Folder(edittext1.text + "/SO小样拼贴");
|
||||
新文件夹.create();
|
||||
var 新加字文件夹 = new Folder(edittext1.text + "/SO小样拼贴加字");
|
||||
新加字文件夹.create();
|
||||
|
||||
|
||||
宽度=Number (edittext2.text);
|
||||
高度=Number (edittext3.text);
|
||||
|
||||
|
||||
for (var i = 0; i < 遍历tiff.length; i++) {
|
||||
if (遍历tiff[i] instanceof File) {
|
||||
app.open(遍历tiff[i]);
|
||||
app.activeDocument.flatten();
|
||||
var 当前文档 = app.activeDocument;
|
||||
var 当前文档名称 = 当前文档.name;
|
||||
resizeImageToCm(宽度, 高度,200);
|
||||
/*
|
||||
图像大小()
|
||||
预设图案(当前文档名称);
|
||||
app.activeDocument.crop([UnitValue("0px"), UnitValue("0px"), UnitValue(宽度, "cm"), UnitValue(高度, "cm")]);
|
||||
填充图案(当前文档名称);
|
||||
app.activeDocument.flatten();
|
||||
画布扩展()
|
||||
*/
|
||||
画布扩展()
|
||||
// 保存新的图像文件到新建的文件夹中
|
||||
var 保存路径 = 新文件夹 + "/" + 当前文档名称;
|
||||
var tifSaveOpt = new TiffSaveOptions();
|
||||
tifSaveOpt.imageCompression = TIFFEncoding.TIFFLZW;
|
||||
tifSaveOpt.byteOrder = ByteOrder.IBM;
|
||||
var asCopy = true;
|
||||
app.activeDocument.saveAs(new File(保存路径), tifSaveOpt, asCopy);
|
||||
创建并处理文本图层();
|
||||
app.activeDocument.flatten();
|
||||
var 保存路径 = 新加字文件夹 + "/" + 当前文档名称;
|
||||
var tifSaveOpt = new TiffSaveOptions();
|
||||
tifSaveOpt.imageCompression = TIFFEncoding.TIFFLZW;
|
||||
tifSaveOpt.byteOrder = ByteOrder.IBM;
|
||||
var asCopy = true;
|
||||
app.activeDocument.saveAs(new File(保存路径), tifSaveOpt, asCopy);
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//alert("小样连晒完成")
|
||||
dialog.close();
|
||||
// 创建并保存拼贴图像(新文件夹, 幅宽)
|
||||
};
|
||||
|
||||
|
||||
function resizeImageToCm(widthCm, heightCm, resolution) {
|
||||
// 将厘米转换为像素
|
||||
var widthInPixels = widthCm * (resolution / 2.54);
|
||||
var heightInPixels = heightCm * (resolution / 2.54);
|
||||
|
||||
// 调整图像大小
|
||||
app.activeDocument.resizeImage(widthInPixels, heightInPixels, resolution, ResampleMethod.NEARESTNEIGHBOR);
|
||||
}
|
||||
|
||||
// 使用示例:将图像大小调整为 10cm x 15cm,分辨率为 300 像素/英寸
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 预设图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("pattern"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
|
||||
r1.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("using"), r1);
|
||||
d.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 填充图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("contentLayer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
var d2 = new ActionDescriptor();
|
||||
var d3 = new ActionDescriptor();
|
||||
d3.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
|
||||
d2.putObject(stringIDToTypeID("pattern"), stringIDToTypeID("pattern"), d3);
|
||||
d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("patternLayer"), d2);
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("contentLayer"), d1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 图像大小() //图像大小
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putUnitDouble(stringIDToTypeID("resolution"), stringIDToTypeID("densityUnit"), 200);
|
||||
d.putBoolean(stringIDToTypeID("scaleStyles"), true);
|
||||
d.putBoolean(stringIDToTypeID("constrainProportions"), true);
|
||||
d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("nearestNeighbor"));
|
||||
executeAction(stringIDToTypeID("imageSize"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 画布扩展() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putBoolean(stringIDToTypeID("relative"), true);
|
||||
d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("distanceUnit"), 14.4);
|
||||
d.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("distanceUnit"), 14.4);
|
||||
d.putEnumerated(stringIDToTypeID("horizontal"), stringIDToTypeID("horizontalLocation"), stringIDToTypeID("center"));
|
||||
d.putEnumerated(stringIDToTypeID("vertical"), stringIDToTypeID("verticalLocation"), stringIDToTypeID("center"));
|
||||
d.putEnumerated(stringIDToTypeID("canvasExtensionColorType"), stringIDToTypeID("canvasExtensionColorType"), stringIDToTypeID("color"));
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putDouble(stringIDToTypeID("red"), 255);
|
||||
d1.putDouble(stringIDToTypeID("green"), 255);
|
||||
d1.putDouble(stringIDToTypeID("blue"), 255);
|
||||
d.putObject(stringIDToTypeID("canvasExtensionColor"), stringIDToTypeID("RGBColor"), d1);
|
||||
executeAction(stringIDToTypeID("canvasSize"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 创建并处理文本图层() {
|
||||
// 新建图层
|
||||
var textLayer = activeDocument.artLayers.add();
|
||||
|
||||
// 将新建图层变成文本图层
|
||||
textLayer.kind = LayerKind.TEXT;
|
||||
|
||||
// 将文本内容改为当前文档name
|
||||
textLayer.textItem.contents = activeDocument.name;
|
||||
|
||||
// 字体大小固定值
|
||||
var 固定字体大小 = 30; // 例如,30像素
|
||||
textLayer.textItem.size = 固定字体大小;
|
||||
|
||||
// 文字字体固定值
|
||||
textLayer.textItem.font = "微软雅黑";
|
||||
|
||||
// 计算并调整文本位置
|
||||
var x = activeDocument.width - textLayer.bounds[2];
|
||||
var y = textLayer.bounds[1];
|
||||
textLayer.translate(x, -y);
|
||||
|
||||
// 偏移
|
||||
textLayer.translate(UnitValue("-1cm"), UnitValue("+0.5cm"));
|
||||
|
||||
// 复制并栅格化图层
|
||||
var copyLayer = textLayer.duplicate();
|
||||
copyLayer.rasterize(RasterizeType.ENTIRELAYER);
|
||||
|
||||
// 设置固定颜色值
|
||||
var 固定颜色 = new SolidColor();
|
||||
固定颜色.rgb.red = 255; // 红色分量
|
||||
固定颜色.rgb.green = 255; // 绿色分量
|
||||
固定颜色.rgb.blue = 255; // 蓝色分量
|
||||
|
||||
activeDocument.activeLayer = copyLayer;
|
||||
activeDocument.selection.fill(固定颜色, ColorBlendMode.NORMAL, 100, true);
|
||||
|
||||
// 白边
|
||||
activeDocument.activeLayer.applyMinimum(10);
|
||||
后移一层()
|
||||
向上选择()
|
||||
向下合并()
|
||||
名称更改字体()
|
||||
缩小字体图层至文档一半()
|
||||
多选背景()
|
||||
底对齐()
|
||||
水平居中对齐()
|
||||
}
|
||||
|
||||
// 调用函数
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 后移一层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("previous"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("move"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 向上选择() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("forwardEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(19);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
function 向下合并() //向下合并
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 名称更改字体() //名称更改
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putString(stringIDToTypeID("name"), "字体");
|
||||
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("layer"), d1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 缩小字体图层至文档一半() {
|
||||
var 文档 = app.activeDocument;
|
||||
var 字体图层 = null;
|
||||
|
||||
// 遍历文档中的图层以找到名为"字体"的图层
|
||||
for (var i = 0; i < 文档.artLayers.length; i++) {
|
||||
if (文档.artLayers[i].name === "字体") {
|
||||
字体图层 = 文档.artLayers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (字体图层 !== null) {
|
||||
// 获取文档的宽度的一半
|
||||
var 目标宽度 = 文档.width / 2;
|
||||
|
||||
// 获取图层的当前宽度
|
||||
var 图层宽度 = 字体图层.bounds[2] - 字体图层.bounds[0];
|
||||
|
||||
// 计算缩放比例
|
||||
var 缩放比例 = 目标宽度 / 图层宽度 * 100;
|
||||
|
||||
// 缩放图层
|
||||
字体图层.resize(缩放比例, 缩放比例, AnchorPosition.MIDDLECENTER);
|
||||
} else {
|
||||
alert("未找到名为'字体'的图层");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function 多选背景() //自由变换
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("layer"), "背景");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(1);
|
||||
list.putInteger(13);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 底对齐() //底对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSBottoms"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 水平居中对齐() //水平居中对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSCentersH"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 设置单位为像素
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
361
PSMARK代码块/米样自动拼贴.jsx
Normal file
361
PSMARK代码块/米样自动拼贴.jsx
Normal file
@@ -0,0 +1,361 @@
|
||||
// 设置单位为像素
|
||||
|
||||
|
||||
|
||||
var dialog = new Window("dialog");
|
||||
|
||||
|
||||
dialog.text = "SO自动米样拼贴";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "源图像";
|
||||
panel1.preferredSize.width = 388;
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "使用:";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = panel1.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var button1 = group2.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "选取";
|
||||
|
||||
var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}');
|
||||
edittext1.text = "[选择图像文件夹]";
|
||||
edittext1.preferredSize.width = 300;
|
||||
|
||||
// PANEL2
|
||||
// ======
|
||||
var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});
|
||||
panel2.text = "SO小样文档";
|
||||
panel2.preferredSize.height = 160;
|
||||
panel2.orientation = "column";
|
||||
panel2.alignChildren = ["left","top"];
|
||||
panel2.spacing = 10;
|
||||
panel2.margins = 10;
|
||||
|
||||
var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "设定:";
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = panel2.add("group", undefined, {name: "group3"});
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "幅宽(cm):";
|
||||
|
||||
var edittext2 = group3.add('edittext {properties: {name: "edittext2"}}');
|
||||
edittext2.preferredSize.width = 100;
|
||||
|
||||
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = panel2.add("group", undefined, {name: "group4"});
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
// GROUP5
|
||||
// ======
|
||||
var group5 = group1.add("group", undefined, {name: "group5"});
|
||||
group5.orientation = "row";
|
||||
group5.alignChildren = ["left","center"];
|
||||
group5.spacing = 10;
|
||||
group5.margins = 0;
|
||||
|
||||
// PANEL3
|
||||
// ======
|
||||
|
||||
|
||||
// GROUP7
|
||||
// ======
|
||||
var group7 = dialog.add("group", undefined, {name: "group7"});
|
||||
group7.orientation = "column";
|
||||
group7.alignChildren = ["fill","top"];
|
||||
group7.spacing = 10;
|
||||
group7.margins = 0;
|
||||
|
||||
var ok = group7.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "确认";
|
||||
|
||||
var cancel = group7.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var dialog = new Window("dialog");
|
||||
dialog.text = "SO自动米样拼贴";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "源图像";
|
||||
panel1.preferredSize.width = 388;
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "使用:";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = panel1.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var button1 = group2.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "选取";
|
||||
|
||||
var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}');
|
||||
edittext1.text = "[选择图像文件夹]";
|
||||
edittext1.preferredSize.width = 300;
|
||||
|
||||
// PANEL2
|
||||
// ======
|
||||
var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});
|
||||
panel2.text = "SO小样文档拼贴";
|
||||
panel2.preferredSize.height = 160;
|
||||
panel2.orientation = "column";
|
||||
panel2.alignChildren = ["left","top"];
|
||||
panel2.spacing = 10;
|
||||
panel2.margins = 10;
|
||||
|
||||
var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "设定:";
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = panel2.add("group", undefined, {name: "group3"});
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "幅宽(cm):";
|
||||
|
||||
var edittext2 = group3.add('edittext {properties: {name: "edittext2"}}');
|
||||
edittext2.preferredSize.width = 100;
|
||||
|
||||
|
||||
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = panel2.add("group", undefined, {name: "group4"});
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
// GROUP5
|
||||
// ======
|
||||
var group5 = group1.add("group", undefined, {name: "group5"});
|
||||
group5.orientation = "row";
|
||||
group5.alignChildren = ["left","center"];
|
||||
group5.spacing = 10;
|
||||
group5.margins = 0;
|
||||
|
||||
// PANEL3
|
||||
// ======
|
||||
|
||||
|
||||
// GROUP7
|
||||
// ======
|
||||
var group7 = dialog.add("group", undefined, {name: "group7"});
|
||||
group7.orientation = "column";
|
||||
group7.alignChildren = ["fill","top"];
|
||||
group7.spacing = 10;
|
||||
group7.margins = 0;
|
||||
|
||||
var ok = group7.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "确认";
|
||||
|
||||
var cancel = group7.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
|
||||
|
||||
|
||||
|
||||
button1.onClick = function () {
|
||||
// 打开文件夹选择对话框
|
||||
var selectedFolder = Folder.selectDialog("选择图像文件夹");
|
||||
|
||||
// 检查用户是否取消了选择
|
||||
if (selectedFolder) {
|
||||
// 将选择的文件夹路径显示在输入框中
|
||||
edittext1.text = selectedFolder.fsName;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
ok.onClick = function () {
|
||||
app.preferences.rulerUnits = Units.PIXELS;
|
||||
//function 创建拼贴图(导入文件夹路径, 文档宽度厘米) {
|
||||
|
||||
// 假设这些值是从某处获取或者用户输入的
|
||||
var 导入文件夹路径 =new Folder (edittext1.text);
|
||||
var 文档宽度厘米 = Number(edittext2.text);
|
||||
var 文档高度厘米 = 300; // 例如,50厘米
|
||||
var 分辨率 = 150; // 分辨率设置为150 DPI
|
||||
|
||||
// 转换厘米到像素
|
||||
var 厘米到像素的转换系数 = 2.54;
|
||||
var 文档宽度像素 = 文档宽度厘米 / 厘米到像素的转换系数 * 分辨率;
|
||||
var 文档高度像素 = 文档高度厘米 / 厘米到像素的转换系数 * 分辨率;
|
||||
|
||||
var 导入文件夹 = new Folder(导入文件夹路径);
|
||||
var 文件列表 = 导入文件夹.getFiles("*.*");
|
||||
var 文件名数组 = new Array();
|
||||
var 文件宽度数组 = new Array();
|
||||
var 文件高度数组 = new Array();
|
||||
|
||||
|
||||
// 读取文件列表并获取文件信息
|
||||
for (var 索引1 = 0; 索引1 < 文件列表.length; 索引1++) {
|
||||
var 文档 = app.open(文件列表[索引1]);
|
||||
文件名数组[索引1] = 文档.fullName;
|
||||
文件宽度数组[索引1] = parseInt(文档.width);
|
||||
文件高度数组[索引1] = parseInt(文档.height);
|
||||
文档.close();
|
||||
}
|
||||
|
||||
// 根据高度对文件进行排序
|
||||
for (var 索引1 = 文件高度数组.length - 1; 索引1 > 0; --索引1) {
|
||||
for (var 索引2 = 0; 索引2 < 索引1; ++索引2) {
|
||||
if (文件高度数组[索引2] > 文件高度数组[索引2 + 1])
|
||||
交换数组元素(索引2, 索引2 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
function 交换数组元素(索引1, 索引2) {
|
||||
var 临时 = 文件高度数组[索引1];
|
||||
文件高度数组[索引1] = 文件高度数组[索引2];
|
||||
文件高度数组[索引2] = 临时;
|
||||
|
||||
var 临时2 = 文件宽度数组[索引1];
|
||||
文件宽度数组[索引1] = 文件宽度数组[索引2];
|
||||
文件宽度数组[索引2] = 临时2;
|
||||
|
||||
var 临时3 = 文件名数组[索引1];
|
||||
文件名数组[索引1] = 文件名数组[索引2];
|
||||
文件名数组[索引2] = 临时3;
|
||||
}
|
||||
|
||||
// 创建新文档并添加图片
|
||||
var 新文档 = app.documents.add(文档宽度像素, 文档高度像素, 分辨率, "拼贴", NewDocumentMode.CMYK, DocumentFill.WHITE);
|
||||
var 当前顶部 = 0;
|
||||
var 当前左侧 = 0;
|
||||
for (var 索引1 = 0; 索引1 < 文件名数组.length; 索引1++) {
|
||||
var 文档 = app.open(文件名数组[索引1]);
|
||||
文档.selection.selectAll();
|
||||
文档.selection.copy();
|
||||
文档.close();
|
||||
|
||||
if ((当前左侧 + 文件宽度数组[索引1]) > 文档宽度像素) {
|
||||
当前左侧 = 0;
|
||||
当前顶部 += 文件高度数组[索引1 - 1];
|
||||
}
|
||||
|
||||
var 边界 = [
|
||||
[当前左侧, 当前顶部],
|
||||
[当前左侧 + 文件宽度数组[索引1], 当前顶部],
|
||||
[当前左侧 + 文件宽度数组[索引1], 当前顶部 + 文件高度数组[索引1]],
|
||||
[当前左侧, 当前顶部 + 文件高度数组[索引1]]
|
||||
];
|
||||
新文档.selection.select(边界, SelectionType.REPLACE, 0, true);
|
||||
新文档.paste();
|
||||
当前左侧 += 文件宽度数组[索引1];
|
||||
}
|
||||
|
||||
// 选择输出文件夹并保存图片
|
||||
var 输出文件夹 = new Folder(edittext1.text + "/拼贴");
|
||||
if (!输出文件夹.exists) 输出文件夹.create();
|
||||
|
||||
// 设置TIFF保存选项
|
||||
var tiffSaveOptions = new TiffSaveOptions();
|
||||
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW; // 使用LZW压缩
|
||||
tiffSaveOptions.byteOrder = ByteOrder.IBM; // 设置字节顺序为IBM(大端序)
|
||||
|
||||
// 定义保存的文件路径和名称
|
||||
var 文件 = new File(输出文件夹 + "/combined.tif");
|
||||
|
||||
// 保存当前文档为TIFF格式
|
||||
新文档.saveAs(文件, tiffSaveOptions, true, Extension.LOWERCASE);
|
||||
裁切透明像素();
|
||||
|
||||
// 关闭文档,不保存更改
|
||||
//新文档.close(SaveOptions.DONOTSAVECHANGES);
|
||||
dialog.close();
|
||||
alert("拼贴完成")
|
||||
|
||||
}
|
||||
|
||||
function 裁切透明像素() {
|
||||
var 文档 = app.activeDocument; // 获取当前活动的文档
|
||||
|
||||
// 裁切透明像素
|
||||
// TrimType.TOPLEFT 表示从图像的左上角开始裁切
|
||||
// 第二个参数 true 表示裁切顶部的透明像素
|
||||
// 第三个参数 true 表示裁切左侧的透明像素
|
||||
// 第四个参数 true 表示裁切底部的透明像素
|
||||
// 第五个参数 true 表示裁切右侧的透明像素
|
||||
文档.trim(TrimType.TOPLEFT, true, true, true, true);
|
||||
}
|
||||
|
||||
|
||||
dialog.show();
|
||||
473
PSMARK代码块/自动连晒.jsx
Normal file
473
PSMARK代码块/自动连晒.jsx
Normal file
@@ -0,0 +1,473 @@
|
||||
|
||||
|
||||
|
||||
自动连晒()
|
||||
|
||||
|
||||
|
||||
function 自动连晒(){
|
||||
var dialog = new Window("dialog");
|
||||
|
||||
dialog.text = "S/O样自动连晒";
|
||||
//dialog.text = "SO自动米样拼贴";
|
||||
dialog.orientation = "row";
|
||||
dialog.alignChildren = ["left","top"];
|
||||
dialog.spacing = 10;
|
||||
dialog.margins = 16;
|
||||
|
||||
// GROUP1
|
||||
// ======
|
||||
var group1 = dialog.add("group", undefined, {name: "group1"});
|
||||
group1.orientation = "column";
|
||||
group1.alignChildren = ["fill","top"];
|
||||
group1.spacing = 10;
|
||||
group1.margins = 0;
|
||||
|
||||
// PANEL1
|
||||
// ======
|
||||
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
|
||||
panel1.text = "源图像";
|
||||
panel1.preferredSize.width = 388;
|
||||
panel1.preferredSize.height = 205;
|
||||
panel1.orientation = "column";
|
||||
panel1.alignChildren = ["left","top"];
|
||||
panel1.spacing = 10;
|
||||
panel1.margins = 10;
|
||||
|
||||
var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});
|
||||
statictext1.text = "使用:";
|
||||
|
||||
// GROUP2
|
||||
// ======
|
||||
var group2 = panel1.add("group", undefined, {name: "group2"});
|
||||
group2.orientation = "row";
|
||||
group2.alignChildren = ["left","center"];
|
||||
group2.spacing = 10;
|
||||
group2.margins = 0;
|
||||
|
||||
var button1 = group2.add("button", undefined, undefined, {name: "button1"});
|
||||
button1.text = "选取";
|
||||
|
||||
var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}');
|
||||
edittext1.text = "[选择图像文件夹]";
|
||||
edittext1.preferredSize.width = 300;
|
||||
|
||||
// PANEL2
|
||||
// ======
|
||||
var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});
|
||||
panel2.text = "SO小样文档";
|
||||
panel2.preferredSize.height = 160;
|
||||
panel2.orientation = "column";
|
||||
panel2.alignChildren = ["left","top"];
|
||||
panel2.spacing = 10;
|
||||
panel2.margins = 10;
|
||||
|
||||
var statictext2 = panel2.add("statictext", undefined, undefined, {name: "statictext2"});
|
||||
statictext2.text = "设定:";
|
||||
|
||||
// GROUP3
|
||||
// ======
|
||||
var group3 = panel2.add("group", undefined, {name: "group3"});
|
||||
group3.orientation = "row";
|
||||
group3.alignChildren = ["left","center"];
|
||||
group3.spacing = 10;
|
||||
group3.margins = 0;
|
||||
|
||||
var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"});
|
||||
statictext3.text = "宽度(cm):";
|
||||
|
||||
var edittext2 = group3.add('edittext {properties: {name: "edittext2"}}');
|
||||
edittext2.preferredSize.width = 100;
|
||||
|
||||
var statictext4 = group3.add("statictext", undefined, undefined, {name: "statictext4"});
|
||||
statictext4.text = "高度(cm):";
|
||||
|
||||
var edittext3 = group3.add('edittext {properties: {name: "edittext3"}}');
|
||||
edittext3.preferredSize.width = 100;
|
||||
|
||||
// GROUP4
|
||||
// ======
|
||||
var group4 = panel2.add("group", undefined, {name: "group4"});
|
||||
group4.orientation = "row";
|
||||
group4.alignChildren = ["left","center"];
|
||||
group4.spacing = 10;
|
||||
group4.margins = 0;
|
||||
|
||||
// GROUP5
|
||||
// ======
|
||||
var group5 = group1.add("group", undefined, {name: "group5"});
|
||||
group5.orientation = "row";
|
||||
group5.alignChildren = ["left","center"];
|
||||
group5.spacing = 10;
|
||||
group5.margins = 0;
|
||||
|
||||
// PANEL3
|
||||
// ======
|
||||
|
||||
|
||||
// GROUP7
|
||||
// ======
|
||||
var group7 = dialog.add("group", undefined, {name: "group7"});
|
||||
group7.orientation = "column";
|
||||
group7.alignChildren = ["fill","top"];
|
||||
group7.spacing = 10;
|
||||
group7.margins = 0;
|
||||
|
||||
var ok = group7.add("button", undefined, undefined, {name: "ok"});
|
||||
ok.text = "确认";
|
||||
|
||||
var cancel = group7.add("button", undefined, undefined, {name: "cancel"});
|
||||
cancel.text = "取消";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
button1.onClick = function () {
|
||||
// 打开文件夹选择对话框
|
||||
var selectedFolder = Folder.selectDialog("选择图像文件夹");
|
||||
|
||||
// 检查用户是否取消了选择
|
||||
if (selectedFolder) {
|
||||
// 将选择的文件夹路径显示在输入框中
|
||||
edittext1.text = selectedFolder.fsName;
|
||||
}
|
||||
};
|
||||
|
||||
ok.onClick = function () {
|
||||
app.preferences.rulerUnits = Units.PIXELS;
|
||||
var 素材图片文件夹 = new Folder(edittext1.text);
|
||||
var 遍历tiff = 素材图片文件夹.getFiles("*.*");
|
||||
|
||||
// 新建文件夹
|
||||
var 新文件夹 = new Folder(edittext1.text + "/SO小样拼贴");
|
||||
新文件夹.create();
|
||||
var 新加字文件夹 = new Folder(edittext1.text + "/SO小样拼贴加字");
|
||||
新加字文件夹.create();
|
||||
|
||||
|
||||
宽度=Number (edittext2.text);
|
||||
高度=Number (edittext3.text);
|
||||
|
||||
|
||||
for (var i = 0; i < 遍历tiff.length; i++) {
|
||||
if (遍历tiff[i] instanceof File) {
|
||||
app.open(遍历tiff[i]);
|
||||
app.activeDocument.flatten();
|
||||
var 当前文档 = app.activeDocument;
|
||||
var 当前文档名称 = 当前文档.name;
|
||||
图像大小()
|
||||
预设图案(当前文档名称);
|
||||
app.activeDocument.crop([UnitValue("0px"), UnitValue("0px"), UnitValue(宽度, "cm"), UnitValue(高度, "cm")]);
|
||||
填充图案(当前文档名称);
|
||||
app.activeDocument.flatten();
|
||||
画布扩展()
|
||||
// 保存新的图像文件到新建的文件夹中
|
||||
var 保存路径 = 新文件夹 + "/" + 当前文档名称;
|
||||
var tifSaveOpt = new TiffSaveOptions();
|
||||
tifSaveOpt.imageCompression = TIFFEncoding.TIFFLZW;
|
||||
tifSaveOpt.byteOrder = ByteOrder.IBM;
|
||||
var asCopy = true;
|
||||
app.activeDocument.saveAs(new File(保存路径), tifSaveOpt, asCopy);
|
||||
创建并处理文本图层();
|
||||
app.activeDocument.flatten();
|
||||
var 保存路径 = 新加字文件夹 + "/" + 当前文档名称;
|
||||
var tifSaveOpt = new TiffSaveOptions();
|
||||
tifSaveOpt.imageCompression = TIFFEncoding.TIFFLZW;
|
||||
tifSaveOpt.byteOrder = ByteOrder.IBM;
|
||||
var asCopy = true;
|
||||
app.activeDocument.saveAs(new File(保存路径), tifSaveOpt, asCopy);
|
||||
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//alert("小样连晒完成")
|
||||
dialog.close();
|
||||
// 创建并保存拼贴图像(新文件夹, 幅宽)
|
||||
};
|
||||
|
||||
|
||||
|
||||
function 预设图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("pattern"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
|
||||
r1.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("using"), r1);
|
||||
d.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 填充图案(当前文档名称) //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putClass(stringIDToTypeID("contentLayer"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
var d2 = new ActionDescriptor();
|
||||
var d3 = new ActionDescriptor();
|
||||
d3.putString(stringIDToTypeID("name"), 当前文档名称);
|
||||
|
||||
d2.putObject(stringIDToTypeID("pattern"), stringIDToTypeID("pattern"), d3);
|
||||
d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("patternLayer"), d2);
|
||||
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("contentLayer"), d1);
|
||||
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 图像大小() //图像大小
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putUnitDouble(stringIDToTypeID("resolution"), stringIDToTypeID("densityUnit"), 200);
|
||||
d.putBoolean(stringIDToTypeID("scaleStyles"), true);
|
||||
d.putBoolean(stringIDToTypeID("constrainProportions"), true);
|
||||
d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("nearestNeighbor"));
|
||||
executeAction(stringIDToTypeID("imageSize"), d, DialogModes.NO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 画布扩展() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
d.putBoolean(stringIDToTypeID("relative"), true);
|
||||
d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("distanceUnit"), 14.4);
|
||||
d.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("distanceUnit"), 14.4);
|
||||
d.putEnumerated(stringIDToTypeID("horizontal"), stringIDToTypeID("horizontalLocation"), stringIDToTypeID("center"));
|
||||
d.putEnumerated(stringIDToTypeID("vertical"), stringIDToTypeID("verticalLocation"), stringIDToTypeID("center"));
|
||||
d.putEnumerated(stringIDToTypeID("canvasExtensionColorType"), stringIDToTypeID("canvasExtensionColorType"), stringIDToTypeID("color"));
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putDouble(stringIDToTypeID("red"), 255);
|
||||
d1.putDouble(stringIDToTypeID("green"), 255);
|
||||
d1.putDouble(stringIDToTypeID("blue"), 255);
|
||||
d.putObject(stringIDToTypeID("canvasExtensionColor"), stringIDToTypeID("RGBColor"), d1);
|
||||
executeAction(stringIDToTypeID("canvasSize"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 创建并处理文本图层() {
|
||||
// 新建图层
|
||||
var textLayer = activeDocument.artLayers.add();
|
||||
|
||||
// 将新建图层变成文本图层
|
||||
textLayer.kind = LayerKind.TEXT;
|
||||
|
||||
// 将文本内容改为当前文档name
|
||||
textLayer.textItem.contents = activeDocument.name;
|
||||
|
||||
// 字体大小固定值
|
||||
var 固定字体大小 = 30; // 例如,30像素
|
||||
textLayer.textItem.size = 固定字体大小;
|
||||
|
||||
// 文字字体固定值
|
||||
textLayer.textItem.font = "微软雅黑";
|
||||
|
||||
// 计算并调整文本位置
|
||||
var x = activeDocument.width - textLayer.bounds[2];
|
||||
var y = textLayer.bounds[1];
|
||||
textLayer.translate(x, -y);
|
||||
|
||||
// 偏移
|
||||
textLayer.translate(UnitValue("-1cm"), UnitValue("+0.5cm"));
|
||||
|
||||
// 复制并栅格化图层
|
||||
var copyLayer = textLayer.duplicate();
|
||||
copyLayer.rasterize(RasterizeType.ENTIRELAYER);
|
||||
|
||||
// 设置固定颜色值
|
||||
var 固定颜色 = new SolidColor();
|
||||
固定颜色.rgb.red = 255; // 红色分量
|
||||
固定颜色.rgb.green = 255; // 绿色分量
|
||||
固定颜色.rgb.blue = 255; // 蓝色分量
|
||||
|
||||
activeDocument.activeLayer = copyLayer;
|
||||
activeDocument.selection.fill(固定颜色, ColorBlendMode.NORMAL, 100, true);
|
||||
|
||||
// 白边
|
||||
activeDocument.activeLayer.applyMinimum(10);
|
||||
后移一层()
|
||||
向上选择()
|
||||
向下合并()
|
||||
名称更改字体()
|
||||
缩小字体图层至文档一半()
|
||||
多选背景()
|
||||
底对齐()
|
||||
水平居中对齐()
|
||||
}
|
||||
|
||||
// 调用函数
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function 后移一层() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var r1 = new ActionReference();
|
||||
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("previous"));
|
||||
d.putReference(stringIDToTypeID("to"), r1);
|
||||
executeAction(stringIDToTypeID("move"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
function 向上选择() //
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("forwardEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(19);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
function 向下合并() //向下合并
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
executeAction(stringIDToTypeID("mergeLayersNew"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function 名称更改字体() //名称更改
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
var d1 = new ActionDescriptor();
|
||||
d1.putString(stringIDToTypeID("name"), "字体");
|
||||
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("layer"), d1);
|
||||
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 缩小字体图层至文档一半() {
|
||||
var 文档 = app.activeDocument;
|
||||
var 字体图层 = null;
|
||||
|
||||
// 遍历文档中的图层以找到名为"字体"的图层
|
||||
for (var i = 0; i < 文档.artLayers.length; i++) {
|
||||
if (文档.artLayers[i].name === "字体") {
|
||||
字体图层 = 文档.artLayers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (字体图层 !== null) {
|
||||
// 获取文档的宽度的一半
|
||||
var 目标宽度 = 文档.width / 2;
|
||||
|
||||
// 获取图层的当前宽度
|
||||
var 图层宽度 = 字体图层.bounds[2] - 字体图层.bounds[0];
|
||||
|
||||
// 计算缩放比例
|
||||
var 缩放比例 = 目标宽度 / 图层宽度 * 100;
|
||||
|
||||
// 缩放图层
|
||||
字体图层.resize(缩放比例, 缩放比例, AnchorPosition.MIDDLECENTER);
|
||||
} else {
|
||||
alert("未找到名为'字体'的图层");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function 多选背景() //自由变换
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putName(stringIDToTypeID("layer"), "背景");
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
|
||||
d.putBoolean(stringIDToTypeID("makeVisible"), false);
|
||||
var list = new ActionList();
|
||||
list.putInteger(1);
|
||||
list.putInteger(13);
|
||||
d.putList(stringIDToTypeID("layerID"), list);
|
||||
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function 底对齐() //底对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSBottoms"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 水平居中对齐() //水平居中对齐
|
||||
{
|
||||
|
||||
var d = new ActionDescriptor();
|
||||
var r = new ActionReference();
|
||||
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
|
||||
d.putReference(stringIDToTypeID("null"), r);
|
||||
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("alignDistributeSelector"), stringIDToTypeID("ADSCentersH"));
|
||||
d.putBoolean(stringIDToTypeID("alignToCanvas"), false);
|
||||
executeAction(stringIDToTypeID("align"), d, DialogModes.NO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 设置单位为像素
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
49
PSMARK代码块/自由变换函数.jsx
Normal file
49
PSMARK代码块/自由变换函数.jsx
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
|
||||
|
||||
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, 插值方法,角度);
|
||||
28
PSMARK代码块/读取json文件.jsx
Normal file
28
PSMARK代码块/读取json文件.jsx
Normal file
@@ -0,0 +1,28 @@
|
||||
// 创建一个文件对象指向桌面上的子图层名称.json文件
|
||||
var desktop = Folder.desktop;
|
||||
var file = new File(desktop + "/名称数据.json");
|
||||
|
||||
// 打开文件以进行读取
|
||||
if (file.open('r')) {
|
||||
var content = file.read();
|
||||
file.close();
|
||||
|
||||
// 从JSON格式的字符串中删除前后的方括号,并根据逗号分割为数组
|
||||
var 名称数组 = content.replace(/^\s*\[|\]\s*$/g, '').split(/"\s*,\s*"/);
|
||||
|
||||
// 循环遍历数组并逐个弹出名称
|
||||
for (var i = 0; i < 名称数组.length; i++) {
|
||||
// 从每个名称中删除前后的双引号
|
||||
var 名称 = 名称数组[i].replace(/^"|"$/g, '');
|
||||
|
||||
// 弹出整个名称
|
||||
// alert("完整名称: " + 名称);
|
||||
|
||||
// 使用正则表达式提取括号内的内容
|
||||
var matches = 名称.match(/\(([^)]+)\)/);
|
||||
var 图案名称=matches [1]
|
||||
//alert("图案名称: " + 图案名称);
|
||||
}
|
||||
} else {
|
||||
alert("无法打开文件!");
|
||||
}
|
||||
50
PSMARK代码块/读取图层json.jsx
Normal file
50
PSMARK代码块/读取图层json.jsx
Normal file
@@ -0,0 +1,50 @@
|
||||
// 检查是否有活动文档
|
||||
if (app.documents.length > 0) {
|
||||
var doc = app.activeDocument; // 获取活动文档
|
||||
|
||||
// 递归函数来构建所有图层的字符串表示
|
||||
function buildLayersString(layerSet, indent) {
|
||||
var result = "";
|
||||
var currentIndent = Array(indent + 1).join(" "); // 根据缩进级别构建缩进字符串
|
||||
for (var i = 0; i < layerSet.layers.length; i++) {
|
||||
var layer = layerSet.layers[i];
|
||||
var layerName = layer.name.replace(/"/g, '\\"'); // 转义引号
|
||||
|
||||
if (layer.typename === 'ArtLayer') {
|
||||
// 构建图层的字符串表示
|
||||
result += '\n' + currentIndent + '\"图层: ' + layerName + '\": null';
|
||||
} else { // LayerSet
|
||||
// 构建图层组的字符串表示,并递归处理子图层
|
||||
var childResult = buildLayersString(layer, indent + 1);
|
||||
if (childResult !== "") {
|
||||
result += '\n' + currentIndent + '\"图层组: ' + layerName + '\": {' + childResult + '}';
|
||||
}
|
||||
}
|
||||
|
||||
if (i < layerSet.layers.length - 1) {
|
||||
result += ','; // 如果不是最后一个图层或图层组,添加逗号
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
var layersString = "{" + buildLayersString(doc, 0) + "\n}";
|
||||
|
||||
// 删除最后一个逗号
|
||||
layersString = layersString.replace(/,\s*$/, '');
|
||||
|
||||
// 创建文件并写入数据
|
||||
var desktopPath = Folder.desktop.fsName; // 获取桌面路径
|
||||
var filePath = desktopPath + "/photoshop_layers.json"; // 文件完整路径
|
||||
var file = new File(filePath);
|
||||
|
||||
// 打开文件进行写入,并使用GBK编码
|
||||
file.open("w");
|
||||
file.encoding = "GBK";
|
||||
file.write(layersString);
|
||||
file.close();
|
||||
|
||||
alert("文件已保存至桌面: photoshop_layers.json");
|
||||
} else {
|
||||
alert("没有打开的文档");
|
||||
}
|
||||
44
PSMARK代码块/遍历图层.jsx
Normal file
44
PSMARK代码块/遍历图层.jsx
Normal file
@@ -0,0 +1,44 @@
|
||||
// 确保Photoshop中有打开的文档
|
||||
if (app.documents.length == 0) {
|
||||
$.writeln("没有打开的文档!");
|
||||
} else {
|
||||
// 获取当前激活的文档
|
||||
var doc = app.activeDocument;
|
||||
|
||||
// 指定要遍历的图层组名称
|
||||
var targetLayerSetName = "组 1"; // 请替换为您的图层组名称
|
||||
|
||||
// 查找并遍历指定的图层组
|
||||
var targetLayerSet = findLayerSet(doc, targetLayerSetName);
|
||||
if (targetLayerSet != null) {
|
||||
traverseLayers(targetLayerSet, "");
|
||||
} else {
|
||||
$.writeln("未找到名为 '" + targetLayerSetName + "' 的图层组!");
|
||||
}
|
||||
}
|
||||
|
||||
// 函数:查找指定名称的图层组
|
||||
function findLayerSet(doc, name) {
|
||||
for (var i = 0; i < doc.layerSets.length; i++) {
|
||||
if (doc.layerSets[i].name == name) {
|
||||
return doc.layerSets[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 函数:遍历图层
|
||||
function traverseLayers(layerSet, indent) {
|
||||
// 遍历图层组中的所有图层
|
||||
for (var i = 0; i < layerSet.layers.length; i++) {
|
||||
var layer = layerSet.layers[i];
|
||||
|
||||
// 在控制台打印图层名称及其在图层组中的位置
|
||||
$.writeln(indent + layer.name);
|
||||
|
||||
// 如果是图层组,递归遍历该组内的图层
|
||||
if (layer.typename == "LayerSet") {
|
||||
traverseLayers(layer, indent + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user