5 Replies Latest reply on Oct 23, 2013 10:55 AM by Laubender

    how to update text frame by snippets using javascript?

    Mahabub Ali

      Hi,

       

      How can i update text frame by importing snippets using javascript?

      I got a solution from http://jsid.blogspot.com/2007/09/placing-snippets-inlineanchored.html

      But problem is it create nested text frame.

       

       

      Thanks,

      Mahabub

        • 1. Re: how to update text frame by snippets using javascript?
          AnshulJain19 Adobe Employee

          Hi,

           

          If you want to place snippet as inline in a text frame then you can use following script:

           

          myDoc = app.activeDocument;

          textFrame1 = myDoc.textFrames[0];

          textFrame1.parentStory.insertionPoints[-1].place(filepath);

           

          Thanks

          -Anshul

          • 2. Re: how to update text frame by snippets using javascript?
            Mahabub Ali Level 1

            Hi Anshul,

             

            Thanks for your reply.

             

            Sorry this also create nested frame.

             

            I need a script where i can replace parentStory of textframe using snippet.

             

             

            Thanks

            Mahabub

            • 3. Re: how to update text frame by snippets using javascript?
              AnshulJain19 Adobe Employee

              Hi,

               

              I think you want to replace text frame content with snippet, in that case you can use same script and add a line in it to first delete its content and then place snippet.

               

              myDoc = app.activeDocument;

              textFrame1 = myDoc.textFrames[0];

              myDoc = app.activeDocument;

              textFrame1 = myDoc.textFrames[0];

               

              In this case it will place another text frame inside a text frame.

              If you want only text inside a text frame then you can place txt or rtf file instead of a snippet file.

               

              Thanks

              -Anshul

              • 4. Re: how to update text frame by snippets using javascript?
                Mahabub Ali Level 1

                Hi Anshul,

                 

                Yes, I want to replace textframe contents with snippet.

                 

                I have tried with rtf file earlier and it worked. but in that case i have to convert snippet file to rtf.

                 

                Is there any way to relace textframe contents with snippet?

                 

                 

                Thanks,

                Mahabub

                • 5. Re: how to update text frame by snippets using javascript?
                  Laubender Adobe Community Professional & MVP

                  @Mahabub – do you want to replace the "contents" as in the "Contents" property?
                  Or do you want to replace the formatted text with formatted text as in "Texts" object?

                   

                  If it's the latter (I assume you are meaning that):

                   

                  1. Let's store the target text frame it in a variable called targetTextFrame. Remove the contents of targetTextFrame.

                   

                  targetTextFrame.contents = ""

                   

                  2. Place the snippet file at the first insertion point of targetTextFrame (there is no other insertion point left in it). Now the placed snippet (I assume a single text frame here) is textFrames[0] of targetTextFrame.

                   

                  3. Move or duplicate the "texts[0]" object of targetTextFrame.parentStory.textFrames[0] to the first insertion point of the targetTextFrame. Use the methods move() or duplicate() for that.

                   

                  4. Get rid of the placed snippet text frame by removing the last character of the parent story of the targetTextFrame (or, if you wish: textFrames[-1] of targetTextFrame.parentStory. (The last character in that story contains the snippet).

                   

                  CAUTION! The targetTextFrame should be not threaded to another text frame.

                   

                  Uwe