5 Replies Latest reply on Jul 1, 2008 11:47 PM by Loic.Aigon

    Moving text frame contents to new document (JS, CS2)

      I suspect that this is very simple, but I am JS amateur and I just haven't quite been able to put it together.

      In the most general terms, here is what I hope to do with a script:
      Copy the contents of an active text frame in a working document
      Open an existing template (ie. myTemplate.indt)
      Insert the copied contents into a target text frame on the newly opened template

      As a bonus, it would be awesome to autoflow (adding pages as necessary) the text in the new document.

      I think that I have pieces of this working, but trying to learn and understand what each step needs to be. Thank you very, very much in advance for any help.

      Cheers!
      -Scott
        • 1. Re: Moving text frame contents to new document (JS, CS2)
          Loic.Aigon Adobe Community Professional
          Hi scott,
          As you suspect, it's really simple. However, I guess that what you are really trying to get may lead to a richer way of thinking. Could you tell us more on the whole project.
          Anyway,
          var doc = app.activeDocument;
          var mysel = String(app.selection[0].contents); //Assuming that your selection is text.
          // X is a string like /c/my documents...
          //If you want to be able to pick a particular template,
          //you can choose to set a var to var mytemplate = File.openDialog("choose a file");
          var mytemplate = app.open(File(X));
          var mytemplateframe = app.documents.item(mytemplatedocname).pages[0].textFrames.add({geometricBounds:[0,0,200,2 00]});
          mytemplateframe.label = "textframe";
          mytemplateframe.contents = mysel;
          It needs to be completed regarding to owerflow. And textframes dimension are empiric, you can adjust that too.
          hope it helps.
          Loic
          • 2. Re: Moving text frame contents to new document (JS, CS2)
            Level 1
            Thank you for your response Loic.

            It is an important step in what I am grying to accomplish. How would I best do this while still maintaining the formatting of the contents?

            I am going to try to set aside some time to respond with a little more detail regarding precisely what I am trying to accomplish. Much appreciated ...

            -Scott
            • 3. Re: Moving text frame contents to new document (JS, CS2)
              Loic.Aigon Adobe Community Professional
              Hi Scott,
              try this
              var mytemplate = app.open(File(X));
              //X is a string for the file i.e. /c/...

              var mysel = String(app.selection[0].contents);
              //Assuming that your selection is text.
              app.copy();
              app.activeDocument=mytemplate;
              var mytemplateframe = doc2.textFrames.add({geometricBounds:[0,0,200,200]});
              mytemplateframe.insertionPoints[0].select(SelectionOptions.REPLACE_WITH);
              app.paste();

              However, maybe the simpliest is to copy the parent textFrame then eventually set it for position and size.
              Have you ever thought about xml ? It may handle well different inputs with styles etc. Could help you.
              Loic
              • 4. Re: Moving text frame contents to new document (JS, CS2)
                Level 1
                Hi Scott, Loic,

                Just a note--in CS3, you can do this without copy/paste, and you can retain all formatting between the two documents. We do, every now and then, make things better between releases.:-)

                Thanks,

                Ole
                • 5. Re: Moving text frame contents to new document (JS, CS2)
                  Loic.Aigon Adobe Community Professional
                  Hi Ole,
                  I am glad to hear it and sure about your wish to improve the soft version after version.
                  However could you tell us more about the non utility of "copy/paste" for this stuff ? Do you think about the duplicate() method ? Or something I should know :-)
                  Thanks a lot.
                  Loic