On 20 jul 2004, 20:48, kerry...@gmail.com (Kyle M) wrote:
> So does anyone out here usefmPythonat all?
> I'm a newbie to Python, and maybe I just don't understand
> object-oriented programming well enough, but I simply can't getfmPythonto insert text into a FrameMaker document.
....
> Anyone have any ideas as to why the first script is doing nothing?
> Thanks in advance,
> Kyle
For future reference, a follow-up to an old post by "Kyle M On Jul 20
2004" (see below for the complete post. For some reason I wasn't able
to reply to the old thread, so I just post it as a new one)
A FrameMaker document contains more than only the paragraphs on the
Body page: there are paragraphs as well in the Master Page(s) and
Reference Page(s). Moreover, notwithstanding that the "doc.firstPgf"
is the first paragraph in FrameMaker's *list* of paragraphs, this list
does not order the paragraphs as you/I would expect, i.e. the first
paragraph on the Body page doesn't seem to always come first in the
list.
The following script does what you want, i.e. insert something in the
first Body page paragraph of your document:
import maker
doc = maker.session.activeDoc
par=doc.mainFlow.firstFrame.firstPgf
newTxLocation =maker.TxLocation(par, 0)
newTxLocation.addText("hello at the beginning")
newTxLocation =maker.TxLocation(par, maker.symbol.EndOffset-1)
newTxLocation.addText("hello at the end")
To get a list of all paragraphs in your FrameMaker document, you could
execute the following script:
import maker
ses = maker.session
doc = ses.activeDoc
par=doc.firstPgf
c_par=0 #this is just a counter for outputting purposes
print "Starting paragraph loop ..."
do = 1
while do:
try:
c_par = c_par+1
print str(c_par) + " Flow name: " +
str(par.inTextFrame.flow.name) + " Par tag: " + par.name
except RuntimeError:
pass
try:
par = par.nextInDoc
except RuntimeError:
do = 0
print "...Finished paragraph loop"
(Note that there is also a "par.nextInFlow" method which allows you to
cycle through all paragraphs in a flow. If you would set the initial
paragraph to the first paragraph in the main flow - as in the script
above - you could get just the paragraphs in the main flow, which DO
seem to come in the order in which they appear in your document)
On Jul 20 2004, 8:48 pm, kerry...@gmail.com (Kyle M) wrote:
> So does anyone out here usefmPythonat all?
>
> I'm a newbie to Python, and maybe I just don't understand
> object-oriented programming well enough, but I simply can't getfmPythonto insert text into a FrameMaker document.
>
> For example, I found the following code tidbit in a much older thread:
>
> import maker
> doc = maker.session.activeDoc
> newTxLocation = maker.TxLocation(doc.firstPgf,
> maker.symbol.EndOffset-1)
> newTxLocation.addText("hello")
>
> Now I tried running it, but absolutely nothing happens. No text placed
> in the current document. Not even an error in the FrameMaker console.
>
> I do knowfmPythonis working, since I can carry out simple tests that
> output text to the console, like:
> import maker
> doc = maker.session.activeDoc
> print doc.path
>
> This prints out the location of my file in the console.
>
> Anyone have any ideas as to why the first script is doing nothing?
> Thanks in advance,
> Kyle
|