Illustrator腳本開(kāi)發(fā)刪除文檔專(zhuān)色
發(fā)布時(shí)間:2024-11-08 11:58 [ 我要自學(xué)網(wǎng)原創(chuàng) ] 發(fā)布人: 快樂(lè)小女 閱讀: 145

function main() {

    try {
        app.activeDocument
    } catch (error) {
        alert('請(qǐng)至少打開(kāi)一個(gè)文檔.', "提示")
        return
    }

    var doc = app.activeDocument

    // 獲取專(zhuān)色列表
    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", "我要自學(xué)網(wǎng)案例-刪除文檔的專(zhuān)色")

    if (spotList.length == 0) {
        win.margins = 50
        win.add('statictext', undefined, '當(dāng)前文檔專(zhuān)色數(shù)量為 "零" ');
    } else {
        win.add('statictext', undefined, "當(dāng)前文檔共 " + spotList.length + " 個(gè)專(zhuān)色, 選擇想要?jiǎng)h除的專(zhuān)色");
        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 + " 個(gè)專(zhuān)色")
            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腳本開(kāi)發(fā)教程
我要自學(xué)網(wǎng)商城 ¥70 元
進(jìn)入購(gòu)買(mǎi)
文章評(píng)論
0 條評(píng)論 按熱度排序 按時(shí)間排序 /350
添加表情
遵守中華人民共和國(guó)的各項(xiàng)道德法規(guī),
承擔(dān)因您的行為而導(dǎo)致的法律責(zé)任,
本站有權(quán)保留或刪除有爭(zhēng)議評(píng)論。
參與本評(píng)論即表明您已經(jīng)閱讀并接受
上述條款。
V
特惠充值
聯(lián)系客服
APP下載
官方微信
返回頂部
分類(lèi)選擇:
電腦辦公 平面設(shè)計(jì) 室內(nèi)設(shè)計(jì) 室外設(shè)計(jì) 機(jī)械設(shè)計(jì) 工業(yè)自動(dòng)化 影視動(dòng)畫(huà) 程序開(kāi)發(fā) 網(wǎng)頁(yè)設(shè)計(jì) 會(huì)計(jì)課程 興趣成長(zhǎng) AIGC