-
Notifications
You must be signed in to change notification settings - Fork 30
ExtendScript in InDesign Scripting DOM
###ExtendScript
JavaScript, or EcmaScript, is what brought us in web browsers such things as scrolling by pressing a button, warnings and similar things. ExtendScript is a "dialect" of JavaScript, which was developed by Adobe. This means InDesign understands JavaScript and ExtendScript, but a browser can't do anything with ExtendScript commands.
"The ID Scripting DOOOOOOOOOOOOOOOOM"
wuahahahahahahahah! (Lightning aaaaannnnnddd Thunder)
Now lets have a quick look on how to use all the js in InDesign
/**
* ExtendScript has its extended kind of calling objects
* in the InDesign scripting doom
* like for example item(), lastItem(), everyItem()
* if you try to use them on an javascript array
* you will get an error
*/
var names = ["Paul", "Peter", "Mary", "Jamens", "Hans", "Smeagol", "Estragon"];
try{
alert(names.middleItem());
}catch(e){
alert("The object " + names.constructor.name +" cant do that:\n"+e );
};
// lets build some stuff to play with
// some pages with some text on them
var ph = 50;
var pw = 50;
var count = 0; // for the loop
while (count < names.length){
var doc = app.documents.add({
documentPreferences:{
pageHeight:ph,
pageWidth:pw
}
});
// you can give labels to nearly everything
doc.label = names[count];
var tf = doc.pages.item(0).textFrames.add({
geometricBounds:[ ph/2,0,ph,pw],
contents:names[count]
});
tf.paragraphs.everyItem().justification = Justification.CENTER_ALIGN;
count++;
}
/**
* Now another thing.
* The lastItem() is not the last item created
* The last item is the last item in the collection of
* things you are calling
*/
var list = new Array();
list.push("Last item in collection : " + app.documents.lastItem().label);
list.push("Active Item : " + app.activeDocument.label);
list.push("'app.documents.item(0)' : " + app.documents.item(0).label);
alert("Names\n" + list.join("\n"));
/**
* Now close some of them
*/
var name = app.documents.lastItem().label;
app.documents.lastItem().close(SaveOptions.NO);
alert("closed last item named " + name);
var name = app.documents.middleItem().label;
app.documents.middleItem().close(SaveOptions.NO);
alert("closed last item named " + name);
// use the following piece of code with care:
// Like Uncle Ben saz: "With great power comes great responsibility!"
//~ app.documents.everyItem().close(SaveOptions.NO);
/*
As in javascript in the ID DOM everything is an object
you can for example add a doc with a text frame on the first page with
*/
var aString = "Hello World!\rHello Dude. How are you?\rFine and you?";
var doc = app.documents.add();
var pg = doc.pages[0];
var d_pref = doc.documentPreferences;
var pw = d_pref.pageWidth;
var ph = d_pref.pageHeight;
var x1 = 13;
var y1 = 13;
var x2 = pw - x1;
var y2 = ph - y1;
var gb = [y1, x1, y2, x2];
var tf = pg.textFrames.add();
tf.geometricBounds = gb;
tf.contents = aString;
for(var i = 0; i < tf.paragraphs.length; i++){
var par = tf.paragraphs[i];
alert(par + "-->" + par.contents);
for(var j = 0; j < par.words.length; j++){
alert(par.words[j].contents);
}
}
You can think of the ID DOM as a flow chart. You can access the application and its options the documents. the active document. All pages from a document and all text frames on a page. or all words in a line from a paragraph that is part of a story. This chart shows just a part of the interconnection. It is not automatically generated. Just written up from my head.
This wiki is maintained by:
fabiantheblind
Thanks to:
- JohnDarnell for fixing lots of typos.
- jsp for fixing lots of typos.
- ltfschoen for fixing typos.
- wridgers for adding more links.
Thanks to the students from the seminar for asking all those questions and making me start this wiki.
- adinaradke
- AnitaMei
- ce0311
- coerv
- felixharle
- FerdinandP
- Flave
- marche
- monkian
- natael
- OliverMatelowski
- PDXIII
- praktischend
- schlompf
- skaim
You are awesome.
- Arrays
- Classes
- Comments
- Conditionals
- Functions
- Inspect Properties
- Loops
- Objects
- Output And Interaction
- Recursive Functions
- Inspect Properties
- Variables And Operations
- Extended JavaScript Guide
- Bridge Talk
- Create And Read Files
- ExtendScript Toolkit
- File
- Folder
- Includes JSX
- Object Watch
- Read In JSON From File And DONT Eval
- Storing Data In A Target Engine
- Target an application
- XML
- app
- Colorbrewer
- Colors And Swatches
- Delay And View
- Dialogs
- Documents
- Duplicate And Transform
- Event AfterSave
- Export IDML
- ExtendScript in InDesign Scripting DOM
- Fonts
- GeometricBounds and Coordinates
- Get named pageItems
- Graphic Lines
- Groups
- HSL Color Wheel
- Images
- Includes
- InsertionPoints
- Layers
- Line Feeds And Carrige Returns
- Masterspreads
- Matrix
- Objectstyles
- Outlines Groups Alignment
- Pages And Margins
- Pathfinder
- Placeholder Text
- Rectangles Ovals Polygons
- RulerOrigin
- Select words at insertionPoint
- Simple Find And Change Grep with FC Query
- Simple Find And Change Grep
- Simple Find And Change Text
- Spiro
- Styles
- Text Analysis ID FC
- Text Analysis
- Text Find Locations
- Text
- Transformation Matricies
- TransparencySettings
- XML creation and import