Applying styles to place assest from AppleScript. CS5.5
We are running a script that based on a csv file, loads various elements from a library then imports XML. An example of these elements might be designed to have 4 separate item records within it and each item record might contain a few text boxes and an image and each of these items have xml tags. To better understand, think of a supermarket circular where they might have 4 meat items in one section with a description, size, price and an image. We've broken it into different sections and based on data coming from our database we can relate to a specific element in our indesign library and know how many items will need to be loaded in that section. This all works fine so far and is pretty cool how it loads but we are looking to maybe pass a basic page theme which might be both object and paragraph styles so we'd like to apply these styles through our script because it is possible that different elements might get different styles in same load or even same elements might be re-used in same load and have different styles so really can't define elements with styles we'd like or associate specific xml tages with styles because might be different in each element.
I can in Applescript apply paragraph and object styles to by either index like applying style x to paragraph 1 but would like to do it to element that we placed on page. Here is an example of our script to maybe better understand. Look for comments where we place our assets(elements) on page. Looking to how we can apply style to say paragraph 1 or text frame 1 of placedAsset says can't get text frame 1 or paragraph 1 of group xxx.
Tried variations of:
tell application "Adobe InDesign CS5.5"
set myDocument to active document
set myPage to active page of active window
set placedAsset to place asset asset "7" of library "GT.indl" on myDocument
move placedAsset to {0.65, 0.6}
tell myDocument
set myStyle to paragraph style "Style1"
set objStyle to object style "objStyle"
--This works for just applying styles by index
tell paragraph 1 of text frame 1
apply paragraph style using myStyle
end tell
tell text frame 1
apply object style using objStyle
end tell
--This gives error described above
tell text frame 1 of placedAsset
apply object style using objStyle
end tell
end tell
end tell
----------------------------------------------------------------------------------------
Script which runs now but is not set to apply styles yet:
----------------------------------------------------------------------------------------
try
set CSVstr to "Please locate your CSV file..."
set CSV_File to (choose file with prompt CSVstr) as text
set csvData to read file CSV_File
set csvEntries to paragraphs of csvData
tell application "Adobe InDesign CS5.5"
set myDocument to active document
tell XML view preferences
set show attributes to false
set show structure to true
set show tagged frames to false
set show tag markers to false
set show text snippets to true
end tell
tell XML import preferences
set allow transform to false
set create link to XML to false
set ignore unmatched incoming to true
set ignore whitespace to true
set import CALS tables to true
set import style to merge import
set import text into tables to false
set import to selected to false
set remove unmatched existing to false
set repeat text elements to true
end tell
set myPage to active page of active window
set AppleScript's text item delimiters to ","
repeat with i from 1 to count csvEntries
set csvEntry to csvEntries's item i
set {fldElement, fldLocationX, fldLocationY} to csvEntry's text items
-- display dialog fldElement
set placedAsset to place asset asset fldElement of library "GTElements.indl" on myDocument
move placedAsset to {fldLocationX, fldLocationY}
--This is where we'd like to apply styles to placed asset contents. This placed asset will have a few text frames and at
--least one image. We would just pass extra fields in our csv file with names of styles to be applied
end repeat
set AppleScript's text item delimiters to {""}
tell myDocument
set XMLstr to "Please locate your XML file..."
set XML_File to (choose file with prompt XMLstr)
import XML from XML_File
end tell
tell application "Adobe InDesign CS5.5"
set find text preferences to nothing
set change text preferences to nothing
set find what of find text preferences to "mykzlplx"
set change to of change text preferences to ""
tell active document
change text
end tell
set find text preferences to nothing
set change text preferences to nothing
set find what of find text preferences to "Â"
set change to of change text preferences to ""
tell active document
change text
end tell
set find text preferences to nothing
set change text preferences to nothing
end tell
end tell
end try