9 Replies Latest reply on May 19, 2008 9:25 PM by (Avi)

    [JS] Problem in importing data.

      Hello

      I am trying to place a .doc file in my document(textframe). For that i am using following script

      var myDocument = app.activeDocument;
      var myTextFrame = myDocument.pages.item(0).textFrames.add({geometricBounds:myGetBounds(myDocument, myDocument.pages.item(0))});
      myTextFrame.place(File(mypath_new));

      But i want to auto-flow the data if i use above script it will place the text on first page only.
      Is there any way to auto-flow the data in InDesign.

      Thank you,
        • 1. Re: [JS] Problem in importing data.
          Level 1
          Hi Avi,

          Instead of creating a frame and then placing the document in it, tell the page to place the document and provide the upper-left margin as the place point, turing autoflow on as you do so. Like this:

          var myBounds = myGetBounds(myDocument, myDocument.pages.item(0));
          var myX = myBounds[1];
          var myY = myBounds[0];
          myDocument.pages.item(0).place(File(mypath_new), [myX, myY], undefined, false, true);

          Thanks,

          Ole
          • 2. Re: [JS] Problem in importing data.
            Level 1
            If you use above code it will create a two text frame one for each column is there any way to flow a data with only one text frame.
            • 3. Re: [JS] Problem in importing data.
              Level 1
              Hi Avi,

              That depends on the column setup for the page. Apply a master spread with one column, and you'll get a one frame per page layout. It's the same as placing text on a page in the user interface--the width of the text frame depends on the column you click in; the top of the text frame depends on the vertical location of the place icon when you click.

              Thanks,

              Ole
              • 4. Re: [JS] Problem in importing data.
                Level 1
                But there is no way that we can merge that two text frame.
                My final aim is to apply a object and paragraph style to that text frame.
                So, please tell me what should i do.

                --Avi
                • 5. Re: [JS] Problem in importing data.
                  Level 1
                  Hi Avi,

                  I don't think you understand what I'm saying. Flowing the text using the code I posted will not create two text frames unless you are placing it on a page with two columns. Set the margin preferences of the page and/or the master spread to use one column, and you will not have two text frames on the page. If you don't have two text frames on the page, then you do not need to merge them.

                  Or it might be that I'm not understanding you--if you mean that placing the document with autoflow on results in the story spanning multiple pages, then--yes, that's what autoflow does. That's what you asked for, as I understood it.

                  To apply an object style to all of the text frames created by the autoflow operation, do this:

                  var myBounds = myGetBounds(myDocument, myDocument.pages.item(0));
                  var myX = myBounds[1];
                  var myY = myBounds[0];
                  //Placing a file returns an array--in this
                  //case, an array containing a single item.
                  var myStory = myDocument.pages.item(0).place(File("/c/AutoflowTest.txt"), [myX, myY], undefined, false, true)[0];
                  //Apply an object style "myTextFrameStyle" to
                  //all of the text frames in the story.
                  for(var myCounter = 0; myCounter < myStory.textContainers.length; myCounter++){
                  myStory.textContainers[myCounter].applyObjectStyle(myDocument.objectStyles.item("myTextFr ameStyle"));
                  }

                  Thanks,

                  Ole
                  • 6. Re: [JS] Problem in importing data.
                    Level 1
                    Thank you Olav.

                    Last question.
                    If you try to apply a paragraph style in same way it will gives you an error. As "myStory.textContainers[myCounter].applyParagraphStyle is not a function"

                    myStory.textContainers[myCounter].applyParagraphStyle(myDocument.paragraphStyleGroups.item ("NYT Byline & Text Styles").paragraphStyles.item("NYT Text"));

                    You can't apply paragraph style in same ways as object style.
                    Is there any way we can apply paragraph style.

                    --Avi
                    • 7. Re: [JS] Problem in importing data.
                      Level 1
                      Hi Avi,

                      Define the paragraph style as part of the object style.

                      Or you can use the applyParagraphStyle method on myStory.texts.item(0)--but it's easier to apply it as part of the object style. (The reason what you're trying to do is not working is that text frames do not have the applyParagraphStyle method--take a look in the object model viewer. Only text stream objects--character, word, paragraph, text, etc., but *not* textFrame--have this method.)

                      Thanks,

                      Ole
                      • 8. Re: [JS] Problem in importing data.
                        Level 1
                        Thank you ole.
                        My script is working.
                        • 9. Re: [JS] Problem in importing data.
                          Level 1
                          There is a problem when you use below script. The error is "Object does not support method or property paragraphStyleGroups "

                          var myStory = myDocument.pages.item(0).place(File(mypath_new), [myX, myY], undefined, false, true)[0];

                          for(var myCounter = 0; myCounter < myStory.textContainers.length; myCounter++)
                          {
                          myStory.textContainers[myCounter].applyObjectStyle(myDocument.objectStyles.item("2 Legs Leading Top"));

                          myStory.texts.item(0).paragraphStyleGroups.item("NYT Byline & Text Styles").paragraphStyles.item("NYT Text");
                          }

                          Can anybody help me to solve this problem.