Thanks for your further input Sunshine and Dermot.
In fact it turns out that I don't need to use scripts within EA at all, as I have now found a relatively simple solution to my problem:
RepoDoc, from
Archimetes (
http://www.archimetes.com). Essentially, with RepoDoc you prepare a template in the
liquid template language, using a plain text editor. When I first looked at RepoDoc, it had the liquid feature that supports recursion disabled, but when I explained my problem to Jan at Archimetes, he very quickly produced a development version of RepoDoc and a template that did what I needed in terms of following links from one model element to another to an arbitrary depth. The template was 70 lines long in total. That development version of RepoDoc has now been formally released. I have found the liquid template language easy to learn, but powerful.
This solution won't necessarily be for everyone, because it doesn't support generating Microsoft Word documents. But with the addition of easily available (and free) post-processing tools, RepoDoc can produce good looking documents in pdf format, which is what I want (because I don't agree with providing customer-facing documentation as Microsoft Word documents.)
Disclaimer: I have no connection with Archimetes other than as a (soon to be) customer. I'm just posting what I have found in case it is useful to others.
Thanks, everyone.