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

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

    var win = new Window("dialog", "我要自學網案例-畫板加矩形")
    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, "當前激活的畫板")
    onlyChoose.value = true
    areaPnl.add("radiobutton", undefined, "當前文檔所有畫板")

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

    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() // 關閉窗口
    }

    win.center()
    win.show()
}

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