

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();

