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

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.

Hi Marc,

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

My text before:

Paragraph1
Paragraph2
Paragraph3
Paragraph4
Paragraph1
Head 1
Paragraph1
Paragraph2

I need to apply text tag in Paragraphs like below:
Paragraph1
Paragraph2
Paragraph3
Paragraph4
Paragraph1
Head 1
Paragraph1
Paragraph2

Try this:

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

Awesome!!!

Thanks Marc.