• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Get Content of Pgf

New Here ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

439

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Nov 04, 2020 Nov 04, 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;

}

Votes

Translate

Translate
Enthusiast ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

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)"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

 

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

Thanks! This worked just perfectly.

Really appreciate your help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

You're welcome - gern geschehen

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

Maybe one more question here:

 

Lets say I have the same format I picked the pgfs with as tables with anchors.

I am playing around at the moment, trying to figure out how to pick the table. 

So far I am only able to select the anchor but as i need the text inside the table I asked myself if there is a way to kind of tell the script "here's your anchor, so now jump into the table (second column) and extract the text there. I know it might be better to select the tables right away, not by the anchor but I can't select them via "FirstTableInDoc -> if(table.Name == whatever)" somehow. 

 

Would be great if you (or someone else) could give me some hint there^^ 

 

Thanks again!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

Hi Yannick,

here you find several examples how to handle tables and cells:

http://extendingframemaker.blogspot.com/2011/12/tables.html

- creating tables

- adding row to table

- adding columns to table

- getting table cells row by row

and so on....

That helped me when I started scripting. I'm sure, it will help you, too.

 

If that doesn't answer your questions, just drop a line here in the forum

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

Hi Klaus... again,

 

I am sorry, but i am really struggling with this. 

As stated in the blow, I need to use the

doc.MainFlowInDoc.GetText(Constants.FTI_TblAnchor); to get the tables in flow order. 

 

But what exactly do I get here? Does this fetch all Tables? Or just the TextItems in the first Table? How am I able to iterate through and select the table by formats within the cells?

I have tables with one row and two columns. 

-> I need to get the format of the text in the first column (first cell (only cell)) and distinguish. Something 

     like tbl.FirstColumnInTbl.Name (I know that this doesn't work)

-> After that I delete the first column depending on the format

-> Then jumo to the next column with, get format too, save the text within and write it in the previous 

     as I did before with your help.

-> Then delete this column too (maybe skip deletion of first column and delete the whole table here)

 

I am still stuck by figuring out how I can even iterate throuch and find the tables with the wanted formats within.

 

Sorry again, I am usually not working with this, just started like 2 or 3 weeks ago and yeah... 

 

Thanks for your help again!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

Lol, sorry for all the typos... Hope it's still readable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 10, 2020 Nov 10, 2020

Copy link to clipboard

Copied

LATEST

Hey again!

 

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

I figured it out with your help again.

 

Big greetings

Yannick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines