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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Indesign CS5 - Import XML Using AppleScript

Status
Not open for further replies.

jjjax64

IS-IT--Management
Apr 27, 2010
39
0
0
US
Hi, new to everything about indesign but given task of trying to automate loading data from our database into indesign for our circular print. I can export data from our database to xml and can manually import that data after setting up tags but now looking to automate. I found some samples from indesign and will post below but having trouble understanding how to get it to load actual data from xml automatically. It looks to create text box element but now how to add actual data? I know manually I had to create placeholder text and tag but not sure how to do it in applescript or if I am even going about this the correct way?

Here is the script and xml file and will attach link to picture of what it looks like in indesign. THANKS!


--ImportXMLIntoSelectedElement.applescript
--An InDesign CS5.5 AppleScript
--
--Imports an XML file into the selected XML element.
main()
on main()
mySetup()
mySnippet()
myTeardown()
end main
on mySetup()
tell application "Adobe InDesign CS5.5"
set myDocument to make document
tell myDocument
set myRootElement to XML element 1
set myXMLTag to make XML tag with properties {name:"xml_element"}
tell myRootElement
set myXMLElement to make XML element with properties {markup tag:myXMLTag}
end tell
set myPage to page 1
tell myPage
set myTextFrame to make text frame with properties {geometric bounds:my myGetBounds(myDocument, myPage)}
end tell
end tell
end tell
end mySetup
on mySnippet()
tell application "Adobe InDesign CS5.5"
set myDocument to document 1
--<fragment>
tell myDocument
tell XML import preferences
set import to selected to true
end tell
set myRootElement to XML element 1
set myXMLElement to XML element 1 of myRootElement
select myXMLElement
--You'll have to fill in your own file path.
import XML from "///Applications/tbl_BatchType.xml"
--Place the XML element so that you can see the result.
tell story 1
place XML using myXMLElement
end tell
end tell
--</fragment>
end tell
end mySnippet
on myTeardown()
end myTeardown
on myGetBounds(myDocument, myPage)
tell application "Adobe InDesign CS5.5"
tell document preferences of myDocument
set myPageWidth to page width
set myPageHeight to page height
end tell
tell margin preferences of myPage
if side of myPage is left hand then
set myX2 to left
set myX1 to right
else
set myX1 to left
set myX2 to right
end if
set myY1 to top
set myY2 to bottom
end tell
set myX2 to myPageWidth - myX2
set myY2 to myPageHeight - myY2
return {myY1, myX1, myY2, myX2}
end tell
end myGetBounds


XML

<?xml version="1.0" encoding="UTF-8"?>
<X1>
<tbl>
<btDescription>TestDescription1</btDescription>
</tbl>
<tbl>
<btDescription>TestDescription2</btDescription>
</tbl>
<tbl>
<btDescription>TestDescription3</btDescription>
</tbl>
</X1>

Link to what it looks like in indesign.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top