Tuesday, June 27, 2017

#1 2017-06-16 01:21:59 am

changrark
Member
Registered: 2012-04-06
Posts: 3

Placing previous paragraph text tag in next paragraph.

Hi,

I am writing a script for placing previous text tag in next paragraph where no text tag available. But I am stuck to place in third paragraph or so. I have placed my script below, please help.

tell application "Adobe InDesign CS5.5"
    set myDocument to document 1
    set myStory to story 1 of myDocument
    set myDocument to parent of myStory
    set find grep preferences to nothing
    set change grep preferences to nothing
    set include footnotes of find change grep options to false
    set include hidden layers of find change grep options to false
    set include locked layers for find of find change grep options to false
    set include locked stories for find of find change grep options to false
    set include master pages of find change grep options to false
    set myFoundWordTextStringList to {}
    set myFoundWordTextStringLists to {}
    set find what of find grep preferences to "(^<.+?>)(.+\\r)(^[^<].+\\r)+"
    set myStartTags to {"<"}
    set myEndTags to {">"}
    set mm to 0
    set MyFoundWords to find grep
   
    if (count MyFoundWords) is not equal to 0 then
        set myFoundTagsa to {}
        repeat with myCounters from 1 to (count MyFoundWords)
            set myFoundTagm to contents of item myCounters of MyFoundWords
            if myFoundTagsa does not contain myFoundTagm then
                copy myFoundTagm to end of myFoundTagsa
            end if
           
           
            repeat with i from 1 to count of myFoundTagsa
                set find text preferences to nothing
                set change text preferences to nothing
                set find what of find text preferences to item i of myFoundTagsa
                set selection to find text
                repeat with m from 1 to count of every paragraph of selection
                    set myselect to contents of paragraph m of selection
                    set find text preferences to nothing
                    set change text preferences to nothing
                    set find what of find text preferences to myselect
                    set selection to find text
                    if item m of myselect starts with myStartTags then
                        set find what of find grep preferences to "(^<.+?>)"
                        set MyFoundWordss to find grep
                        if (count MyFoundWordss) is not equal to 0 then
                            set myFoundTags to {}
                            repeat with myCounter from 1 to (count MyFoundWordss)
                                set myFoundTag to contents of item myCounter of MyFoundWordss
                                if myFoundTags does not contain myFoundTag then
                                    copy myFoundTag to end of myFoundTags
                                end if
                            end repeat
                        end if
                    end if
                    repeat with k from 1 to count of myFoundTags
                        set myselectiona to item k of myFoundTags
                        if myselectiona is in myselect then
                            set contents of insertion point -1 of selection to myselectiona
                        end if
                    end repeat
                end repeat
            end repeat
        end repeat
    end if
end tell

Offline

 

#2 2017-06-16 12:48:59 pm

Marc Anthony
Member
From: Dallas, TX
Registered: 2006-04-27
Posts: 749

Re: Placing previous paragraph text tag in next paragraph.

Hi. I'm not sure I understand the question; a small before and after text example would be helpful. There's a potential problem in your approach. You shouldn't attempt edits on a selection, as this can affect your search/replace by altering insertion points.

Offline

 

#3 2017-06-19 05:54:02 am

changrark
Member
Registered: 2012-04-06
Posts: 3

Re: Placing previous paragraph text tag in next paragraph.

Hi Marc,

Thanks for your reply. Please refer the text below, about the need.

My text before:

<TX1>Paragraph1
Paragraph2
Paragraph3
Paragraph4
<TX2>Paragraph1
<A-head>Head 1
<TX1>Paragraph1
Paragraph2

I need to apply text tag in Paragraphs like below:
<TX1>Paragraph1
<TX1>Paragraph2
<TX1>Paragraph3
<TX1>Paragraph4
<TX2>Paragraph1
<A-head>Head 1
<TX1>Paragraph1
<TX1>Paragraph2

Offline

 

#4 2017-06-19 12:22:47 pm

Marc Anthony
Member
From: Dallas, TX
Registered: 2006-04-27
Posts: 749

Re: Placing previous paragraph text tag in next paragraph.

Try this:

Applescript:

tell application "Adobe InDesign CS3"
   set find what of find grep preferences to "^<.+>"
   set rawTags to find grep document 1 with reverse order
   set translatedTags to {}
   repeat with aTag in rawTags
       set translatedTags's end to aTag as text
   end repeat
   
   tell document 1
       set counter to 1
       repeat with aPara in (get (story 1's paragraphs)'s object reference)'s reverse
           if aPara does not start with "<" then
               set aPara's beginning to translatedTags's item counter
           else
               set counter to counter + 1
           end if
       end repeat
   end tell
end tell

edited for error introduced by secondary repeat loop, now removed

Last edited by Marc Anthony (2017-06-19 01:44:16 pm)

Offline

 

#5 2017-06-21 12:43:50 am

changrark
Member
Registered: 2012-04-06
Posts: 3

Re: Placing previous paragraph text tag in next paragraph.

Awesome!!!

Thanks Marc.

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.047 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)