InDesign外掛--常規功能開發--對齊到頁面--js指令碼開發--ID外掛
Adobe InDesign是Adobe公司的一個桌面出版 (DTP) 的應用程式,主要用於各種印刷品的排版編輯。InDesign可以將文件直接匯出為Adobe的PDF格式,而且有多語言支援。採用指令碼語言自動化編碼,在學習中的一個重要功能是對齊到頁面功能,以下原始碼僅用於學習交流,請勿用於商業用途和其它非法用途。原始碼如下所示:
//AlignToPage.jsx
//An InDesign CS2 JavaScript
//
//Aligns the items in the selection to the specified location on the page.
//
//
//
var myObjectList = new Array;
if (app.documents.length != 0) {
if (app.selection.length != 0) {
for (var myCounter = 0; myCounter < app.selection.length; myCounter++) {
switch (app.selection[myCounter].constructor.name) {
case "Rectangle":
case "Oval":
case "Polygon":
case "TextFrame":
case "Group":
case "Button":
case "GraphicLine":
myObjectList.push(app.selection[myCounter]);
break;
}
}
if (myObjectList.length != 0) {
myDisplayDialog(myObjectList);
} else {
alert("請選擇一個頁面再試——執著Indesign.");
}
} else {
alert("請選擇一個物件再試.");
}
} else {
alert("請開啟一個文件,選擇一個物件再試.");
}
function myDisplayDialog(myObjectList) {
var myDialog = app.dialogs.add({
name: "對齊到頁面"
});
with (myDialog.dialogColumns.add()) {
with (dialogRows.add()) {
with (dialogColumns.add()) {
with (borderPanels.add()) {
staticTexts.add({
staticLabel: "垂直"
});
var myVerticalAlignmentButtons = radiobuttonGroups.add();
with (myVerticalAlignmentButtons) {
radiobuttonControls.add({
staticLabel: "頂",
checkedState: true
});
radiobuttonControls.add({
staticLabel: "中心"
});
radiobuttonControls.add({
staticLabel: "底部"
});
radiobuttonControls.add({
staticLabel: "無"
});
}
}
}
with (dialogColumns.add()) {
with (borderPanels.add()) {
staticTexts.add({
staticLabel: "水平"
});
var myHorizontalAlignmentButtons = radiobuttonGroups.add();
with (myHorizontalAlignmentButtons) {
radiobuttonControls.add({
staticLabel: "靠左",
checkedState: true
});
radiobuttonControls.add({
staticLabel: "中心"
});
radiobuttonControls.add({
staticLabel: "靠右"
});
radiobuttonControls.add({
staticLabel: "無"
});
}
}
}
}
with (dialogRows.add()) {
var myConsiderMarginsCheckbox = checkboxControls.add({
staticLabel: "考慮頁邊空白",
checkedState: false
});
}
}
var myResult = myDialog.show();
if (myResult == true) {
myVerticalAlignment = myVerticalAlignmentButtons.selectedButton;
myHorizontalAlignment = myHorizontalAlignmentButtons.selectedButton;
myConsiderMargins = myConsiderMarginsCheckbox.checkedState;
myDialog.destroy();
myAlignObjects(myObjectList, myVerticalAlignment, myHorizontalAlignment, myConsiderMargins);
} else {
myDialog.destroy();
}
}
function myAlignObjects(myObjectList, myVerticalAlignment, myHorizontalAlignment, myConsiderMargins) {
var myPageHeight = app.activeDocument.documentPreferences.pageHeight;
var myPageWidth = app.activeDocument.documentPreferences.pageWidth;
var myOldRulerOrigin = app.activeDocument.viewPreferences.rulerOrigin;
app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
app.activeDocument.zeroPoint = [0, 0];
var myXCenter = myPageWidth / 2;
var myYCenter = myPageHeight / 2;
var myMarginPreferences = app.activeWindow.activePage.marginPreferences;
var myTopMargin = myMarginPreferences.top;
var myLeftMargin = myMarginPreferences.left;
var myBottomMargin = myMarginPreferences.bottom;
var myRightMargin = myMarginPreferences.right;
if (myConsiderMargins == true) {
switch (myHorizontalAlignment) {
case 0:
myX = myLeftMargin;
break;
case 1:
myX = myXCenter;
break;
case 2:
myX = myPageWidth - myRightMargin;
break;
case 3:
myX = null;
break;
}
switch (myVerticalAlignment) {
case 0:
myY = myTopMargin;
break;
case 1:
myY = myYCenter;
break;
case 2:
myY = myPageHeight - myBottomMargin;
break;
case 3:
myY = null;
break;
}
} else {
switch (myHorizontalAlignment) {
case 0:
myX = 0;
break;
case 1:
myX = myXCenter;
break;
case 2:
myX = myPageWidth;
break;
case 3:
myX = null;
break;
}
switch (myVerticalAlignment) {
case 0:
myY = 0;
break;
case 1:
myY = myYCenter;
break;
case 2:
myY = myPageHeight;
break;
case 3:
myY = null;
break;
}
}
for (myCounter = 0; myCounter < myObjectList.length; myCounter++) {
myAlignObject(myObjectList[myCounter], myX, myY, myHorizontalAlignment, myVerticalAlignment);
}
app.activeDocument.viewPreferences.rulerOrigin = myOldRulerOrigin;
}
function myAlignObject(myObject, myX, myY, myHorizontalAlignment, myVerticalAlignment) {
var myBounds = myObject.geometricBounds;
var myWidth = myBounds[3] - myBounds[1];
var myHeight = myBounds[2] - myBounds[0];
if (myX == null) {
myX = myBounds[1];
}
if (myY == null) {
myY = myBounds[0];
}
switch (myHorizontalAlignment) {
case 0:
break;
case 1:
myX = myX - (myWidth / 2);
break;
case 2:
myX = myX - myWidth;
break;
case 3:
break;
}
switch (myVerticalAlignment) {
case 0:
break;
case 1:
myY = myY - (myHeight / 2);
break;
case 2:
myY = myY - myHeight;
break;
case 3:
break;
}
myObject.move([myX, myY]);
}
合理的指令碼程式碼可以有效的提高工作效率,減少重複勞動。
歡迎光臨知了軟體開發網路平臺,本公司定製開發各類軟體,主要方向為桌面專業軟體開發和外掛定製開發,桌面軟體主要包括文字圖形識別類軟體,資訊管理類軟體,3D列印類軟體,視訊類軟體以及其它涉及專業的各類圖形影像處理軟體。外掛包含AE外掛,AI外掛,PS外掛,PDF外掛,3DMAX外掛以及Word,Excel等Office外掛開發。詳情請諮詢,微信QQ:312117271,手機:18928899728,郵箱: anjingzhi_sea@163.com.
公司網址:http://www.zhiliaos.com
相關文章
- InDesign外掛--常規功能開發--隨機填充--js指令碼開發--ID外掛隨機JS指令碼
- InDesign外掛--常規功能開發--移動選擇專案到指定頁--js指令碼開發--ID外掛JS指令碼
- InDesign外掛--常規功能開發--奇偶頁物件分別移動--js指令碼開發--ID外掛物件JS指令碼
- illustrator外掛--拼版功能開發--印前角線--js指令碼開發JS指令碼
- wordpress外掛開發02-首頁文章自動摘要外掛開發
- chrome 外掛開發Chrome
- flutter 外掛開發Flutter
- 開發Rhino外掛
- VscodeIDEA開發外掛VSCodeIdea
- Skywalking 外掛開發
- Webstorm 外掛開發WebORM
- Flutter外掛開發Flutter
- Mybatis外掛開發MyBatis
- 使用React.js開發Chrome外掛ReactJSChrome
- ZBlog外掛開發檔案結構(外掛)
- apisix~lua外掛開發與外掛註冊API
- dlopen開發外掛庫
- Chrome外掛開發教程Chrome
- eslint外掛開發教程EsLint
- Eclipse外掛開發demoEclipse
- Maven外掛開發教程Maven
- Idea日常開發外掛Idea
- VScode股票外掛開發VSCode
- babel 外掛開發案例Babel
- Vue-外掛開發Vue
- babel外掛開發心得Babel
- Flutter開發之Flutter外掛開發Flutter
- wordpress外掛開發03-簡單的all in one seo 外掛開發
- [外掛擴充套件]js版本分頁外掛套件JS
- 使用 Vite 外掛開發構建 Tampermonkey 使用者指令碼Vite指令碼
- 手把手教你開發 MyBatis 分頁外掛MyBatis
- 使用pgrx開發postgre外掛
- go~wasm外掛的開發GoASM
- Electron 外掛開發實踐
- blazor wasm開發chrome外掛BlazorASMChrome
- Flutter外掛開發---iOS篇FlutteriOS
- Flutter外掛開發---Android篇FlutterAndroid
- Flutter 原生外掛開發流程Flutter