Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascripting for InDesign

Status
Not open for further replies.

eugenetyson

Technical User
Aug 21, 2007
1,066
IE
I was wondering if it is possible to create a script that will align a heading depending on if it's in a left hand column or a right hand column. I have text that flows in from a source file, it all comes in fine to a single frame with 2 columns. Each heading has a Keep Option to Start in a New Column. I need the heading in the left column to be always aligned left. And I need the heading in the right column to be always aligned to the right. It's for a book and the usual facing pages apply, single text frame, 2 columns. Is it possible to have a script that only targets a paragraph heading that is in a right column?

Any help is greatly appreciated, I can honestly say I don't know anything about scripting, I just need this for a current project and InDesign doesn't allow alignment for "Align away from gutters" unfortunately.

PS - I have posted this on the Adobe Forums too.

I am a regular contributor to the InDesign section of Tek Tips also, and I don't think anyone over that side of the Fourms knows much about scripting.

Regards


 
My InDesign knowledge is lacking, so apologies if this is completely off-track...

Are we talking about a regular HTML page here, that you could style using CSS? If so, you could apply a class to the left column (e.g. 'leftCol') and the same to the right column, and then use that to perform your alignment, e.g.

Code:
.leftCol .heading {
   text-align: left;
}

.rightCol .heading {
   text-align: right;
}

Like I said, I could be way off here when it comes to InDesign... does it load HTML pages, or does it just use JS to script other elements?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
No it doesn't load html pages, I'm not sure how it works to be honest.

InDesign is a page layout program. It is used for laying out books, magazines, catalogues, brochures, etc.

It's primarily for printing and exporting hi-res pdfs for printing.

Here's a sample script:

//AlignToPage.jsx
//An InDesign CS2 JavaScript
//
//Aligns the items in the selection to the specified location on the page.
//
//
//For more information on InDesign scripting, go to //Or visit the InDesign Scripting User to User forum at //
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 ("Please select a page item and try again.");
}
}
else{
alert ("Please select an object and try again.");
}
}
else{
alert ("Please open a document, select an object, and try again.");
}
function myDisplayDialog(myObjectList){
var myDialog = app.dialogs.add({name:"AlignToPage"});
with(myDialog.dialogColumns.add()){
with(dialogRows.add()){
with(dialogColumns.add()){
with(borderPanels.add()){
staticTexts.add({staticLabel:"Vertical"});
var myVerticalAlignmentButtons = radiobuttonGroups.add();
with(myVerticalAlignmentButtons){
radiobuttonControls.add({staticLabel:"Top", checkedState: true});
radiobuttonControls.add({staticLabel:"Center"});
radiobuttonControls.add({staticLabel:"Bottom"});
radiobuttonControls.add({staticLabel:"None"});
}
}
}
with(dialogColumns.add()){
with(borderPanels.add()){
staticTexts.add({staticLabel:"Horizontal"});
var myHorizontalAlignmentButtons = radiobuttonGroups.add();
with(myHorizontalAlignmentButtons){
radiobuttonControls.add({staticLabel:"Left", checkedState: true});
radiobuttonControls.add({staticLabel:"Center"});
radiobuttonControls.add({staticLabel:"Right"});
radiobuttonControls.add({staticLabel:"None"});
}
}
}
}
with(dialogRows.add()){
var myConsiderMarginsCheckbox = checkboxControls.add({staticLabel:"Consider Page Margins", 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]);
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top