//提示框函数
function tan(){
	alert("输入的不是整数,已转换成最接近的整数");
}

//切换到矩形工具函数
function juxing(){
	var idslct = charIDToTypeID( "slct" );
    var desc14 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref6 = new ActionReference();
        var idrectangleTool = stringIDToTypeID( "rectangleTool" );
        ref6.putClass( idrectangleTool );
    desc14.putReference( idnull, ref6 );
    var iddontRecord = stringIDToTypeID( "dontRecord" );
    desc14.putBoolean( iddontRecord, true );
    var idforceNotify = stringIDToTypeID( "forceNotify" );
    desc14.putBoolean( idforceNotify, true );
	executeAction( idslct, desc14, DialogModes.NO );
}


//****新建一个快照
function new_snapshot(){
	var idMk = charIDToTypeID( "Mk  " );
    var desc117 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref38 = new ActionReference();
        var idSnpS = charIDToTypeID( "SnpS" );
        ref38.putClass( idSnpS );
    desc117.putReference( idnull, ref38 );
    var idFrom = charIDToTypeID( "From" );
        var ref39 = new ActionReference();
        var idHstS = charIDToTypeID( "HstS" );
        var idCrnH = charIDToTypeID( "CrnH" );
        ref39.putProperty( idHstS, idCrnH );
    desc117.putReference( idFrom, ref39 );
executeAction( idMk, desc117, DialogModes.NO );
}


//****选择执行历史记录里面的最后一个快照
function last_snapshot(){
	var a =app.activeDocument.historyStates;
	var hist=[];
	for(i=0;i<a.length;i++){
	   if(a[i].snapshot){
	   hist.push(a[i].name);}}
	var kuai = hist[hist.length-1]
	var idslct = charIDToTypeID( "slct" );
    var desc108 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref26 = new ActionReference();
        var idSnpS = charIDToTypeID( "SnpS" );
        ref26.putName( idSnpS, kuai );
    desc108.putReference( idnull, ref26 );
executeAction( idslct, desc108, DialogModes.NO );
}

//移动选中当前图层到顶层
function ding(){
	var idmove = charIDToTypeID( "move" );
    var desc357 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref48 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref48.putEnumerated( idLyr, idOrdn, idTrgt );
    desc357.putReference( idnull, ref48 );
    var idT = charIDToTypeID( "T   " );
        var ref49 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idFrnt = charIDToTypeID( "Frnt" );
        ref49.putEnumerated( idLyr, idOrdn, idFrnt );
    desc357.putReference( idT, ref49 );
executeAction( idmove, desc357, DialogModes.NO );
}

//****多选，选择下一个图层
function xuanxia(){
    // =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc30 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref3 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idBckw = charIDToTypeID( "Bckw" );
        ref3.putEnumerated( idLyr, idOrdn, idBckw );
    desc30.putReference( idnull, ref3 );
    var idselectionModifier = stringIDToTypeID( "selectionModifier" );
    var idselectionModifierType = stringIDToTypeID( "selectionModifierType" );
    var idaddToSelection = stringIDToTypeID( "addToSelection" );
    desc30.putEnumerated( idselectionModifier, idselectionModifierType, idaddToSelection );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc30.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list5 = new ActionList();
        list5.putInteger( 6 );
        list5.putInteger( 7 );
    desc30.putList( idLyrI, list5 );
executeAction( idslct, desc30, DialogModes.NO );

}


//新建图层函数
function xintuceng(){
var idMk = charIDToTypeID( "Mk  " );
    var desc58 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref22 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref22.putClass( idLyr );
    desc58.putReference( idnull, ref22 );
    var idLyrI = charIDToTypeID( "LyrI" );
    desc58.putInteger( idLyrI, 11 );
executeAction( idMk, desc58, DialogModes.NO );
}

//新建图层组
function xinzu(){
var idMk = charIDToTypeID( "Mk  " );
    var desc277 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref102 = new ActionReference();
        var idlayerSection = stringIDToTypeID( "layerSection" );
        ref102.putClass( idlayerSection );
    desc277.putReference( idnull, ref102 );
    var idlayerSectionStart = stringIDToTypeID( "layerSectionStart" );
    desc277.putInteger( idlayerSectionStart, 119 );
    var idlayerSectionEnd = stringIDToTypeID( "layerSectionEnd" );
    desc277.putInteger( idlayerSectionEnd, 120 );
    var idNm = charIDToTypeID( "Nm  " );
    desc277.putString( idNm, """×é 1""" );
executeAction( idMk, desc277, DialogModes.NO );

}

//带像素的数组转化成数字函数
function shu(c){
        var c = c.toString();
    var c = c.substring(0,c.length-2);
    var c = parseFloat(c);
    return c;
    }
function  lujing(cuxi){
// =======================================================
var idMk = charIDToTypeID( "Mk  " );
    var desc74 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref15 = new ActionReference();
        var idcontentLayer = stringIDToTypeID( "contentLayer" );
        ref15.putClass( idcontentLayer );
    desc74.putReference( idnull, ref15 );
    var idUsng = charIDToTypeID( "Usng" );
        var desc75 = new ActionDescriptor();
        var idType = charIDToTypeID( "Type" );
            var desc76 = new ActionDescriptor();
            var idClr = charIDToTypeID( "Clr " );
                var desc77 = new ActionDescriptor();
                var idRd = charIDToTypeID( "Rd  " );
                desc77.putDouble( idRd, 74.000003 );
                var idGrn = charIDToTypeID( "Grn " );
                desc77.putDouble( idGrn, 74.000003 );
                var idBl = charIDToTypeID( "Bl  " );
                desc77.putDouble( idBl, 74.000003 );
            var idRGBC = charIDToTypeID( "RGBC" );
            desc76.putObject( idClr, idRGBC, desc77 );
        var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
        desc75.putObject( idType, idsolidColorLayer, desc76 );
        var idShp = charIDToTypeID( "Shp " );
            var desc78 = new ActionDescriptor();
            var idTrgp = charIDToTypeID( "Trgp" );
            var idPthK = charIDToTypeID( "PthK" );
            var idTrgp = charIDToTypeID( "Trgp" );
            desc78.putEnumerated( idTrgp, idPthK, idTrgp );
        var idpathClass = stringIDToTypeID( "pathClass" );
        desc75.putObject( idShp, idpathClass, desc78 );
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
            var desc79 = new ActionDescriptor();
            var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
            desc79.putInteger( idstrokeStyleVersion, 2 );
            var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );
            desc79.putBoolean( idstrokeEnabled, true );
            var idfillEnabled = stringIDToTypeID( "fillEnabled" );
            desc79.putBoolean( idfillEnabled, false );
            var idstrokeStyleLineWidth = stringIDToTypeID( "strokeStyleLineWidth" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc79.putUnitDouble( idstrokeStyleLineWidth, idPxl, 1.000000 );
            var idstrokeStyleLineDashOffset = stringIDToTypeID( "strokeStyleLineDashOffset" );
            var idPnt = charIDToTypeID( "#Pnt" );
            desc79.putUnitDouble( idstrokeStyleLineDashOffset, idPnt, 0.000000 );
            var idstrokeStyleMiterLimit = stringIDToTypeID( "strokeStyleMiterLimit" );
            desc79.putDouble( idstrokeStyleMiterLimit, 100.000000 );
            var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
            var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
            var idstrokeStyleButtCap = stringIDToTypeID( "strokeStyleButtCap" );
            desc79.putEnumerated( idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleButtCap );
            var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
            var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
            var idstrokeStyleMiterJoin = stringIDToTypeID( "strokeStyleMiterJoin" );
            desc79.putEnumerated( idstrokeStyleLineJoinType, idstrokeStyleLineJoinType, idstrokeStyleMiterJoin );
            var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
            var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
            var idstrokeStyleAlignInside = stringIDToTypeID( "strokeStyleAlignInside" );
            desc79.putEnumerated( idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignInside );
            var idstrokeStyleScaleLock = stringIDToTypeID( "strokeStyleScaleLock" );
            desc79.putBoolean( idstrokeStyleScaleLock, false );
            var idstrokeStyleStrokeAdjust = stringIDToTypeID( "strokeStyleStrokeAdjust" );
            desc79.putBoolean( idstrokeStyleStrokeAdjust, false );
            var idstrokeStyleLineDashSet = stringIDToTypeID( "strokeStyleLineDashSet" );
                var list7 = new ActionList();
            desc79.putList( idstrokeStyleLineDashSet, list7 );
            var idstrokeStyleBlendMode = stringIDToTypeID( "strokeStyleBlendMode" );
            var idBlnM = charIDToTypeID( "BlnM" );
            var idNrml = charIDToTypeID( "Nrml" );
            desc79.putEnumerated( idstrokeStyleBlendMode, idBlnM, idNrml );
            var idstrokeStyleOpacity = stringIDToTypeID( "strokeStyleOpacity" );
            var idPrc = charIDToTypeID( "#Prc" );
            desc79.putUnitDouble( idstrokeStyleOpacity, idPrc, 100.000000 );
            var idstrokeStyleContent = stringIDToTypeID( "strokeStyleContent" );
                var desc80 = new ActionDescriptor();
                var idClr = charIDToTypeID( "Clr " );
                    var desc81 = new ActionDescriptor();
                    var idRd = charIDToTypeID( "Rd  " );
                    desc81.putDouble( idRd, 83.404924 );
                    var idGrn = charIDToTypeID( "Grn " );
                    desc81.putDouble( idGrn, 83.404924 );
                    var idBl = charIDToTypeID( "Bl  " );
                    desc81.putDouble( idBl, 83.404932 );
                var idRGBC = charIDToTypeID( "RGBC" );
                desc80.putObject( idClr, idRGBC, desc81 );
            var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
            desc79.putObject( idstrokeStyleContent, idsolidColorLayer, desc80 );
            var idstrokeStyleResolution = stringIDToTypeID( "strokeStyleResolution" );
            desc79.putDouble( idstrokeStyleResolution, 72.000000 );
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
        desc75.putObject( idstrokeStyle, idstrokeStyle, desc79 );
    var idcontentLayer = stringIDToTypeID( "contentLayer" );
    desc74.putObject( idUsng, idcontentLayer, desc75 );
    var idLyrI = charIDToTypeID( "LyrI" );
    desc74.putInteger( idLyrI, 6 );
executeAction( idMk, desc74, DialogModes.NO );

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc82 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref16 = new ActionReference();
        var iddirectSelectTool = stringIDToTypeID( "directSelectTool" );
        ref16.putClass( iddirectSelectTool );
    desc82.putReference( idnull, ref16 );
    var iddontRecord = stringIDToTypeID( "dontRecord" );
    desc82.putBoolean( iddontRecord, true );
    var idforceNotify = stringIDToTypeID( "forceNotify" );
    desc82.putBoolean( idforceNotify, true );
executeAction( idslct, desc82, DialogModes.NO );

// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc83 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref17 = new ActionReference();
        var idcontentLayer = stringIDToTypeID( "contentLayer" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref17.putEnumerated( idcontentLayer, idOrdn, idTrgt );
    desc83.putReference( idnull, ref17 );
    var idT = charIDToTypeID( "T   " );
        var desc84 = new ActionDescriptor();
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
            var desc85 = new ActionDescriptor();
            var idstrokeStyleContent = stringIDToTypeID( "strokeStyleContent" );
                var desc86 = new ActionDescriptor();
                var idClr = charIDToTypeID( "Clr " );
                    var desc87 = new ActionDescriptor();
                    var idRd = charIDToTypeID( "Rd  " );
                    desc87.putDouble( idRd, 0.000000 );
                    var idGrn = charIDToTypeID( "Grn " );
                    desc87.putDouble( idGrn, 0.000000 );
                    var idBl = charIDToTypeID( "Bl  " );
                    desc87.putDouble( idBl, 0.000000 );
                var idRGBC = charIDToTypeID( "RGBC" );
                desc86.putObject( idClr, idRGBC, desc87 );
            var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
            desc85.putObject( idstrokeStyleContent, idsolidColorLayer, desc86 );
            var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
            desc85.putInteger( idstrokeStyleVersion, 2 );
            var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );
            desc85.putBoolean( idstrokeEnabled, true );
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
        desc84.putObject( idstrokeStyle, idstrokeStyle, desc85 );
    var idshapeStyle = stringIDToTypeID( "shapeStyle" );
    desc83.putObject( idT, idshapeStyle, desc84 );
executeAction( idsetd, desc83, DialogModes.NO );

// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc88 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref18 = new ActionReference();
        var idcontentLayer = stringIDToTypeID( "contentLayer" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref18.putEnumerated( idcontentLayer, idOrdn, idTrgt );
    desc88.putReference( idnull, ref18 );
    var idT = charIDToTypeID( "T   " );
        var desc89 = new ActionDescriptor();
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
            var desc90 = new ActionDescriptor();
            var idstrokeStyleLineWidth = stringIDToTypeID( "strokeStyleLineWidth" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc90.putUnitDouble( idstrokeStyleLineWidth, idPxl, cuxi );
            var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
            desc90.putInteger( idstrokeStyleVersion, 2 );
            var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );
            desc90.putBoolean( idstrokeEnabled, true );
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
        desc89.putObject( idstrokeStyle, idstrokeStyle, desc90 );
    var idshapeStyle = stringIDToTypeID( "shapeStyle" );
    desc88.putObject( idT, idshapeStyle, desc89 );
executeAction( idsetd, desc88, DialogModes.NO );

// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc91 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref19 = new ActionReference();
        var idcontentLayer = stringIDToTypeID( "contentLayer" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref19.putEnumerated( idcontentLayer, idOrdn, idTrgt );
    desc91.putReference( idnull, ref19 );
    var idT = charIDToTypeID( "T   " );
        var desc92 = new ActionDescriptor();
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
            var desc93 = new ActionDescriptor();
            var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
            var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
            var idstrokeStyleSquareCap = stringIDToTypeID( "strokeStyleSquareCap" );
            desc93.putEnumerated( idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleSquareCap );
            var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
            var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
            var idstrokeStyleAlignCenter = stringIDToTypeID( "strokeStyleAlignCenter" );
            desc93.putEnumerated( idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignCenter );
            var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
            desc93.putInteger( idstrokeStyleVersion, 2 );
            var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );
            desc93.putBoolean( idstrokeEnabled, true );
        var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
        desc92.putObject( idstrokeStyle, idstrokeStyle, desc93 );
    var idshapeStyle = stringIDToTypeID( "shapeStyle" );
    desc91.putObject( idT, idshapeStyle, desc92 );
executeAction( idsetd, desc91, DialogModes.NO );
}
//定义画笔函数；
function drawLine(doc, start, stop,cuxi) {

        var startPoint = new PathPointInfo();
            startPoint.anchor = start;
            startPoint.leftDirection = start;
            startPoint.rightDirection = start;
            startPoint.kind = PointKind.CORNERPOINT;
        var stopPoint = new PathPointInfo();
            stopPoint.anchor = stop;
            stopPoint.leftDirection = stop;
            stopPoint.rightDirection = stop;
            stopPoint.kind = PointKind.CORNERPOINT;
        var spi = new SubPathInfo();
            spi.closed = false;
            spi.operation = ShapeOperation.SHAPEXOR;
            spi.entireSubPath = [startPoint, stopPoint];
        var line = doc.pathItems.add("Line", [spi]);
            //app.activeDocument.artLayers.add();
            lujing(cuxi);
            //line.strokePath(ToolType.PENCIL);
            line.remove();
};
//选择上一个图层
function shang(){
    // =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc177 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref158 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idFrwr = charIDToTypeID( "Frwr" );
        ref158.putEnumerated( idLyr, idOrdn, idFrwr );
    desc177.putReference( idnull, ref158 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc177.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list124 = new ActionList();
        list124.putInteger( 82 );
    desc177.putList( idLyrI, list124 );
executeAction( idslct, desc177, DialogModes.NO );

}

//选择下一个图层
function xia(){
// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc122 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref66 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idBckw = charIDToTypeID( "Bckw" );
        ref66.putEnumerated( idLyr, idOrdn, idBckw );
    desc122.putReference( idnull, ref66 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc122.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list47 = new ActionList();
        list47.putInteger( 113 );
    desc122.putList( idLyrI, list47 );
executeAction( idslct, desc122, DialogModes.NO );


}

//取消编组，再新建编组
function quxiaobian(){
    // =======================================================
var idungroupLayersEvent = stringIDToTypeID( "ungroupLayersEvent" );
    var desc25 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref10 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref10.putEnumerated( idLyr, idOrdn, idTrgt );
    desc25.putReference( idnull, ref10 );
executeAction( idungroupLayersEvent, desc25, DialogModes.NO );
}
//再新建编组
function xinjianbian(){
// =======================================================
var idMk = charIDToTypeID( "Mk  " );
    var desc26 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref11 = new ActionReference();
        var idlayerSection = stringIDToTypeID( "layerSection" );
        ref11.putClass( idlayerSection );
    desc26.putReference( idnull, ref11 );
    var idFrom = charIDToTypeID( "From" );
        var ref12 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref12.putEnumerated( idLyr, idOrdn, idTrgt );
    desc26.putReference( idFrom, ref12 );
    var idlayerSectionStart = stringIDToTypeID( "layerSectionStart" );
    desc26.putInteger( idlayerSectionStart, 8 );
    var idlayerSectionEnd = stringIDToTypeID( "layerSectionEnd" );
    desc26.putInteger( idlayerSectionEnd, 9 );
    var idNm = charIDToTypeID( "Nm  " );
    desc26.putString( idNm, """×é 1""" );
executeAction( idMk, desc26, DialogModes.NO );
}


//设置默认单位为像素
function xiangsu(){

var idsetd = charIDToTypeID( "setd" );
    var desc64 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref50 = new ActionReference();
        var idPrpr = charIDToTypeID( "Prpr" );
        var idUntP = charIDToTypeID( "UntP" );
        ref50.putProperty( idPrpr, idUntP );
        var idcapp = charIDToTypeID( "capp" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref50.putEnumerated( idcapp, idOrdn, idTrgt );
    desc64.putReference( idnull, ref50 );
    var idT = charIDToTypeID( "T   " );
        var desc65 = new ActionDescriptor();
        var idRlrU = charIDToTypeID( "RlrU" );
        var idRlrU = charIDToTypeID( "RlrU" );
        var idRrPx = charIDToTypeID( "RrPx" );
        desc65.putEnumerated( idRlrU, idRlrU, idRrPx );
    var idUntP = charIDToTypeID( "UntP" );
    desc64.putObject( idT, idUntP, desc65 );
executeAction( idsetd, desc64, DialogModes.NO );
}


//定义文字大小，位置
function text(s,a0,a3){
    //app.activeDocument.layerSets.add();
    var artLayerRef=app.activeDocument.activeLayer;
    artLayerRef.kind = LayerKind.TEXT;
    var textItemRef = artLayerRef.textItem;
    textItemRef.contents = "测试文字";
    textItemRef.size = s;
    
    
   var a = app.activeDocument.activeLayer.bounds;
    var x =a[0];
    var x= shu(x);
    var y =a[1];
    var y =shu(y);
    artLayerRef.translate(a0-x,a3-y);
}
//多选。同时选中下一个图层
function duoxuan_xia(){
    // =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc111 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref60 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idBckw = charIDToTypeID( "Bckw" );
        ref60.putEnumerated( idLyr, idOrdn, idBckw );
    desc111.putReference( idnull, ref60 );
    var idselectionModifier = stringIDToTypeID( "selectionModifier" );
    var idselectionModifierType = stringIDToTypeID( "selectionModifierType" );
    var idaddToSelection = stringIDToTypeID( "addToSelection" );
    desc111.putEnumerated( idselectionModifier, idselectionModifierType, idaddToSelection );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc111.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list45 = new ActionList();
        list45.putInteger( 91 );
        list45.putInteger( 92 );
    desc111.putList( idLyrI, list45 );
executeAction( idslct, desc111, DialogModes.NO );

}

//***复制图层，移动图层
function copy_move(x,y){
//选择当前选中图层
app.activeDocument.activeLayer;

//复制当前图层
var idCpTL = charIDToTypeID( "CpTL" );
executeAction( idCpTL, undefined, DialogModes.NO );

//移动当前图层
app.activeDocument.activeLayer.translate(x,y);
}

function zuobiao(){

    if(app.activeDocument.activeLayer.typename=="ArtLayer"){
	var a = app.activeDocument.activeLayer.bounds;
	return [a[0] ,a[1] ,a[2] ,a[3]];
  }
  else{
    return(0);
  }
}

//***复制图层，移动图层，(选择下一图层)
function copy_zi(x,y){
	//选择当前选中图层
app.activeDocument.activeLayer;

//复制当前图层
var idCpTL = charIDToTypeID( "CpTL" );
executeAction( idCpTL, undefined, DialogModes.NO );

//移动当前图层
app.activeDocument.activeLayer.translate(x,y);

/*//选择当前图层的下一图层
var idslct = charIDToTypeID( "slct" );
    var desc230 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref77 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idBckw = charIDToTypeID( "Bckw" );
        ref77.putEnumerated( idLyr, idOrdn, idBckw );
    desc230.putReference( idnull, ref77 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc230.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list32 = new ActionList();
        list32.putInteger( 26 );
    desc230.putList( idLyrI, list32 );
executeAction( idslct, desc230, DialogModes.NO );
*/
}
//绘制线条和文字函数
function xian(cuxi,hang,lie,zi){
		xiangsu();
        var fen = app.activeDocument.resolution;
		var a = app.activeDocument.activeLayer.bounds;
        if(shu(a[0])==0 && shu(a[1])==0 &&  shu(a[2])==0 &&  shu(a[3])==0 || app.activeDocument.activeLayer.typename !=="ArtLayer" ) alert("请指定或绘制表格大小");
		else{
            var a0=a[0], a1=a[1] , a2 = a[2] ,a3=a[3];
		app.activeDocument.activeLayer;
		ding();ding();ding();ding();
		app.activeDocument.activeLayer.remove()
		new_snapshot();
		//app.activeDocument.activeLayer.name="*表格大小展示图层*";
		xinzu();
        
        ding();
		xintuceng();
		drawLine(app.activeDocument, [72*shu(a0)/fen,72*shu(a1)/fen], [72*shu(a2)/fen,72*shu(a1)/fen],cuxi);
		for (var i = 0; i < hang; i++) {
			copy_move(0,(shu(a3)-shu(a1))/hang);
		};
		xintuceng();
		drawLine(app.activeDocument, [72*shu(a0)/fen,72*shu(a1)/fen], [72*shu(a0)/fen,72*shu(a3)/fen],cuxi);
		for (var i = 0; i < lie; i++) {
			copy_move((shu(a2)-shu(a0))/lie,0);
		};
		shang();
        quxiaobian();
        xinjianbian();

        app.activeDocument.activeLayer.name="线框组";
		if (zi=="1") {
			xintuceng();
			
			ding();
			
			text(16,shu(a0),shu(a1));
			app.activeDocument.activeLayer.translate(3,0.5*(shu(a3)-shu(a1))/hang-8);
			
				for (var j = 0; j < lie-1; j++) {
                    //if(i==0 && j ==0)continue;
					copy_zi((shu(a2)-shu(a0))/lie,0);
                }
				for(var j = 0; j < lie-1; j++){
                    duoxuan_xia();
                }
                xinjianbian();
                xinjianbian();
                xia();
                for(var i = 0 ; i< hang-1;i++){
                    copy_zi(0,(shu(a3)-shu(a1))/hang);
                }
			};
            
            shang();
            quxiaobian();
            quxiaobian();
             xinjianbian();
             app.activeDocument.activeLayer.name="文字组";
		};		

}


function chexiao(){
	var a =app.activeDocument.layers;
	var b =[];
	for(i=0;i<a.length;i++){
    
     b.push(a[i].name);
    }
	var c =b.join("-");
	var d ="线框组";
	var c = c.indexOf(d);
	if(c>=0){
	last_snapshot();	
	}
	}