1 person found this helpful
The stringFromNumber function in my script somewhere in this post Numbered list style: "One, two, three, four... converts any number (in a reasonable range) to a string. Since it returns a string, you can immediately insert it into any frame, using something like "yourFrame.contents = stringFromNumber (123). This one is home-brewn, there are also other ways -- a quick google shows lots of hits.
(The initCap function is just a little helper, which you may want to use or not. It's only used in the final line of stringToNumber.)
As for 'grabbing a number to convert', you can do this
app.selection.contents = stringFromNumber (Number(app.selection.contents));
to immediately convert a selected number to text. (Go ahead -- copy the functions stringToNumber and initCap and add this line, then try it.)
Grabbing a page number is a bit more complicated -- it's not a real number but a code. Therefore, you have to a bit of digging around inside ID's objects. The frame in which the number will appear, is placed onto a page -- its parent object. This parent page has an index, which is the zero-based actual page number -- regardless of any section numbering. The page also has a name, which is the text that appears in the place of a page number code. It's important to realize it is a text, rather than a number, because "AAB" and "Section 1:xliv" are perfectly good page numbers. I suppose you set up your document to have "normal" page numbers, though, so getting the page number for a selected frame would be
and to immediately insert that number as a word into the frame, all you have to do is
app.selection.contents = stringFromNumber (Number(app.selection.parent.name));
for any selected text frame on a page (which ideally should be empty, because its contents are replaced). (Go ahead -- try this as well!)
You could do this on each of your pages ...
To get an entire list of numbers-to-convert, you could set up a paragraph to include automatic numbering. Remember to remove the default period and tab -- you'll only want the numbers. Hit enter enough times to get all the numbers you need, then select all and convert the automatic numbering to text. Then select the frame and run this script:
list = app.selection.contents.split("\r"); result = ''; for (a=0; a<list.length; a++) result += stringFromNumber(Number(list[a]))+"\r"; app.selection.contents = result;
(Again, it needs the functions stringFromNumber and initCap.)
There are lots of improvements that could be made. A more complicated script could, for example, automatically create a new frame on the correct position per page, set the right font, and insert the number-as-text... But I'll leave it up to your imagination
Wow! I am going to go play with this NOW.
Thank you so much!
Thank you very much, I got this working on a list! Now I can thread this through the document pages.
Of course why settle for this …Now I am going to see if I can somehow apply this to a second page number placeholder on the master and have it auto paginate with numbers as words simultaneously. I really have no idea what I'm doing, but hopefully I will after a while.
Thanks again for such a detailed and quick answer!
Hi, you said you are extremly new to scripting but I can tell I know nothing on scripting. I need to figure out how to convert page numbers to words in a 200 pages-book for children. Can you give me a hand with this by teach me how to do this (step by step) or link me to a good tutorial on this. Thank you very much.
Where to start, when starting from nothing ...
A good starting point is Adobe's own introduction: http://wwwimages.adobe.com/www.adobe.com/eeurope/products/indesign/scripting/pdfs/InDesign CS4_ScriptingTutorial.pdf -- it introduces the basics of writing a script, special handling of ID's environment, and shows lots of little snippets of code to use as "building blocks" of more complicated script.
If you worked your way through that front-to-back, you can start reading from the top of this thread and (hopefully) follow the example scripts and code snippets I wrote for the previous poster.