Copy link to clipboard
Copied
Hello
I am trying to create an ExtendScript that takes contents from a FrameMaker document and write it to the Console in the first instance:
This is my attempt:
var doc = app.ActiveDoc;
var firstPgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;floop(firstPgf);
function floop(Pgf){
while(Pgf){
var pgfText = Pgf.GetText(Constants.FTI_String);
Pgf=doc.MainFlowInDoc.FirstTextFrameInFlow.NextPgf;
for(var i=0; i<pgfText.length;i++){
$.writeln(pgfText[i]);
}
$.writeln(pgfText);
}
}
------
The output I get is:
[object TextItem]
Result: undefined
[object TextItem]
[object TextItem]
[object TextItem]
[object TextItem]
[object TextItem]
[object TextItem],[object TextItem],[object TextItem],[object TextItem],[object TextItem]
Result: undefined
The object instances returned seem to be empty or not read at all.
Can you advise?
Thanks
There are some other problems with your code. Here is what you can use for a shell; add the getText function to the bottom of this script:
#target framemaker
main ();
function main () {
var doc;
doc = app.ActiveDoc;
if (doc.ObjectValid () === 1) {
processDoc (doc);
}
}
function processDoc (doc) {
var pgf;
pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
while (pgf.ObjectValid () === 1) {
Console (getText (pgf, doc));
...
Copy link to clipboard
Copied
TextItems can be a little complicated to figure out because you have to know what properties to extract. Here is a function that you call for each paragraph that will give you the paragraph's text:
function getText (textObj, doc) {
// Gets the text from the text object or text range.
var textItems, text, i;
// Get a list of the strings in the text object or text range.
if (textObj.constructor.name !== "TextRange") {
textItems = textObj.GetText (Constants.FTI_String);
}
else {
textItems = doc.GetTextForRange (textObj, Constants.FTI_String);
}
// Concatenate the strings.
text = "";
for (i = 0; i < textItems.len; i += 1) {
text += (textItems[i].sdata);
}
return text; // Return the text
}
Copy link to clipboard
Copied
There are some other problems with your code. Here is what you can use for a shell; add the getText function to the bottom of this script:
#target framemaker
main ();
function main () {
var doc;
doc = app.ActiveDoc;
if (doc.ObjectValid () === 1) {
processDoc (doc);
}
}
function processDoc (doc) {
var pgf;
pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
while (pgf.ObjectValid () === 1) {
Console (getText (pgf, doc));
pgf = pgf.NextPgfInFlow;
}
}
Copy link to clipboard
Copied
Thanks very much. It works.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more