Skip to main content
Participant
November 4, 2020
Answered

Get Content of Pgf

  • November 4, 2020
  • 3 replies
  • 1053 views

Hello again!

 

So my issue today goes as follows:

I have formatted text in my document which I want to 

1. Catch it

2. Write the text to the end of the previous paragraph 

3. Delete the original pgf

 

So here is what I have so far:

 

 //MOVE + DELETE NOTE TEXTS
function MoveNoteText(doc)
{
    
    for(var i = 0; i < countNT; i++){
        
     var note = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
     while (note.ObjectValid()) {
        
     if (note.Name == "Geschenk" || note.Name == "Achtung" || note.Name == "Hinweis") {
             
             pgf = note.PrevPgfInFlow;
             tl = new TextLoc(pgf, Constants.FV_OBJ_END_OFFSET-1);
             doc.AddText(tl, "PLACEHOLDER-TEXT-ICON");         
             
             note.Delete();
             } 
          else if(note.Name == "Hinweis_text") {
             
             text = Content of Paragraph should be caught here
             pgf = note.PrevPgfInFlow;
             tl = new TextLoc(pgf, Constants.FV_OBJ_END_OFFSET-1);
             doc.AddText(tl, text); 
             
             note.Delete();
             }
         
         note = note.NextPgfInFlow;
         
      }
   }
}

I am stuck at the point on which I want to get the text inside the pgf (if "Hinweis_text") ... Dont know how to do that. I kind of found out how to get the Text Items: 

 

text = note.GetText(-1); //To get all TI

 

But how can I fetch the text?

 

Thanks in advance!

This topic has been closed for replies.
Correct answer Klaus Göbel

 

Your code line:

pgf = note.PrevPgfInFlow;

After that insert :

var NewText = GetTextFromPgf(pgf);

 

And the add this function:

function GetTextFromPgf(foPgf)
{
var locTextItems = foPgf.GetText (Constants.FTI_String);

var sTestText = "";
for (var i = 0; i <= locTextItems.length -1; i++)
{
sTestText = sTestText + locTextItems[i].sdata;
}

return sTestText;

}

3 replies

Klaus Göbel
Legend
November 9, 2020

Hi Yannick,

the whole answer would be very time consuming, because it's not only ONE answer.

 

But I could give you some hints:

 

doc.MainFlowInDoc.GetText(Constants.FTI_TblAnchor)

 That gives you an array of textitems. Textitems does NOT mean, that it is text.

In this case it's TableAnchors.

 

 

var oTextItems = doc.MainFlowInDoc.GetText(Constants.FTI_TblAnchor)
var Table = oTextItems[0].obj // here you get the "REAL" table. Make sure that a table exists. You can use a loop to go through
var oRow = oTable.FirstRowInTbl;    // First row in the table
    
var oLastRow = oTable.FirstRowInTbl;    // Last row in the table
var oCell = oRow.FirstCellInRow;   
var oPgf = oCell.FirstPgf // here you get a PGF - go on with NextPgf to find all Pgfs in Cell
var PgfFmt =  oPgf.Name  // PgfFmt

oRow.Delete(); // Delete the row.

 

Hope it helps a bit.

Participating Frequently
November 10, 2020

Hey again!

 

Thank you very much! You are my hero haha^^

I figured it out with your help again.

 

Big greetings

Yannick

Klaus Göbel
Klaus GöbelCorrect answer
Legend
November 4, 2020

 

Your code line:

pgf = note.PrevPgfInFlow;

After that insert :

var NewText = GetTextFromPgf(pgf);

 

And the add this function:

function GetTextFromPgf(foPgf)
{
var locTextItems = foPgf.GetText (Constants.FTI_String);

var sTestText = "";
for (var i = 0; i <= locTextItems.length -1; i++)
{
sTestText = sTestText + locTextItems[i].sdata;
}

return sTestText;

}
Participant
November 4, 2020

Thanks! This worked just perfectly.

Really appreciate your help!

Klaus Göbel
Legend
November 4, 2020

You're welcome - gern geschehen

Klaus Göbel
Legend
November 4, 2020

Hi Yannick,

have a look at this :https://community.adobe.com/t5/framemaker/script-no-longer-working/m-p/11071057?page=1

 

Look for "function getText (textObj, doc)"

Participant
November 4, 2020

Hi Klaus,

 

I don't really get how to get this working sorry...

I tried this:

             textObjs = note.GetText(-1);
             
             for(var x = 0; x < textObj.length; x++) {
                  text += textObj[x].GetText(Constants.FTI_String);
                 }
             

First I get all the text items in the paragraph, then I try to put them together. However, this code gives an error.