aijs ctp咬口 自家用
  r30rt1PHwqqA 2023年11月02日 39 0


var pt = 72 / 25.4;
var doc = activeDocument;

//ctp唯一编码
var codePath = "//server/d/info/印刷用文件/ctpCode.txt"

var ctpCode = new Txt(codePath).read();



// if (new Main(1030, 790, 49).work()) {
//     new Txt(codePath, parseInt(ctpCode) + 1).write();
// }
// app.doScript('tif','jialan75')
// if (new Main(760, 605, 47).work()) {
//     new Txt(codePath, parseInt(ctpCode) + 1).write();
// }

if (new Main(550, 433, 28).work()) {
    new Txt(codePath, parseInt(ctpCode) + 1).write();
}

function Main(banCaiWidth, banCaiHeight, banCaiYaoKou) {

    juli = 6;
    this.banCaiWidthStr = banCaiWidth + "";
    this.banCaiWidth = banCaiWidth * pt;
    this.banCaiHeight = banCaiHeight * pt;
    this.banCaiYaoKou = (banCaiYaoKou - juli) * pt;
    this.baibian = 10 * pt;

    this.work = function () {
        for (i = 0; i < doc.artboards.length; i++) {
            var abBounds = doc.artboards[i].artboardRect;
            var left = abBounds[0];
            //拼版宽度
            var impWidth = (abBounds[2] - abBounds[0]);
            //拼版高度
            var impHeight = (abBounds[1] - abBounds[3]);
            //拼版距离页面左边
            var impLeft = (this.banCaiWidth - impWidth) / 2;
            //拼版距离页面底部距离
            var impBottom = this.banCaiHeight - impHeight - this.banCaiYaoKou;

            var p = doc.artboards.length;
            var k = i + 1
            if (p == 1) {
                var str1 = activeDocument.name;
            } else {
                if (i % 2 == 0) {
                    var j = parseInt((i + 1) / 2.1 + 1);
                    var str1 = "【第" + j + "套 正面】" + "【" + p + "-" + k + "】" + activeDocument.name;
                }
                if (i % 2 == 1) {
                    var j = parseInt((i + 1) / 2.1 + 1);
                    var str1 = "【第" + j + "套 反面】" + "【" + p + "-" + k + "】" + activeDocument.name;
                }
            }

            //修改画布
            doc.artboards[i].artboardRect = [abBounds[0] - impLeft, abBounds[1] + impBottom, abBounds[2] + impLeft, abBounds[3] - this.banCaiYaoKou];

            var tx, ty;

            //添加咬口 文字
            tx = left - impLeft + 5 * pt;
            ty = this.baibian + abBounds[3] - this.banCaiYaoKou;
            addText(tx, ty, getCode() + " " + getTime() + "  " + this.banCaiWidthStr + " " + str1, 0, "MicrosoftYaHei", 15, true);

            // 添加上面右边文字
            tx = abBounds[2] + (this.banCaiWidth - (abBounds[2] - abBounds[0])) / 2 - 15 * pt;
            ty = abBounds[1] + (this.banCaiHeight - (abBounds[1] - abBounds[3]) - this.banCaiYaoKou) - 5 * pt;
            addText(tx, ty, getCode(), 180, "MicrosoftYaHei", 8, false);

            // 添加上面右边文字 放大
            tx = abBounds[2] + (this.banCaiWidth - (abBounds[2] - abBounds[0])) / 2 - 15 * pt;
            ty = abBounds[1] + (this.banCaiHeight - (abBounds[1] - abBounds[3]) - this.banCaiYaoKou) - 7.3 * pt;
            addText(tx, ty, ctpCode, 180, "MicrosoftYaHei", 16, false);

            //添加索面左边文字
            tx = abBounds[0] - (this.banCaiWidth - (abBounds[2] - abBounds[0])) / 2 + 3 * pt;
            ty = abBounds[1] + (this.banCaiHeight - (abBounds[1] - abBounds[3]) - this.banCaiYaoKou) - 5 * pt;
            addText(tx, ty, getCode(), 180, "MicrosoftYaHei", 8);

            //添加索面左边文字 放大
            tx = abBounds[0] - (this.banCaiWidth - (abBounds[2] - abBounds[0])) / 2 + 3 * pt;
            ty = abBounds[1] + (this.banCaiHeight - (abBounds[1] - abBounds[3]) - this.banCaiYaoKou) - 7.3 * pt;
            addText(tx, ty, ctpCode, 180, "MicrosoftYaHei", 16, false);



        }
        return true;
    }

    function getTime() {
        var thedate = new Date()
        return thedate.getFullYear() + '/' + (thedate.getMonth() + 1) + '/' + thedate.getDate() + ' ' + thedate.getHours() + ':' + thedate.getMinutes()  //2016-3-5 15:01:08
    }
    function getCode() {
        var name1 = activeDocument.name
        return name1.substring(name1.indexOf('[') + 1, name1.indexOf(']'));
    }

    function addText(x, y, content, rotate, fontName, fontSize, thisHeight) {
        var textFrame = doc.textFrames.add();
        textFrame.left = x;//距离左边的距离
        textFrame.contents = content;
        textFrame.textRange.characterAttributes.size = fontSize; //**********字体大小
        textFrame.textRange.characterAttributes.underline = false; //下划线
        textFrame.textRange.characterAttributes.textFont = textFonts.getByName(fontName);
        textFrame.textRange.characterAttributes.fillColor = getRegColor();//填充颜色
        textFrame.top = y;
        if (thisHeight) {
            textFrame.top += textFrame.height;
        }
        var t = textFrame.createOutline();//是否转曲
        t.rotate(rotate)
    }


    function getRegColor() {
        for (i = 0; i < doc.spots.length; i++) {
            var newSpot1 = doc.spots[i]; //获得套版色
            var s = newSpot1.toString();
            aa = s.indexOf('套');
            bb = s.indexOf('Registration');
            if (bb != -1) {
                var newSpot = doc.spots[i]; //获得套版色
                i = doc.spots.length
            }
            if (aa != -1) {
                var newSpot = doc.spots[i]; //获得套版色
                i = doc.spots.length
            }
        }
        regColor = new SpotColor();
        regColor.spot = newSpot;
        return regColor;

    }
}




function Txt(path, txt) {
    this.path = path;
    this.txt = txt;
    this.read = function () {
        try {
            var f = new File(this.path);//文件位置
            f.open('r');
            var txt = f.read();
            f.close();
            return txt;
        } catch (e) {
            return '0';
        }
    }

    this.write = function () {
        try {
            var f = new File(this.path);//文件位置
            f.open('w');
            f.write(this.txt);
            f.close();
            return txt;
        } catch (e) {
            return '';
        }
    }
}


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  f18CFixvrKz8   2024年05月20日   88   0   0 JavaScript
  fxrR9b8fJ5Wh   2024年05月17日   52   0   0 JavaScript
  2xk0JyO908yA   2024年04月28日   40   0   0 JavaScript
r30rt1PHwqqA
作者其他文章 更多