Illustrator腳本開發(fā)刪除文檔專色
發(fā)布時間:2024-11-08 11:58 [ 我要自學網(wǎng)原創(chuàng) ] 發(fā)布人: 快樂小女 閱讀: 126

function main() {

    try {
        app.activeDocument
    } catch (error) {
        alert('請至少打開一個文檔.', "提示")
        return
    }

    var doc = app.activeDocument

    // 獲取專色列表
    var spotList = []
    for (var i = 0; i < doc.spots.length; i++) {
        if (doc.spots[i].colorType == ColorModel.SPOT) {
            spotList.push(doc.spots[i])
        }
    }

    var win = new Window("dialog", "我要自學網(wǎng)案例-刪除文檔的專色")

    if (spotList.length == 0) {
        win.margins = 50
        win.add('statictext', undefined, '當前文檔專色數(shù)量為 "零" ');
    } else {
        win.add('statictext', undefined, "當前文檔共 " + spotList.length + " 個專色, 選擇想要刪除的專色");
        var panelLocation = win.add("panel", undefined, "")
        var checkboxGroup = panelLocation.add("group", undefined)
        checkboxGroup.orientation = "row"
        checkboxGroup.alignChildren = "top"

        var splitNum
        if (spotList.length < 50) {
            splitNum = 5
        } else if (spotList.length < 100) {
            splitNum = 10
        } else if (spotList.length < 200) {
            splitNum = 20
        }

        var checkBoxList = []
        var tempGroup = checkboxGroup
        for (var i = 0; i < spotList.length; i++) {
            if (i % 10 == 0) {
                tempGroup = checkboxGroup.add("group")
                tempGroup.orientation = "column"
                tempGroup.alignChildren = "left"
            }
            checkBoxList.push(tempGroup.add("checkbox", undefined, spotList[i].name))
        }

        var btnGroup = win.add("group", undefined)

        var allBtn = btnGroup.add("button", undefined, "全選")
        var goBtn = btnGroup.add("button", undefined, "執(zhí)行")
        var reAllBtn = btnGroup.add("button", undefined, "反選")

        allBtn.onClick = function () {
            for (var i = 0; i < checkBoxList.length; i += 1) {
                checkBoxList[i].value = true
            }
        }

        reAllBtn.onClick = function () {
            for (var i = 0; i < checkBoxList.length; i += 1) {
                if (checkBoxList[i].value) {
                    checkBoxList[i].value = false
                } else {
                    checkBoxList[i].value = true
                }
            }
        }

        goBtn.onClick = function () {
            var count = 0
            for (var i = 0; i < checkBoxList.length; i += 1) {
                if (checkBoxList[i].value) {
                    spotList[i].remove()
                    count = count + 1
                }
            }
            alert("刪除成功, 共刪除 " + count + " 個專色")
            app.redraw()
            win.close()
        }
    }

    win.onClose = function () {
        panelHeight = win.bounds.height;
        for (var i = 50; i >= 1; i += -2) {
            win.opacity = i / 50;
            $.sleep(1);
            win.bounds.height = panelHeight * (i / 50);
        }

        $.sleep(100);
        callMe()
    }


    win.center()
    win.show()
}

main()

Illustrator腳本開發(fā)教程
我要自學網(wǎng)商城 ¥70 元
進入購買
文章評論
0 條評論 按熱度排序 按時間排序 /350
添加表情
遵守中華人民共和國的各項道德法規(guī),
承擔因您的行為而導(dǎo)致的法律責任,
本站有權(quán)保留或刪除有爭議評論。
參與本評論即表明您已經(jīng)閱讀并接受
上述條款。
V
特惠充值
聯(lián)系客服
APP下載
官方微信
返回頂部
分類選擇:
電腦辦公 平面設(shè)計 室內(nèi)設(shè)計 室外設(shè)計 機械設(shè)計 工業(yè)自動化 影視動畫 程序開發(fā) 網(wǎng)頁設(shè)計 會計課程 興趣成長 AIGC