🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #16623

Re: Converting prices and currencys

#16623
From: Shane Stanley
Date: Wed, 20 Aug 2003 10:49
50 lines
2788 bytes
This should get you started. It needs more error trapping, but it might save a bit of work if you run it, say, story by story:



 
tell application "InDesign 2.0.2" 
	tell document 1 
		repeat with i from 1 to count of stories -- loop through stories 
			tell story i 
				set thePrices to (every word whose contents begins with "�") -- excludes decimal 
				set thePrices to reverse of thePrices -- we want to work from last to first 
				set thePricesIndex to index of (every word whose contents begins with "�") 
				if class of thePricesIndex is not list then 
					set thePricesIndex to {thePricesIndex} 
				end if 
				set thePricesIndex to reverse of thePricesIndex 
				repeat with j from 1 to count of thePrices 
					set decimalLength to 3 -- characters in decimal 
					set priceLength to length of (item j of thePrices) -- characters in price 
					try 
						-- get decimal 
						set theDecimal to (characters ((item j of thePricesIndex) + priceLength) thru ((item j of thePricesIndex) + priceLength + 2)) as real 
					on error -- chars weren't a number, so no decimal 
						set theDecimal to 0 
						set decimalLength to 0 
					end try 
					-- add decimal to price 
					set thePrice to ((text 2 thru -1 of (item j of thePrices)) as real) + theDecimal 
					-- convert price 
					set newPrice to (thePrice * 1.5) as real as text -- whatever factor is 		relevant		 
					-- trim to two decimal places 
					set priceLength to length of newPrice 
					set pointOffset to offset of "." in newPrice 
					if pointOffset = priceLength - 1 then 
						set newPrice to newPrice & "0" 
					else 
						set newPrice to text 1 thru (pointOffset + 2) of newPrice 
					end if 
					-- insert new price 
					set contents of characters (get item j of thePricesIndex) thru ((item j of thePricesIndex) + priceLength + decimalLength - 2) to "$" & newPrice 
				end repeat 
			end tell 
		end repeat 
	end tell 
end tell 




Shane
Technical Details
Message-ID: <2cccf18e.4@webx.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!diablo.voicenet.com!in.100proofnews.com!in.100proofnews.com!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!webx
References: <2cccf18e.-1@webx.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f939a,6507d8367b744ba0
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-08-20 04:07:51 PST
From: "Shane Stanley" <sstanley@myriad-com.com.au>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!diablo.voicenet.com!in.100proofnews.com!in.100proofnews.com!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!webx
Newsgroups: adobe.scripting.indesign
Subject: Re: Converting prices and currencys
Message-ID: <2cccf18e.4@webx.la2eafNXanI>
Date: Wed, 20 Aug 2003 03:49:29 -0700
References: <2cccf18e.-1@webx.la2eafNXanI>
Lines: 56
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit