6 Replies Latest reply on Jan 31, 2012 5:38 AM by 4everJang

    How to get to text in an anchored frame

    4everJang Level 3

      Hello,

       

      I am working on unstructured FrameMaker files, in preparation of comverting them into structured documents. My customer has placed lots of authoring notes in the sidehead of their documents. They are inserted as text frames inside anchored frames. I am trying to retrieve the text from the anchored frames so that I can move it into a new paragraph where it will be picked up by the conversion process.

       

      Browsing through the ExtendScript reference for FrameMaker I find an AFrame object, but it only lists elements and properties pointing to graphics that may be entered into this frame, not text ranges. In the Data Browser I find InvalidObject for the FirstGraphicInFrame and no pointers to any kind of TextFrame.

       

      Can anyone tell me how to get a handle on the text frame in those anchored frames ?

       

      Thanks in advance

       

      Jang

        • 1. Re: How to get to text in an anchored frame
          frameexpert Level 4

          Hi Jang,

           

          You have to loop through the graphic object(s) in the anchored frame and test each graphic to see if it is a text frame. For example, if aframe is your anchored frame object:

           

          // Set a variable for the first graphic in the anchored frame.

          var graphic = aframe.FirstGraphicInFrame;

          // Loop through the graphics in the anchored frame.

          while (graphic.ObjectValid()) {

            // Test to see if the graphic is a text frame.

            if (graphic.constructor.name === "TextFrame") {

              // Do something with the text frame here.

            }

            // Move to the next graphic in the anchored frame.

            graphic = graphic.NextGraphicInFrame;

          }

           

          Please let me know if you have any questions or comments.

           

          Rick Quatro

          • 2. Re: How to get to text in an anchored frame
            4everJang Level 3

            Hi Rick,

             

            The FirstGraphicInFrame property of my anchored frame shows InvalidObject in the data browser. There is no linked list of graphic objects that I can walk through to find a text frame. I am using FM 10.0.0.388

             

            Jang

            • 3. Re: How to get to text in an anchored frame
              frameexpert Level 4

              Hi Jang,

               

              OK, here is what I tried. I select an anchored frame that has a text frame in it and run this code:

               

              var doc = app.ActiveDoc;
              var aframe = doc.FirstSelectedGraphicInDoc;

              var graphic = aframe.FirstGraphicInFrame;
              alert(graphic.constructor.name);

               

              The alert displays "TextFrame" like I would expect. You can also do this to display the Name propety of the FirstPgf property of the text frame:

               

              var doc = app.ActiveDoc;
              var aframe = doc.FirstSelectedGraphicInDoc;

              var graphic = aframe.FirstGraphicInFrame;
              alert(graphic.FirstPgf.Name);

               

              This works for me as well. You should post your code so we can see what might be wrong. Thanks.

               

              Rick

              • 4. Re: How to get to text in an anchored frame
                4everJang Level 3

                Hello again Rick,

                 

                I got it now. I was looking for the wrong type of object. As the anchored frame looks like an anchored frame to me, not like a graphic, I never thought of finding the FirstGraphicInDoc and then treat it like an anchored frame with text frames in it. The FM scripting guide could do with a couple of good examples here and there. I changed the FirstSelectedGraphicInDoc to FirstGraphicInDoc and it finds the objects I was looking for.

                 

                Thanks

                 

                Jang

                • 5. Re: How to get to text in an anchored frame
                  frameexpert Level 4

                  Hi Jang,

                   

                  Be careful here. I used FirstSelectedGraphicInDoc because I purposely wanted to get the selected anchored frame for demonstration purposes. You can't reliably predict which graphic the FirstGraphicInDoc will return. It may be your anchored frame, or it may be some other graphic in the document. In fact, a new Portrait document already has over 30 graphic objects in it before you add any content to it!

                   

                  Rick

                  • 6. Re: How to get to text in an anchored frame
                    4everJang Level 3

                    Hi Rick,

                     

                    I test the returned Graphic to see if it is a TextFrame, as you suggested. If I get to the paragraphs in the text frame, I can also test on the paragraph format, which is only used in the anchored frames. Also, I am trying another method to get to the same point - see my post about finding a paragraph via a format tag. In one way or another, it must be possible to loop through the WriterNote objects in a document, retrieve the text from them and insert them in the main flow of the document before I start my conversion to structured FM.

                     

                    I would never have entered the notes in this way, but customers do crazy stuff while they work in unstructured FM. It makes the conversion a little more challenging, which makes it a steeper learning curve for me.

                     

                    Ciao

                     

                    Jang