Skip to main content
sebinkur
Known Participant
March 16, 2017
Question

Framemaker 12 and Framemaker 15 get stuck after one complete traversal of all Paragraphs in the doc

  • March 16, 2017
  • 4 replies
  • 1819 views

Hi,

I noticed that after one traversal of all paragraphs as given by function 1, framemaker gets stuck and maybe due to that I am unable to execute the while loop in the second function. ($.writeln("CHECK2"); doesn;t get executed)

Please let me know if I am missing out on closing some dangling variables etc. I have attached the code as well.

Thanks,

Sebin

var doc = app.ActiveDoc;

doc.ShowCondIndicators =1;

    var txtFile = "C:/gen_seb.txt";

    var file = new File(txtFile);

    file.open("w"); // open file with write access

    var hash = generate_list(doc);

    find_defined_list_attributes(doc);

    file.close();

function generate_list(doc)

{

    var list = {};

    var pgf= doc.FirstPgfInDoc;

    var cndfmt = doc.FirstCondFmtInDoc;

    var count = 0 ;

    //doc.CondFmtIsShown = 1;

    doc.ShowAll = 0;

   

    while (pgf.ObjectValid()){

             var test = pgf.GetText(Constants.FTI_String); 

             var text, str;

             text = "";

             for (var i=0; i < test.len ; i +=1)

             {

                

                 var str=test .sdata.replace(/^\s+|\s+$/g, '') ;

                  text = text + str;

             } 

        if (pgf.Name == 'Name_1')

        {                      

                            var tr = new TextRange (); 

                            tr.beg.obj = tr.end.obj = pgf; 

                            tr.beg.offset = 0; 

                            tr.end.offset = Constants.FV_OBJ_END_OFFSET;                         

                                var props = doc.GetTextPropVal(tr.beg,Constants.FP_InCond);

                                if(props.propVal.isval.length >0)

                                {

                                   var cnt = 0;

                                   var con_shown = 0;

                                   var propLength= props.propVal.isval.length;

                                   while(cnt<propLength)

                                   {  

                                      if((props.propVal.osval[cnt].CondFmtIsShown))

                                        {

                                            con_shown = 1;

                                            break;

                                        }

                                        else

                                            cnt++;

                                    }

                                       if(con_shown == 1)

                                       {

                                            file.writeln(text);

                                            var regexp = /\(\S+\)/gi;

                                            var regmatch = text.match(regexp);

                                            regmatch=String(regmatch);

                                            regmatch= regmatch.replace(/\(|\)/g, '');

                                                                                      

                                            list[regmatch] = [0,0];

                                       }

                                }

               

        }  

          pgf=pgf.NextPgfInDoc;   

         

}

return reg_list;

}

function find_defined_list_attributes(doc)

{   $.writeln("CHECK1");

    var pgf= doc.FirstPgfInDoc;   

    while (pgf.ObjectValid())

        { $.writeln("CHECK2");

            pgf=pgf.NextPgfInDoc;

        }

   

}

This topic has been closed for replies.

4 replies

Klaus Göbel
Legend
April 9, 2017

Hi Sebin,

thanks to Stefan Gentz https://forums.adobe.com/people/Stefan%20Gentz%20%5BAdobe%5D and the development-team this issue will be solved in update 2.

They worked on it today (Sunday!!) to solve the problem.

MANY THANKS TO THEM ALL.

sebinkur
sebinkurAuthor
Known Participant
April 18, 2017

Hello Klaus,

Thank you so much for the help.

Could you let me know how I could get the "update 2" ? I am currently using Framemaker 12.

Thanks,

Sebin

sebinkur
sebinkurAuthor
Known Participant
March 17, 2017

Hello all,

I think I have narrowed down the problem. For my mif file, I understood that once I iterate through every paragraph (25000 paragraphs in my current mif ) in the document, Framemaker hangs.

If I limit the size of the mif file substantially or limit the while loop like this:  while (pgf.ObjectValid() && count <12000). I can see that Framemaker doesn't hang and I can run the script multiple times over the same document.

I am very new to Framemaker, so it would be great if you could suggest a possible solution to this scenario. FYI, the code that I attached in the previous reply works fine with a smaller mif file.

==================================

var doc = app.ActiveDoc;

    var txtFile = "C:/Users/skuriako/Documents/Framemaker/Junk/dump.txt";

    var file = new File(txtFile);

    var flag1;

    file.open("w");

    generate_reglist(doc);

    file.close();

function generate_reglist(doc){

       var pgf = doc.FirstPgfInDoc;

       var count = 0 ;

       while (pgf.ObjectValid() ){

          count += 1 ;

          pgf=pgf.NextPgfInDoc;  

          }

$.writeln(count);

}

Klaus Göbel
Legend
March 18, 2017

Hi sebinkur,

I guess that it is caused by "$.writeln".

$.writeln is slowing down a script while debugging very much. Also there are known problems with it.

e.g. $.writeln(anynumber) isn't written, but with some text in it : $.writeln("No. :" + anynumber) it is written

I suggest that you try to test it with something like this:

count += 1 ;

count1000 +=1

if (count1000 == 1000)

   {

    $.writeln("Count: " + count);

     count1000 = 0;

     }

sebinkur
sebinkurAuthor
Known Participant
March 20, 2017

Hi Klaus,

I wrote something like what you suggested, but it didn't work for me. The script can only be executed once after which Framemaker is stalled until I force close it.

-Sebin

var doc = app.ActiveDoc;

var pgf = doc.FirstPgfInDoc;

   

var count = 0 ;

var count1000 = 0;

   

while (pgf.ObjectValid() ){

            count += 1 ;

            count1000 +=1  ;

            pgf=pgf.NextPgfInDoc;   

    if (count1000 == 1000) 

    { 

        $.writeln("Count: " + count); 

        count1000 = 0; 

     }

}

4everJang
Legend
March 17, 2017

I can see three things that looks suspicious, but I am only guessing at the goal of the script in the first place.

1. You set Doc.ShowAll to false before starting to process the paragraphs. AFAIK, paragraphs that have a condition applied to them which is currently hidden do not show up as paragraphs at all, so you will miss those in the script.

2. You use a shorthand to assign the same paragraph to two objects: tr.beg.obj = tr.end.obj = pgf;

The scripting wrapper often just copies a pointer and not the entire object. This might cause unexpected results. Better make sure by splitting these two assignments up. Not sure if it makes a difference here, though.

3. You are processing all paragraphs in the document. This includes paragraphs on master and reference pages. My guess is you want to process the paragraphs in the main flow. Start with initializing pfg to Doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf and then walk through the doc using pgf.NextPgfInFlow.

Of course you might get more useful comments when you tell us in words what exactly you want to do with your script. It is hard for me to tell what the logic really is.

sebinkur
sebinkurAuthor
Known Participant
March 17, 2017

Hi,

I reduced the contents of the mif file and ran the same. I was able to execute the above code without framemaker crashing.

Since it is a memory issue, could you please let me know how I could deallocate memory for my text items. I tried using DeallocateTextItems() from the manual but it didn't work.(function is not defined).

Any help in tackling the memory issue would be deeply appreciated.

Thanks,

Sebin

Legend
March 17, 2017

sebinkur,

I don't see any immediate reason why the script would hang, but I see several things that seem suspicious and/or could use improvement.

1 - I don't know what this is:

var list = {};

I'm not the foremost expert in javascript, but that notation doesn't look like anything to me. If you were trying to declare an array, I would expect var list = new Array(). And besides, it doesn't look like this variable is used anywhere anyway.

2 - generate_list() returns reg_list which is not declared anywhere.

3 - generate_list() retrieves the text for every paragraph, whether it is used or not. This is an expensive process. I would move the text retrieval into the if(con_shown ==1) conditional.

4 - To retrieve text properties, you don't need a whole text range, only a text location. For example (note, did not test this);

                           var tl = new TextLoc (); 

                            tl.obj = pgf; 

                            tl.offset = 0; 

                            var props = doc.GetTextPropVal(tl,Constants.FP_InCond);

5 - Overall, the code structure is inefficient, with too many nested conditionals. But this should not cause the problem you are seeing. It just makes the code harder to read and maintain.

6 - You should not need to deallocate any data structures. JavaScript should use automatic trash collection. If it does not, there is a bug. While bugs have been encountered, your code doesn't look extensive enough to exhaust memory even if there were a bug.

I hope this helps some.

Russ

Ian Proudfoot
Legend
March 17, 2017

Russ,

var list = {}; Is normal JavaScript. It's an Object literal and an efficient notation for creating a new empty object. Once it's declared you can add or remove name/value pairs easily.

You can do the same for arrays too like this: var myArray =  [];

Ian