InDesign外掛--常規功能開發--移動選擇專案到指定頁--js指令碼開發--ID外掛

安敬知發表於2020-11-04

  Adobe InDesign是Adobe公司的一個桌面出版 (DTP) 的應用程式,主要用於各種印刷品的排版編輯。InDesign可以將文件直接匯出為Adobe的PDF格式,而且有多語言支援。採用指令碼語言自動化編碼,在學習中的一個重要功能是移動選擇專案到指定頁功能,以下原始碼僅用於學習交流,請勿用於商業用途和其它非法用途。原始碼如下所示:

try {
    var myDocument = app.activeDocument;
    with (myDocument) {
        var myselection = selection;
        var myprefs = documentPreferences.properties;
        var mymaxpagenumber = myprefs.pagesPerDocument;
        var theselectcount = selection.length;

        //make the dialog
        var myDialog = app.dialogs.add({
            name: "移動選擇的專案",
            canCancel: true
        });
        with (myDialog) {
            with (dialogColumns.add()) {
                with (borderPanels.add()) {
                    with (dialogColumns.add()) {
                        staticTexts.add({
                            staticLabel: "想要把選擇的專案移動到哪?"
                        });
                        staticTexts.add({
                            staticLabel: "請在後面輸入頁碼"
                        });
                    }
                    with (dialogColumns.add()) {
                        staticTexts.add({
                            staticLabel: ""
                        });
                        var mypageinfo = integerEditboxes.add({
                            minWidth: 40,
                            minValue: 1,
                            maximumValue: mymaxpagenumber
                        });
                    }
                }
                if (theselectcount > 1) {
                    with (borderPanels.add()) {
                        staticTexts.add({
                            staticLabel: "Group Items",
                            minWidth: 102
                        });
                        var myradiogroup = radiobuttonGroups.add();
                        with (myradiogroup) {
                            var myyesradiobutton = radiobuttonControls.add({
                                staticLabel: "Make into a Group",
                                checkedState: true
                            });
                            var mynoradiobutton = radiobuttonControls.add({
                                staticLabel: "Leave as Selected"
                            });
                        }
                    }
                }
            }
        }
        if (myDialog.show() == true) {
            if (theselectcount > 1) {
                var mygroupungroup = myradiogroup.selectedButton;
            }
            var mypage = mypageinfo.editContents;
            myDialog.destroy();
        }

        var myoldviewprefs = viewPreferences.properties
            var myprefs = documentPreferences
            with (myprefs) {
            var mymaxpagenumber = pagesPerDocument
        }
        if (viewPreferences.rulerOrigin = RulerOrigin.spreadOrigin) {
            var myoldorigin = RulerOrigin.spreadOrigin;
            viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
        }
        var currentPage = myDocument.layoutWindows.item(0).activePage
            var myselection = selection;
        var mycount = myselection.length
            if (theselectcount > 1) {
                myStuff = new Array();
                for (i = 0; mycount > i; i++) {
                    myStuff.push(myselection[i]);
                }
                mygroup = app.activeWindow.activePage.groups.add(myStuff);
                var mymovepage = pages.item(mypage - 1)
                    var myBounds = mygroup.geometricBounds
                    var a = myBounds[0]
                    var b = myBounds[1]
                    var c = myBounds[2]
                    var d = myBounds[3]
                    mygroup.move(mymovepage, undefined)
                    mygroup.move([b, a], undefined)
                    if (mygroupungroup == 1)
                        mygroup.ungroup()
            } else {
                var mymovepage = pages.item(mypage - 1)
                    var mysingleselection = selection[0]
                    var myBounds = mysingleselection.geometricBounds
                    var a = myBounds[0]
                    var b = myBounds[1]
                    var c = myBounds[2]
                    var d = myBounds[3]
                    mysingleselection.move(mymovepage, undefined)
                    mysingleselection.move([b, a], undefined)
            }
            app.activeWindow.activePage = mymovepage
            if (myoldorigin = RulerOrigin.spreadOrigin) {
                viewPreferences.rulerOrigin = RulerOrigin.spreadOrigin
            }
    }
} catch (e) {
    if (app.documents.length == 0) {
        alert("沒有已經開啟的InDesign文件,開啟一個文件然後選擇想要移動的專案。");
    } else {
        if (app.selection.length == 0) {
            alert("沒有專案被選擇,請選擇想要移動的專案。");
        }
    }
}

  合理的指令碼程式碼可以有效的提高工作效率,減少重複勞動。


  歡迎光臨知了軟體開發網路平臺,本公司定製開發各類軟體,主要方向為桌面專業軟體開發和外掛定製開發,桌面軟體主要包括文字圖形識別類軟體,資訊管理類軟體,3D列印類軟體,視訊類軟體以及其它涉及專業的各類圖形影像處理軟體。外掛包含AE外掛,AI外掛,PS外掛,PDF外掛,3DMAX外掛以及Word,Excel等Office外掛開發。詳情請諮詢,微信QQ:312117271,手機:18928899728,郵箱: anjingzhi_sea@163.com.
公司網址:http://www.zhiliaos.com

相關文章