0 Replies Latest reply on Oct 9, 2013 12:30 PM by Dan-BTP

    Replicating JavaScript script with VB.NET

    Dan-BTP Level 1

      I have the following JavaScript script that works as I wish:

       

      var thisPgf = NothingEnum.nothing;

      var thisStory = NothingEnum.nothing;

       

      var articleTitle = "";

      var contentID = 0;

      var filePath = "";

       

      // Open template

       

      var doc = app.open('C:\\Library\\Library Book Template.indt');

       

      // Add articles

       

      var articleList = [56123, 56132, 56138, 56149, 56157, 56168, 56177, 56186, 56194];

       

      for (var i = 0; i < articleList.length; i++) {

          contentID = String(articleList[i]);

          articleTitle = "Article #" + contentID;

             

          thisStory = doc.pages.lastItem().textFrames.lastItem().parentStory;

          thisStory.insertionPoints.item(-1).contents += articleTitle;

         

          thisPgf = thisStory.paragraphs.lastItem();

          thisPgf.appliedParagraphStyle = doc.paragraphStyles.item("Heading");

         

          thisStory.insertionPoints.item(-1).contents += "\r";

         

          doc.recompose();

         

          filePath = "C:\\Library\\" + contentID.substr(0, 2) + "\\" + contentID + "\\" + contentID + ".rtf";

          thisStory.insertionPoints.item(-1).place(filePath);

         

          doc.recompose();

          }

       

      I need to replicate this script in a VB.NET program. Here is how I've done it:

       

          Dim IdApp As InDesign.Application = CType(Activator.CreateInstance(Type.GetTypeFromProgID("InDesign.Application"), True), InDesign.Application)

          Dim IdDoc As InDesign.Document = IdApp.Open(TemplateFilePath, False)

       

          For I = 1 To NumArticles

            ContentID = ArticleList(I).ToString

            ArticleTitle = "Article #" & ContentID

       

            ImportFilePath = "C:\Library\" & Left(ContentID, 2) & "\" & ContentID & "\" & ContentID & ".rtf"

       

            ThisPage = IdDoc.Pages.LastItem

            ThisFrame = ThisPage.TextFrames.LastItem

            ThisStory = ThisFrame.ParentStory

       

            ThisStory.InsertionPoints.Item(-1).Contents &= ArticleTitle

       

            ThisPgf = ThisStory.Paragraphs.LastItem

            ThisPgf.AppliedParagraphStyle = HeadingPgfStyle

       

            ThisStory.InsertionPoints.Item(-1).contents &= vbCr

       

            IdDoc.Recompose()

       

            ThisPage = IdDoc.Pages.LastItem

            ThisFrame = ThisPage.TextFrames.LastItem

            ThisStory = ThisFrame.ParentStory

       

            ThisStory.InsertionPoints.Item(-1).Place(ImportFilePath)

       

            IdDoc.Recompose()

          Next I

       

      What is frustrating me is that when I open the INDD file that is saved at the end of my VB.NET program, the text does not automatically flow onto as many pages as are needed. I have Primary Text Frame checked in InDesign. I have Smart Text Reflow checked, and the left and right master pages of the template document have one text frame each, each of which is designated as a primary text frame.

       

      I have tried putting the last Recompose() statement in a loop, not exiting the loop until the Overflows property for the text frame on the last page is false, but nothing makes it flow automatically.

       

      Is there a different way that I should be doing this? Thanks!