🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #18739

Re: Newbie contemplating something far too complex?

#18739
From: Olav Kvern
Date: Thu, 27 Feb 2003 23:06
99 lines
3915 bytes
Diane--

This one works for me. Does it work for you?



--SortParagraphs.scpt  
--An InDesign 2.0 script. 
--For more on InDesign scripting, go to  
--http://www.adobe.com/products/indesign/scripting.html 
-- 
--Sorts the selected paragraphs alphabetically. 
set myErrorString to "Please select a range of paragraphs and try again." 
tell application "InDesign 2.0.2" 
	set myTextObjects to {insertion point, character, word, line, text style range, paragraph, text column, text, story} 
	set mySelection to selection 
	if (count mySelection) > 0 and class of item 1 of mySelection is in myTextObjects then 
		set myText to item 1 of mySelection 
		set myNumberOfParagraphs to (count paragraphs of myText) 
		if myNumberOfParagraphs > 1 then 
			set myStory to parent of myText 
			set myStart to my myGetParagraphIndex(index of paragraph 1 of myText, myStory) 
			set myEnd to my myGetParagraphIndex(index of paragraph -1 of myText, myStory) 
			--If the last paragraph is at the end of the story, add a return to the end of the paragraph. 
			set myLastCharacter to character -1 of paragraph -1 of myText 
			if myLastCharacter is not return then 
				set contents of insertion point -1 of paragraph -1 of myText to return 
			end if 
			my mySortParagraphs(myStart, myEnd, myStory) 
			--Deselect the sorted paragraphs. 
			tell application "InDesign 2.0.2" 
				select nothing 
			end tell 
		else 
			my myErrorMessage(myErrorString) 
		end if 
	else 
		my myErrorMessage(myErrorString) 
	end if 
end tell

on myErrorMessage(myErrorString) 
	tell application "InDesign 2.0.2" 
		activate 
		display dialog myErrorString 
	end tell 
end myErrorMessage

on myGetParagraphIndex(myIndex, myStory) 
	tell application "InDesign 2.0.2" 
		repeat with myCounter from 1 to (count paragraphs of myStory) 
			set myStart to index of paragraph myCounter of myStory 
			if myStart is equal to myIndex then 
				return myCounter 
			end if 
		end repeat 
	end tell 
end myGetParagraphIndex

--Bubble sort for sorting paragraphs. 
on mySortParagraphs(myStart, myEnd, myStory) 
	tell application "InDesign 2.0.2" 
		repeat 
			set myItemMoved to false 
			set myCounter to myStart 
			repeat while myCounter is less than myEnd 
				if paragraph (myCounter) of myStory > paragraph (myCounter + 1) of myStory then 
					tell paragraph myCounter of myStory 
						move to after paragraph (myCounter + 1) of myStory 
					end tell 
					set myItemMoved to true 
				end if 
				set myCounter to myCounter + 1 
			end repeat 
			set myCounter to myEnd 
			repeat while myCounter is greater than myStart 
				if paragraph myCounter of myStory < paragraph (myCounter - 1) of myStory then 
					tell paragraph myCounter of myStory 
						move to before paragraph (myCounter - 1) of myStory 
					end tell 
					set myItemMoved to true 
				end if 
				set myCounter to myCounter - 1 
			end repeat 
			if myItemMoved is false then 
				exit repeat 
			end if 
		end repeat 
	end tell 
end mySortParagraphs 




The only difference is that it's set to "InDesign 2.0.2"--could that be the trouble?

Thanks,

Ole
Technical Details
Message-ID: <1de80f24.5@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <1de80f24.-1@WebX.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,45607331d5b88ff9
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-02-27 15:08:05 PST
From: "Olav Kvern" <okvern@adobe.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: Newbie contemplating something far too complex?
Message-ID: <1de80f24.5@WebX.la2eafNXanI>
Date: Thu, 27 Feb 2003 15:06:09 -0800
References: <1de80f24.-1@WebX.la2eafNXanI>
Lines: 105
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit