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

Is there some example for creation a TOC for a FM Document?

New Here ,
Dec 11, 2014 Dec 11, 2014

Copy link to clipboard

Copied

I have some ElmScript and want to turn that into an Extendscript, but i have some problems with it.

This is the ElmScript Function.

Sub IHV_Ebene1;

   If fslVersionMajor < 3

      MsgBox 'Ben'+vsoe+'tigt Framescript Version 3 oder neuer';

      LeaveSub;

   EndIf

  

   Set PlatformEncodingMode = True;

   If ActiveDoc = 0

      MsgBox 'Kein aktives Dokument';

      LeaveSub;

   EndIf

  

   Set gvSrcDoc = ActiveDoc;

   GlobalVar gvDocName;

   If gvSrcDoc.Name.Count > 0

      Set gvDocName = gvSrcDoc.Name;

   Else

      Set gvDocName = gvSrcDoc.Label;

   EndIf

  

   New Book File ('tempXXXX.book') NewVar(gvBookVar);

  

   New BookComponent BookObject (gvBookVar) NewVar(gvBookComp);

  

   Set gvBookComp.BookComponentType = BkNotGeneratable;

   Set gvBookComp.Name = gvDocName;

  

   New BookComponent BookObject(gvBookVar) NewVar(gvTocBookComp);

  

   Set gvTocBookComp.BookComponentType = BkToc;

   Set gvTocBookComp.Name = gvDocName+'.TOC';

  

   New StringList NewVar(gvExtractList) Value('Ueberschrift 1 Seite BildSeite') Value('Ueberschrift 1') Value('Ueberschrift 1 mehrzeilig BildSeite');

  

   Set gvTocBookComp.ExtractTags = gvExtractList;

   Set gvTocBookComp.GenerateInclude = True;

   Set gvTocBookComp.InsertLinks = True;

  

   Generate Bookfiles BookObject(gvBookVar) Visible;

  

   Open Document File (gvDocName+'.TOC') NewVar(docobj) ReturnStatus(gvErrorList) Visible;

  

  

   Open Document File ('O:\Fachanwendungen\Vorlagen\FM9_TOC\ti_toc_ohne2_9.fm') NewVar(QuellDok);

 

   Import Formats DocObject(docobj) FromDocObject (QuellDok) RefPage;

   Set ActiveDoc = QuellDok;

   Close Document;

  

   Generate Bookfiles BookObject(gvBookVar) Visible;

  

   Close Book  BookObject(gvBookVar) IgnoreMods;

  

   Set ActiveDoc = docobj;

   Get Object DocObject(docobj) Type(PgfFmt) Name('Inh-Text') NewVar(NeuFormat1);

   Set vPgf = docobj.FirstPgfInDoc;

   Loop While(vPgf)

      If vPgf.Text <> '<$paranum>\t<$paratext>';

         If vPgf.Name = 'Ueberschrift 1IVZ'

            Set vPgf.Properties = NeuFormat1.Properties;

         EndIf

         If vPgf.Name = 'Ueberschrift 1 Seite BildSeiteIVZ'

            Set vPgf.Properties = NeuFormat1.Properties;

         EndIf

         If vPgf.Name = 'Ueberschrift 1 mehrzeilig BildSeiteIVZ'

            Set vPgf.Properties = NeuFormat1.Properties;

         EndIf

      EndIf

      Set vPgf = vPgf.NextPgfInDoc;

   EndLoop

  

   Set vPgf = ActiveDoc;

   Set vPgf.TextSelection = vPgf.FirstPgfInMainFlow.TextRange.Begin;

   Set vPgf.CurrentPage = vPgf.FirstBodyPageInDoc;

  

   If vPgf.CurrentPgf = 0

     MsgBox 'Keine Einfügemarke';

   EndIf

  

   Execute FC CsrTop;

   Execute FC HighFlowEnd;

  

   Copy Text;

  

   Close Document IgnoreMods;

  

   Set ActiveDoc = gvSrcDoc ;

   Set vPgf = ActiveDoc;

   Set vPgf.TextSelection = vPgf.FirstPgfInMainFlow.TextRange.Begin;

   Set vPgf.CurrentPage = vPgf.FirstBodyPageInDoc;

  

   If vPgf.CurrentPgf = 0

     MsgBox 'Keine Einfügemarke';

   EndIf

  

   set vPgf = ActiveDoc.FirstPgfInDoc;

   Loop While(vPgf.Name<>'Inh-Ueberschrift')

      //Display vPgf.Name;

      Set vPgf = vPgf.NextPgfInDoc;

   EndLoop

  

   //Display 'Text: '+vPgf.Text;

   Execute Fc CsrTop;

   Execute Fc CsrNextBop;

   Execute Fc CsrNextBop;

  

   Paste Text;

  

   //MsgBox 'Inhaltverzeichnis generiert'  

EndSub

And This is what i came up with so far:

function IHV_Ebene1()

{     

    var srcDoc = app.ActiveDoc;

    var docName;

    if(srcDoc.Name != "")

    {

            docName = srcDoc.Name;

    }

    else

    {

            docName = srcDoc.Label;

    }

    var gvBookVar = app.NewNamedBook("tempXXXX.book");

    var gvBookComp = gvBookVar.NewSeriesBookComponent(0);

   

    gvBookComp.BookComponentType = Constants.FV_BK_NOT_GENERATABLE;

    gvBookComp.Name = docName;

   

    var gvTocBookComp = gvBookVar.NewSeriesBookComponent(0);

  

    gvTocBookComp.BookComponentType = Constants.FV_BK_TOC;

    gvTocBookComp.Name = docName+".TOC";

  

    var gvExtractList = ["Ueberschrift 1 Seite BildSeite", "Ueberschrift 1", "Ueberschrift 1 mehrzeilig BildSeite"];

   

    gvTocBookComp.ExtractTags = gvExtractList;

    gvTocBookComp.GenerateInclude = true;

    gvTocBookComp.InsertLinks = true;

   

    gvBookVar.SimpleGenerate (false, true);

  

    var docObj = OpenFile(docName + ".TOC", true, true, false, true);

    var QuellDok = OpenFile("O:\\Fachanwendungen\\Vorlagen\\FM9_TOC\\ti_toc_ohne2_9.fm", true, true, false, true);

    docObj.SimpleImportFormats(QuellDok, Constants.FF_UFF_REFPAGE);

    app.ActiveDoc = QuellDok;          

    app.ActiveDoc.Close(Constants.FF_CLOSE_MODIFIED);

   

    gvBookVar.SimpleGenerate (false, true);

    gvBookVar.Close(Constants.FF_CLOSE_MODIFIED);

  

    app.ActiveDoc = docObj;

    var NeuFormat1 = docObj.GetNamedPgfFmt ("Inh-Text");

    var newProps = NeuFormat1.GetProps();

    var mainflow = docObj.MainFlowInDoc;

    var tframe = mainflow.FirstTextFrameInFlow;

    var vPgf = tframe.FirstPgf;

    while(vPgf.ObjectValid())   

    {

         if (vPgf.GetText(Constants.FTI_String) != "<$paranum>\t<$paratext>")

         {

             if (vPgf.Name == "Ueberschrift 1IVZ")

             {

                 vPgf.SetProps (newProps) ;

             }

             if (vPgf.Name == "Ueberschrift 1 Seite BildSeiteIVZ")

             {

                 vPgf.SetProps (newProps) ;

             }

             if (vPgf.Name == "Ueberschrift 1 mehrzeilig BildSeiteIVZ")

             {

                 vPgf.SetProps (newProps) ;

             }

         }

        vPgf = vPgf.NextPgfInDoc;

    }   

        var oPgf = docObj.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

        var oTLoc1 = new TextLoc ( oPgf, 0 );

        var oTLoc2 = new TextLoc ( oPgf, Constants.FV_OBJ_END_OFFSET );

        var oTRange = new TextRange ( oTLoc1, oTLoc2 );

        app.ActiveDoc.TextSelection =oTRange;

        app.ActiveDoc.CurrentPage = app.ActiveDoc.FirstBodyPageInDoc;

  

  // If vPgf.CurrentPgf = 0

//    MsgBox 'Keine Einfügemarke';

//  EndIf

        Fcodes([FCodes.CSR_TOP, FCodes.HIGH_FLOW_END]);

        app.ActiveDoc.Copy(Constants.FF_COPY_TO_CLIP);

        docObj.Close(Constants.FF_CLOSE_MODIFIED);

  

        app.ActiveDoc = srcDoc ;  

           

        var tRange1= new TextRange();       

        tRange1.beg.obj = app.ActiveDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

        tRange1.beg.offset = 0;

        tRange1.end.obj = app.ActiveDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

        tRange1.end.offset = Constants.FV_OBJ_END_OFFSET;

        app.ActiveDoc.TextSelection =tRange1;

        app.ActiveDoc.CurrentPage = app.ActiveDoc.FirstBodyPageInDoc;

  // If vPgf.CurrentPgf = 0

  //   MsgBox 'Keine Einfügemarke';

  // EndIf

     

        mainflow = app.ActiveDoc.MainFlowInDoc;

        tframe = mainflow.FirstTextFrameInFlow;

        vPgf = tframe.FirstPgf;

        while(vPgf.Name != "Inh-Ueberschrift")

        {

            vPgf = vPgf.NextPgfInDoc;

        }

        Fcodes([FCodes.CSR_TOP, FCodes.CSR_NEXT_BOP, FCodes.CSR_NEXT_BOP]);  

        app.ActiveDoc.Paste(Constants.FF_PASTE_CLIP_TEXT);

  

     if(DEBUG) alert("IHV_Ebene1");

    }

Right now it runs without any error messages. But i don´t get the TOC as wanted. It´s inserting some empty space.

I can see it opening an book and the new TOC File with importing refpage. Then i see him selecting the first row of the TOC File(which is empty btw..?!? ) and trying to paste it.

TOPICS
Scripting

Views

441

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 Expert ,
Dec 11, 2014 Dec 11, 2014

Copy link to clipboard

Copied

It is not clear to me what the script is trying to do.

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 ,
Dec 11, 2014 Dec 11, 2014

Copy link to clipboard

Copied

The Script is creating somekind of Table of Contents at the Cursor position.

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 ,
Jan 07, 2015 Jan 07, 2015

Copy link to clipboard

Copied

LATEST

Can a Forum Moderator pls delete this Topic/Discussion?

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