InDesign外掛--常規功能開發--奇偶頁物件分別移動--js指令碼開發--ID外掛

安敬知發表於2020-11-04

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


myDialog = app.dialogs.add({
    name: "奇數頁、偶數頁全部物件分別移動",
    canCancel: true
});
myLabelsColumn1 = myDialog.dialogColumns.add();
with (myLabelsColumn1) {
    staticTexts.add({
        staticLabel: "┏━ID頁碼"
    });
    staticTexts.add({
        staticLabel: "開始頁:"
    });
    staticTexts.add({
        staticLabel: "結束頁:"
    });
    staticTexts.add({
        staticLabel: "┌┄奇數頁┄"
    });
    staticTexts.add({
        staticLabel: "水平偏移:"
    });
    staticTexts.add({
        staticLabel: "垂直偏移:"
    });
    staticTexts.add({
        staticLabel: "┌┄偶數頁┄"
    });
    staticTexts.add({
        staticLabel: "水平偏移:"
    });
    staticTexts.add({
        staticLabel: "垂直偏移:"
    });
}
myLabelsColumn2 = myDialog.dialogColumns.add();
myLabelsColumn2.staticTexts.add({
    staticLabel: "━━━━━┓"
});
StartPageField = myLabelsColumn2.realEditboxes.add({
    editValue: 1
});
EndPageField = myLabelsColumn2.realEditboxes.add({
    editValue: 5
});
myLabelsColumn2.staticTexts.add({
    staticLabel: "┄┄┄┄┄┐"
});
OddXField = myLabelsColumn2.measurementEditboxes.add(); //{editUnits:MeasurementUnits.millimeters});
OddYField = myLabelsColumn2.measurementEditboxes.add();
myLabelsColumn2.staticTexts.add({
    staticLabel: "┄┄┄┄┄┐"
});
EvenXField = myLabelsColumn2.measurementEditboxes.add();
EvenYField = myLabelsColumn2.measurementEditboxes.add();
//Display the dialog box.
if (myDialog.show() == true) {
    myDoc = app.activeDocument;
    StartPage = StartPageField.editValue;
    EndPage = EndPageField.editValue;
    OddX = OddXField.editValue;
    OddY = OddYField.editValue;
    EvenX = EvenXField.editValue;
    EvenY = EvenYField.editValue;
    //Save the current measurement units.
    var myOldXUnits = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
    var myOldYUnits = app.activeDocument.viewPreferences.verticalMeasurementUnits;
    //Set the measurement units to points.
    app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
    app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
    //奇數頁、偶數頁迴圈起始及次數
    PagesNum = EndPage - StartPage + 1;
    StartN = Math.round(StartPage / 2);
    EndN = Math.round(EndPage / 2);
    if ((PagesNum % 2 == 0) && (EndPage % 2 == 0)) {
        OddStartN = StartN;
        OddEndN = EndN;
        EvenStartN = StartN;
        EvenEndN = EndN;
    } else if ((PagesNum % 2 == 0) && (EndPage % 2 !== 0)) {
        OddStartN = StartN + 1;
        OddEndN = EndN;
        EvenStartN = StartN;
        EvenEndN = EndN - 1;
    } else if ((PagesNum % 2 !== 0) && (EndPage % 2 == 0)) {
        OddStartN = StartN;
        OddEndN = EndN - 1;
        EvenStartN = StartN;
        EvenEndN = EndN;
    } else if ((PagesNum % 2 !== 0) && (EndPage % 2 !== 0)) {
        OddStartN = StartN;
        OddEndN = EndN;
        EvenStartN = StartN;
        EvenEndN = EndN - 1;
    }
    //奇數頁、偶數頁全部物件分別移動
    for (i = OddStartN; i <= OddEndN; i++) {
        //奇數頁
        myOddPage = myDoc.pages[(2 * i - 1 - 1)];
        //奇數頁全部物件偏移量
        for (Oddobj = 0; Oddobj <= myOddPage.allPageItems.length - 1; Oddobj++) {
            myOddbject = myOddPage.allPageItems[Oddobj];
            myOddbject.move(undefined, [OddX, OddY]);
        }
    }
    //偶數頁全部物件偏移量
    for (i = EvenStartN; i <= EvenEndN; i++) {
        //偶數頁
        myEvenPage = myDoc.pages[(2 * i - 1)];
        for (Evenobj = 0; Evenobj <= myEvenPage.allPageItems.length - 1; Evenobj++) {
            myEvenbject = myEvenPage.allPageItems[Evenobj];
            myEvenbject.move(undefined, [EvenX, EvenY]);
        }
    }
    //Reset the measurement units to their original values.
    app.activeDocument.viewPreferences.horizontalMeasurementUnits = myOldXUnits;
    app.activeDocument.viewPreferences.verticalMeasurementUnits = myOldYUnits;
} else {
    myDialog.destroy();
}

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


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

相關文章