#target indesign
app.documents.add();
app.documents[0].save()
To add content to a text frame, we firstly need to create the text frame. If we were doing it by hand, we would:
- use the Type Tool to add a text frame
- set the dimensions of the text frame by how big we drag the frame out
- type something into the text frame
Add a text frame and set it's size
To add the text frame via scripting, we use the textFrames.add() method, and set its size with geometricBounds: [top, left, bottom, right], where top, left, bottom and right are the dimensions of the text frame.
app.documents[0].pages[0].textFrames.add({geometricBounds:[40,40,180,180]});
Add Content
To make our code easier to read, let's assign a variable name to the text frame we just created. Like this:
var myFrame = app.documents[0].pages[0].textFrames[0];
So to place content into myFrame, use
myFrame.contents = "Hello world";
Here is the complete script
Next up I'll show how to import a Word file.
No comments:
Post a Comment