Here’s what I want to do: I will have two documents open in InDesign. Doc 1 will have two text frames full of text. Doc 2 will contain vector images built in InDesign. I want a script that will select all the images in Doc 2 and place them inside the text frame in Doc 1. Ideally it would be able to search for a particular phrase and replace the phrase with the image.
But I wonder if I can even place a vector image from one InDesign document into another, because I can’t even get the following simple script to work:
tell application "Adobe InDesign CS4"
set DocA to document 1 --contains text frames
set DocB to document 2 --contains graphics
tell DocB to get all graphics
set mygraphics to all graphics of DocB
tell DocA
place (mygraphics as alias)
end tell
end tell
Has anyone run into issues with placing elements that have been built in InDesign into another InDesign document?
Thank you all in advance for your help and suggestions.
I think you will need to do a repeat loop, kinda like this (untested):
repeat with myGraphToPlace in mygraphics
place (myGraphToPlace as alias)
end
But I think you will have to create rectangles before you can place the graphs, because all my scripts that place links are done kinda like this:
on placeGraphic(myRectangle, myFile, myFitProportional, myFitCenterContent, myFitFrameToContent)
try
tell application "Adobe InDesign CS4"
tell myRectangle
set myGraphic to place (myFile as string)
--The place command returns a list, so get the
--first item of the list.
set myGraphic to item 1 of myGraphic
set label to (myFile as string)
if myFitProportional is true then
fit given proportionally
end if
if myFitCenterContent is true then
fit given center content
end if
if myFitFrameToContent is true then
fit given frame to content
end if
end tell
return {myGraphic, myRectangle}
end tell
on error errMsg number errNum
tell application "Adobe InDesign CS4" to display alert LocaleError message ((LocaleErrorOccured & " (placeGraphic)" & return & return & errNum & " " & errMsg) as string) buttons {"OK"} default button "OK"
end try
end placeGraphic
helps?
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)
leonsimard
Thank you so much for the examples. Unfortunately I’m kind of a newbie and I can’t seem to get the rectangle subroutine to work. There is no error, but I even added dialogs and those aren’t even being acknowledged either. Any ideas on why this might not be working?
Well, I haven’t done anything close to what you want to do yet, so i’m not sure how it would be done. This involves time that unfortunately I do not have right now, just been back from vacation (thus the delay). I can only give you pointers… I understand the idea behind your script, so here’s my suggestion:
Leave graphics to import in a folder, not a InDesign doc., will be simpler to import them and replace text with a link like you mentionned. Then import the listing of the folder containing these links to import and hold them in a list variable.
You have to search for texts inside your destination ID doc based on the content of the list of links with a repeat loop.
You have to set the selection for this found text.
Import the link that should replace it and tell InDesign to place it at insertion point.
I may have omitted some details, but I think that would do it. Of course, all this is untested.
Sorry I can’t be of much more help! Good luck!
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)