Hi,
It’s been a long time since I haven’t open a AS dictionary and I have many difficulties to script again. I really need some help !
I’ve got an open document in ID cs5.5 in which I import text from a file (.txt), then find tabulations and replace them with bloc jumps, then select all the text and apply a paragraph style to the first paragraph. but this last operation doesn’t work, and I can’t figure why.
Here is my code :
tell application "Adobe InDesign CS5.5"
activate
-- Init var
set docPub to active document
set cText to "Textes"
set active layer of docPub to cText
set visible of every layer of docPub whose name is not "Textes" to false
set pagePub to page 1 of docPub
set blocDepart to text frame 67 of layer cText of docPub
-- Place texte at beginning
tell insertion point -1 of blocDepart
set fichAnnonce to choose file
place fichAnnonce without showing options
end tell
-- Init find/change fields
set find text preferences to nothing
set change text preferences to nothing
-- Search for tabs then replace with bloc jumps
set find what of find text preferences to "^t"
set change to of change text preferences to "^R"
-- Init find/change options
set case sensitive of find change text options to false
set include footnotes of find change text options to false
set include hidden layers of find change text options to false
set include locked layers for find of find change text options to false
set include locked stories for find of find change text options to false
set include master pages of find change text options to false
set whole word of find change text options to false
-- Run find/change
tell parent story of blocDepart to change text
-- Apply paragraph style : THIS DOESN'T WORK :(
tell docPub
select text 1 of parent story of blocDepart
apply paragraph style using paragraph style "parVille" with clearing overrides
end tell
end tell
In fact, what I would really want to do, is : apply paragraph style to the first paragraph like if I would run the command : right click on the style name in the paragraph style panel in ID and choose “apply paragraph style, then next style.”
Many thanks in advance for your help !
Hi. The reason that last bit isn’t working is that the apply command needs to be directed to an object. It appears that you expect the selection to be that object, but it needs to be a reference to something; this could be a selection”but preferably would not, because that necessitates a selection.
Either of the following formats should be acceptable syntax:
apply paragraph style blocDepart's text's paragraph 1 using paragraph style "parVille" with clearing overrides
tell blocDepart's text's paragraph 1 to apply paragraph style using paragraph style "parVille" clearing overrides yes
Thanks for this first reply. but none of this 2 propositions works
Is it because I’m using layers in my document ?
[EDIT]
Well, in fact. both work (sorry) BUT. because there’s a BUT, even if the paragraph style is applied to the text, I get an Applescript error : “Adobe Indesign CS5.5 error : Incorrect value for the parameter ‘using’ of method ‘apply paragraph style’. paragraph style expected, but nothing received” (it’s a traduction of the error 'cause I use a french version of ID.)
I don’t have access to CS5, but I suspect something could be incorrectly scoped, or actually missing, or just be in need of parentheses. Try:
tell application "Adobe InDesign CS5.5"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(*
SCOPE DETERMINATION
If app is parent, the style needs to be variablized outside the document reference.
This whole segment can be deleted, once known.
*)
try
display dialog (paragraph style "parVille")'s name & " belongs to the app."
on error
try
tell document 1 to display dialog (paragraph style "parVille")'s name & " belongs to the doc."
on error
display dialog "No such style."
end
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
tell document 1
set blocDepart to text frame 67 of layer "Textes"--this assumes extant frame, layer
tell blocDepart's text's paragraph 1 to apply paragraph style using (paragraph style "parVille") clearing overrides yes
end
end
I also recommend downloading the scripting guide and referring to page 104, which further discusses applying styles.
http://www.adobe.com/content/dam/Adobe/en/products/indesign/pdfs/InDesignCS5_ScriptingGuide_AS.pdf
. Same result
The paragraph style is recognised. but I’ve got the same error.
I will try to “flatten” my document to see if the problem comes from the layers.
I also wonder how numbers of text frames are assigned by ID, 'cause it’s a real mess ! Now that I’ve deleted 12 text frames, my first one has number 56.
I’ve already consult the scriptingGuide_AS document (and many others.), but nothing works. Perhaps, I’m in front of an ID’s bug and should try to install it again.
I’ll try to make a little video of what I’d like to script, then post a link there. This way, it would be easier to help me (my english is so far from being perfect.).
Well. I finally figured it out !
The problem was to “reach” the good story.
Here is the (long) working script (that should/could be shorter. I guess. :rolleyes: )
tell application “Adobe InDesign CS5.5”
activate
-- Init var
set docPub to active document
set cText to "Textes"
set active layer of docPub to cText
set blocDepart to text frame 56 of layer cText of docPub
---------------------------------------------------------------------------------------------
set fichAnnonce to choose file
-- Place text in the first text frame
tell insertion point -1 of blocDepart to place fichAnnonce without showing options
---------------------------------------------------------------------------------------------
-- Init find/change fields
set find text preferences to nothing
set change text preferences to nothing
-- Search for tabs then replace with bloc jumps
set find what of find text preferences to "^t"
set change to of change text preferences to "^R"
-- Init find/change options
set case sensitive of find change text options to false
set include footnotes of find change text options to false
set include hidden layers of find change text options to false
set include locked layers for find of find change text options to false
set include locked stories for find of find change text options to false
set include master pages of find change text options to false
set whole word of find change text options to false
-- Run find/change
tell parent story of blocDepart to change text
---------------------------------------------------------------------------------------------
tell docPub
-- Init the target story
set laStory to story 5 of docPub
-- Test every paragraph and character styles in the document
try
set myParVille to paragraph style "parVille"
on error
set myParVille to make paragraph style with properties {name:"parVille"}
end try
try
set myCarVille to character style "carVille"
on error
set myCarVille to make character style with properties {name:"carVille"}
end try
try
set myParType to paragraph style "parType"
on error
set myParType to make paragraph style with properties {name:"parType"}
end try
try
set myCarType to character style "carType"
on error
set myCarType to make character style with properties {name:"carType"}
end try
try
set myParAnnonce to paragraph style "parAnnonce"
on error
set myParAnnonce to make paragraph style with properties {name:"parAnnonce"}
end try
try
set myCarAnnonce to character style "carAnnonce"
on error
set myCarAnnonce to make character style with properties {name:"carAnnonce"}
end try
try
set myParDPE to paragraph style "parDPE"
on error
set myParDPE to make paragraph style with properties {name:"parDPE"}
end try
try
set myCarDPE to character style "carDPE"
on error
set myCarDPE to make character style with properties {name:"carDPE"}
end try
try
set myParPrix to paragraph style "parPrix"
on error
set myParPrix to make paragraph style with properties {name:"parPrix"}
end try
try
set myCarPrix to character style "carPrix"
on error
set myCarPrix to make character style with properties {name:"carPrix"}
end try
---------------------------------------------------------------------------------------------
repeat with i in {1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56}
-- Apply paragraph and character styles "Ville"
tell paragraph i of laStory
apply paragraph style using myParVille with clearing overrides
tell every text
apply character style using myCarVille
end tell
end tell
-- Apply paragraph and character styles "Type"
tell paragraph (i + 1) of laStory
apply paragraph style using myParType with clearing overrides
tell every text
apply character style using myCarType
end tell
end tell
-- Apply paragraph and character styles "Annonce"
tell paragraph (i + 2) of laStory
apply paragraph style using myParAnnonce with clearing overrides
tell every text
apply character style using myCarAnnonce
end tell
end tell
-- Apply paragraph and character styles "DPE"
tell paragraph (i + 3) of laStory
apply paragraph style using myParDPE with clearing overrides
tell every text
apply character style using myCarDPE
end tell
end tell
-- Apply paragraph and character styles "Prix"
tell paragraph (i + 4) of laStory
apply paragraph style using myParPrix with clearing overrides
tell every text
apply character style using myCarPrix
end tell
end tell
end repeat
end tell
end tell
Thanks