14 Replies Latest reply on May 6, 2014 12:40 PM by frameexpert

    copy paste text frame

    Dimitris Mitrovgenis

      Hi to all.

      I am trying to make a very simple script that finds the first text frame that exists in a flow (in this case a secondary flow with only a line of text) ,copy that in the exact same location to all pages of the active document. Is this possible with javascript?

        • 1. Re: copy paste text frame
          frameexpert Level 4

          Hi Dimitris, Yes this is definitely possible with ExtendScript. You may want to post a link to a sample file so we can see exactly what you are trying to do. You are welcome to send me something offlist to look at. - Rick rick at frameexpert dot com

          • 2. Re: copy paste text frame
            Dimitris Mitrovgenis Level 1

            Hi Rick,

            thanks a lot for your reply.I am trying to make a template for aviation manuals.There is a requirement to have page revision status, that means that I have to enter a date to every page and list this (List of effective pages) in the front pages of the manual.I did this with a paragraph format in a second text flow and a list of paragraphs generated file.The problem is that I have to manual enter in every page the text frame that includes the paragraph format.

            Screen Shot 2014-05-01 at 21.55.43.png

            I thought that a script can help.If you have any other recommendations or solutions or alternative ways to perform this task I would be very happy to hear them.I am not familiar with javascript but I have done loads of scripts in Filemaker.Any help will be appreciated.

             

            Idealy a way to enter this into a 2-page layout (left/right).but if it is a hassle I can convert all layouts to single page.

            • 3. Re: copy paste text frame
              4everJang Level 3

              Dimitris,

               

              Do all pages of the same manual get the same revision number and date, or is this a per-page revision ?

               

              If all pages get the same number and date, you can use FrameMaker variables and do not need a script at all. Just enter the frame on the master pages as non-user-editable text and enter a user variable into it. Changing the user variable gives you the required result.

               

              If each page requires its own revision number and date, scripting will not help you. How are you going to get the revision number and date per page? But even if sections require their own revision number and date, you can divide the entire document into chapters in a book (continued page numbering) and do the same with the FrameMaker variables.

               

              So I do not see a need for any scripting. If you do need this done via scripting, I think you should ask someone like Rick or myself to do it for you for a reasonable fee. What you think is easy is in fact not so straightforward.

               

              Kind regards

               

              Jang

              • 4. Re: copy paste text frame
                Dimitris Mitrovgenis Level 1

                Hi to all,

                The initial issue has the same revision number and revision date.I can not do this with a variable because the list of paragraphs does not get information from master pages.The way I found to make this work is to have a separate flow or a text frame in every page (With its own paragraph format ,in this case LOEP).So when I generate a List of paragraphs , I get the List of effective pages.Now the "problem" is when I want to put the text frame in every page.I can copy the text frame, click on next page icon in frame maker,paste the text frame and go on until I reach the end of the document.So I thought to automate this with a script.

                I think this is very simple to do ,but since I have no experience with javascript it is difficult for me.Anyway since I am an aircraft engineer and I like challenges I made some progress with my own script.

                This is my try:

                var doc = app.ActiveDoc;

                if(doc.ObjectValid() == true)

                {

                doc.FirstBodyPageInDoc.FirstSelectedGraphicInDoc;

                doc.Copy();

                doc.CurrentPage=doc.FirstBodyPageInDoc.PageNext.PageNext;

                doc.paste(0)

                      

                }

                else

                {

                    alert("No active document found. Cannot continue.");

                }

                 

                 

                alert("Script complete!");

                 

                But i have a problem with this because it pastes the selected Graphic in this case a text frame to the first page where I originally selected the object.When i run the script line by line I get to the point where I navigate to the correct page but when it executes the paste(0) ,it goes back to the first page.

                The next step will be to loop this function until no other pages exist.

                I hope now you can understand the task I want to automate.

                 

                Regards

                Dimitris

                • 5. Re: copy paste text frame
                  4everJang Level 3

                  Hi Dimitirs,

                   

                  When you navigate to the right page, I guess you can find the text location where the graphic with the text frame should be inserted? That text location must be used to set the TextSelection property of the document. Methods like Doc.AddText and Doc.Paste always use the current TextSelection.

                   

                  Assuming you have the target location stored in a variable oTLoc, this is what you need to do:

                   

                  var oTRange = new TextRage ( oTLoc, oTLoc );    /* using the same 'beg' and 'end' object effectively moves the cursor to the text location */

                  oDoc.TextSelection = oTRange;

                  oDoc.Paste( 0 );                                   /* the parameter is a field of flags to determine what to do, in your case 0 seems to be appropriate */

                   

                  FYI, In my scripting I always prefix variable names with an indicator of the variable type (as javascript has no explicit typing), so any object receives a lower-case o, strings have 's', string arrays 'sa' etc. When writing elaborate scripts, this does sometimes help to avoid and/or find bugs due to incorrect types being used when passing parameters to methods.

                   

                  Good luck. Let us know when this solved your problem.

                   

                  Jang

                  • 6. Re: copy paste text frame
                    Dimitris Mitrovgenis Level 1

                    The text frame needs to be pasted in the exact same location Jang. I thought that when you copy a text frame the properties are copied also.Is this the case?Am I missing something?From what I have read from you pdf,I think that the problem is that i don't select the pageframe so I can copy it.Correct?

                    • 7. Re: copy paste text frame
                      4everJang Level 3

                      No, you cannot copy the text frame in the exact same location, as that location only exists once in the entire document. What you call "exact same location" is a location relative to the content on the page, but that does not have a meaning for FrameMaker. The document has only one TextSelection, and you have to move that TextSelection to point at the point where you want to insert the copied text frame.

                       

                      Is the Graphic object that you are copying an "anchored frame" or an "unanchored frame" ? That does make a difference, as the anchored frame is attached to an anchor in a text - which is the text location of the Graphic object. Can you share the code you used to copy the original Graphic? We'll take it from there.

                       

                      Jang

                      • 8. Re: copy paste text frame
                        Dimitris Mitrovgenis Level 1

                        It is an unanchored frame.I used this to copy the object:

                         

                        doc.FirstBodyPageInDoc.FirstSelectedGraphicInDoc;

                        doc.Copy();

                         

                        Very simple.The user creates the unanchored frame to the location he wants, writes the text with the desired paragraph format, selects it and after runs the script.That was my intention anyway.

                        • 9. Re: copy paste text frame
                          frameexpert Level 4

                          Hi Dimitris, In the FrameMaker interface, you can use the clipboard for this type of task. But when scripting it, you don't have to use the clipboard. Instead, the script can get the properties of the selected text frame: LocX, LocY, Height, Width, and the frame's text and paragraph format. Then it can go along page by page and create a text frame in the proper location on each page with the correct properties and text. This is much better than using the clipboard. -Rick

                          • 10. Re: copy paste text frame
                            Dimitris Mitrovgenis Level 1

                            Do you get the properties with the GetProps?Can you point me to the right direction?

                            • 11. Re: copy paste text frame
                              frameexpert Level 4

                              Most properties can be picked up directly. For example, select a text frame in a FrameMaker document and run this code:

                               

                              #target framemaker

                               

                              var doc = app.ActiveDoc;

                              var textFrame = doc.FirstSelectedGraphicInDoc;

                               

                              alert (textFrame.LocX);

                               

                              Rick

                              • 12. Re: Re: copy paste text frame
                                frameexpert Level 4
                                #target framemaker
                                
                                // Before running this script:
                                // Draw and position a text frame on the first page and select it.
                                
                                // Set a variable for the active document.
                                var doc = app.ActiveDoc;
                                
                                // Set a variable for the selected text frame.
                                var textFrame = doc.FirstSelectedGraphicInDoc;
                                
                                // Set a variable for the second body page.
                                var page = doc.FirstBodyPageInDoc.PageNext;
                                // Loop through the pages, starting with the second.
                                while (page.ObjectValid() === 1) {
                                    // Make a text frame on the body page.
                                    var newFrame = doc.NewTextFrame (page.PageFrame);
                                    // Assign the selected frame's properties to the new frame.
                                    newFrame.LocX = textFrame.LocX;
                                    newFrame.LocY = textFrame.LocY;
                                    newFrame.Width = textFrame.Width;
                                    newFrame.Height = textFrame.Height;
                                    page = page.PageNext;
                                }
                                
                                • 13. Re: Re: copy paste text frame
                                  Dimitris Mitrovgenis Level 1

                                  Rick thanks a lot for your time and your script!!!

                                  This works almost as desired. The issue is that the text frame is empty without text.It Creates the frame at the correct position but with no text.

                                  • 14. Re: Re: copy paste text frame
                                    frameexpert Level 4

                                    Hi Dimitris, My primary business is writing scripts for clients so there is a limit to how much free help I can provide. There should be examples of adding text in the FrameMaker ExtendScript documentation, or you may find another forum post that will tell you how. Doing some research and trial and error will help you more than someone just giving you the answers. That is basically how I learned and mastered FrameScript and ExtendScript. -Rick