4 Replies Latest reply on May 12, 2017 1:43 PM by Rich.D

    Formatting imported text


      I have an existing InDesign script that places the contents of a document into a temporary TextFrame, applies all necessary formatting and other functions to the new text, and then places it at the selected InsertionPoint.  Works really great in InDesign, but InCopy doesn't seem to have the ability to add the temp TextFrame. Are there any alternatives in InCopy that would make this work on both?

        • 1. Re: Formatting imported text
          Kasyan Servetsky Level 5

          Try to create a temporary document instead of text frame. A newly created document in InCopy already contains one text frame which you can reference by script.

          function Main() {
              var doc = app.documents.add();
              var textFrame = doc.textFrames[0];
              var text = textFrame.texts[0];
              var txtFile = new File("/C/Test.rtf");
              if (txtFile.exists) {
                  var arr = text.place(txtFile);


          • 2. Re: Formatting imported text
            Rich.D Level 1

            I had already tried something like this.  It was successfully creating the new document, but never placed any text. The key seems to be placing the content in the textframe's texts(0) instead of just doing textframe.place. It seems that the textframe is not fully initialized until it has some content, but for some reason bypassing the textframe to its texts bypasses the problem.


            Thanks for the assistance.

            • 3. Re: Formatting imported text
              Kasyan Servetsky Level 5

              I tested my code in InCopy CS3 before posting. It works for me: the text has been placed.


              • 4. Re: Formatting imported text
                Rich.D Level 1

                Sorry for the confusion, your code was correct. It never placed the text in my previous test because I was doing:
                TextFrames.Item(1).Place filePath,
                instead of
                TextFrames.Item(1).Texts.Item(1).Place filePath