Illustrator腳本開發(fā)畫板加矩形
發(fā)布時間:2024-11-08 12:01 [ 我要自學(xué)網(wǎng)原創(chuàng) ] 發(fā)布人: 快樂小女 閱讀: 183

function main() {
    if (app.documents.length == 0) {
        alert("請至少打開一個文檔")
        return
    }

    var win = new Window("dialog", "我要自學(xué)網(wǎng)案例-畫板加矩形")
    win.margins = 20

    win.onClose = function () {
        var winHeight = win.bounds.height
        for (var i = 100; i >= 0; i = i - 4) {
            win.opacity = i / 100
            win.bounds.height = winHeight * i / 100
            $.sleep(10)
        }
    }

    var areaPnl = win.add("panel", undefined, "更改范圍")
    areaPnl.orientation = "row"
    areaPnl.margins = 20

    var onlyChoose = areaPnl.add("radiobutton", undefined, "當(dāng)前激活的畫板")
    onlyChoose.value = true
    areaPnl.add("radiobutton", undefined, "當(dāng)前文檔所有畫板")

    var actionGroup = win.add("group")
    var aboutBtn = actionGroup.add("button", [0, 0, 60, 30], "關(guān)于")
    var okBtn = actionGroup.add("button", [0, 0, 60, 30], "執(zhí)行")
    var closeBtn = actionGroup.add("button", [0, 0, 60, 30], "關(guān)閉")

    aboutBtn.onClick = callMe

    okBtn.onClick = function () {
        var artboards = app.activeDocument.artboards
        var layer = app.activeDocument.layers.add()
        var newColor = new CMYKColor()
        newColor.cyan = 0
        newColor.magenta = 100
        newColor.black = 0
        newColor.yellow = 0

        if (onlyChoose.value) {
            var art = artboards[artboards.getActiveArtboardIndex()]

            var left = art.artboardRect[0]
            var top = art.artboardRect[1]
            var width = art.artboardRect[2] - art.artboardRect[0]
            var height = art.artboardRect[1] - art.artboardRect[3]

            var rect = layer.pathItems.rectangle(top, left, width, height)
            rect.fillColor = new NoColor()
            rect.strokeWidth = UnitValue(1, "mm").as("pt")
            rect.strokeColor = newColor

            alert("創(chuàng)建成功")
            win.close()
        } else {
            for (var i = 0; i < artboards.length; i++) {
                var art = artboards[i]

                var left = art.artboardRect[0]
                var top = art.artboardRect[1]
                var width = art.artboardRect[2] - art.artboardRect[0]
                var height = art.artboardRect[1] - art.artboardRect[3]

                var rect = layer.pathItems.rectangle(top, left, width, height)
                rect.fillColor = new NoColor()
                rect.strokeWidth = UnitValue(1, "mm").as("pt")
                rect.strokeColor = newColor
            }

            alert("創(chuàng)建成功")
            win.close()
        }
    }

    closeBtn.onClick = function () {
        win.close() // 關(guān)閉窗口
    }

    win.center()
    win.show()
}

function callMe() {
    var fileName = Folder.temp + "\\關(guān)于我們.url"

    var myFile = new File(fileName)
    myFile.open("w") // write 寫入
    myFile.writeln("[InternetShortcut]")
    myFile.writeln("URL=http://www.51zxw.net/")
    myFile.close()
    myFile.execute()
}

main()

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