Vbscript; Placing A Graphic; Applescript - Adobe 65024872 - InDesign CS4 - Mac Manual

Scripting guide
Hide thumbs Also See for 65024872 - InDesign CS4 - Mac:
Table of Contents

Advertisement

Adobe InDesign CS4 Scripting Tutorial

VBScript

Rem Display a standard open file dialog box to select a text file.
Rem VBScript does not have the ability to do this, so we'll use
Rem a JavaScript to get a file name. We'll run the JavaScript using
Rem InDesign's DoScript feature.
Rem Disable normal error handling.
On Error Resume Next
Rem Create a JavaScript as a string.
myJavaScriptString = "var myTextFile = File.openDialog(""Choose a text
file"");myTextFile.fsName;"
Rem Run the JavaScript using DoScript.
myFileName = myInDesign.DoScript(myJavaScriptString, idScriptLanguage.idJavascript)
If Error.Number = 0 Then
Rem Place the text file at the end of the text frame.
myTextFrame.InsertionPoints.Item(-1).Place myFileName
Error.Clear
End If
Rem Restore normal error handling.
On Error GoTo 0

Placing a graphic

Placing a graphic is like importing a text file. Again, the script displays a dialog box you can use to select
the graphic you want to place. When we place the graphic, InDesign returns a reference to the graphic
itself, rather than to the frame containing the graphic. To get a reference to the frame, use the
property of the graphic. Once we have that reference, we can apply an object style to the frame.

AppleScript

--Display a standard open file dialog box to select a graphic file.
set myGraphicFile to choose file "Choose graphic file."
--If a graphic file was selected, and if you didn't press Cancel,
--place the graphic file on the page.
if myGraphicFile is not "" then
set myGraphic to place myGraphicFile on page 1 of myDocument
--Since you can place multiple graphics at once, the place method
--returns an array. To get the graphic you placed, get the first
--item in the array.
set myGraphic to item 1 of myGraphic
--Create an object style to apply to the graphic frame.
try
set myObjectStyle to object style "GraphicFrame" of myDocument on error
--The object style did not exist, so create it.
tell myDocument
end tell
end try
set enable stroke of myObjectStyle to true
set stroke weight of myObjectStyle to 3
set stroke type of myObjectStyle to stroke style "Solid" of myDocument
set stroke color of myObjectStyle to color "Red" of myDocument
--The frame containing the graphic is the parent of the graphic.
set myFrame to parent of myGraphic
tell myFrame to apply object style using myObjectStyle
set myObjectStyle to make object style with properties{name:"GraphicFrame"}
Constructing a document 41
parent

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs4

Table of Contents