在印刷制版过程中,经常需要移动项目中的内容,本文介绍如何移动的脚本实现方式,源代码如下所示:
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("没有项目被选择,请选择想要移动的项目。");
}
}
}