5 Replies Latest reply on Oct 3, 2012 6:35 AM by stoereee

    [FM11] Print Image Link and Index Markers with specific Character Style

    stoereee Level 1

      Hello,

       

      I'm new with scripting for Framemaker. I want to export FM docs to RTF so I can import these into InDesign. For the placed images I want to insert a text line that is showing the image link (reference). Besides that I want to show the Index Markers at the mark insertion position with a different Character Style. Can someone help me with that?

       

      Regards, Sjoerd

        • 1. Re: [FM11] Print Image Link and Index Markers with specific Character Style
          stoereee Level 1

          For the images I come with this script:

           

          var doc= app.ActiveDoc;
          
          ListGraphics(doc);
          
          function ListGraphics(doc)
          {
               var graphic = doc.FirstGraphicInDoc;
               while (graphic) {
                   if (graphic.type == Constants.FO_Inset) {
                       alert(graphic.InsetFile);
                       var tLoc= new TextLoc(); //create the text location object
                       tLoc // tLoc has to be the where to graphic is located in the flow
                       doc.AddText (tLoc, graphic.InsetFile);
                       }
                   graphic = graphic.NextGraphicInDoc;
                }
           }
          

           

          How do I define tLoc as the location of the graphic so I can insert the path as a line of text near the graphic?

          • 2. Re: [FM11] Print Image Link and Index Markers with specific Character Style
            4everJang Level 3

            Hello Sjoerd,

             

            One note about your method to retrieve all linked graphics: this will also process the graphics that might be linked into the master and reference pages. Just to be safe against unwanted side effects you should restrict your list of graphics to the ones in the main flow of your document.

             

            About the tLoc: you are really looking for the anchor of the anchored frame that contains graphic. It is a little confusing that FM calls both the anchored frame and the imported graphic by the same name. Even if you add an anchored frame to the text to put an equation or a text box in your document, the anchored frame will show up in the linked list of graphics in the document. If you do have an anchored frame containing an imported graphic file, you have a list of graphic objects inside the anchored frame, which itself appears in the list of graphic objects of the document.

             

            This function should do what you want to do:

             

            function ListGraphics(doc)

            {

                      var aframe = doc.FirstGraphicInDoc;

                 while (aframe.ObjectValid()) {

                     if (aframe.constructor.name == "AFrame") {

                                                    graphic = aframe.FirstGraphicInFrame;

                         if ( graphic.type == Constants.FO_Inset )

                                                         doc.AddText ( aframe.TextLoc, graphic.InsetFile );

                                      }

                     aframe = aframe.NextGraphicInDoc;

                 }

            }

             

            I assume you will also want to remove the anchored frames (the imported image files) from the text. This can be done in the same routine, but you must first catch the following element in the linked list of graphics in the doc before you can delete the current one. Otherwise you will only remove the first and end up with an invalid object. The easiest and safest method to do this is to create an array of elements to be deleted. After ending the while loop, you delete those objects. The full code looks like this:

             

            function ListGraphics(doc)

            {

                      var toDelete = [];

             

                      var aframe = doc.FirstGraphicInDoc;

                 while (aframe.ObjectValid()) {

                     if (aframe.constructor.name == "AFrame") {

                                                    graphic = aframe.FirstGraphicInFrame;

                                                    if ( graphic.type == Constants.FO_Inset ) {

                                                                   doc.AddText ( aframe.TextLoc, graphic.InsetFile );

                                                                   toDelete.push ( aframe );

                                                    }

                                     }

                   aframe = aframe.NextGraphicInDoc;

              }

             

                      for ( i = 0; i < toDelete.length; i++ ) {

                                     toDelete[i].Delete();

               } 

            }

             

            This works on a small test file I created. If you need more support, feel free to contact me: jang at jang dot nl

            • 3. Re: [FM11] Print Image Link and Index Markers with specific Character Style
              stoereee Level 1

              This is a perfect solution! Thank you Jang.

               

              Do you also have a solution for my second question about the Index Markers?

              • 4. Re: [FM11] Print Image Link and Index Markers with specific Character Style
                4everJang Level 3

                Hi Sjoerd,

                 

                The markers are not as complicated as the graphics, so you should be able to manage that, using the same logic of finding and processing all markers before starting to delete all of them.

                 

                But I am thinking that pushing content out to RTF so that it can be imported into InDesign seems like a roundabout way of doing what you need to do. Is the content structured FM or unstructured ?

                 

                From your name I am guessing you are Dutch. Depending on where you are located I might be able to visit and discuss this with a slightly larger scope in mind. Just drop me a line and I'll see what I can do.

                 

                Jang

                • 5. Re: [FM11] Print Image Link and Index Markers with specific Character Style
                  stoereee Level 1

                  Thank you Jang, this is very helpful.

                  From your name I am guessing you are Dutch. Depending on where you are located I might be able to visit and discuss this with a slightly larger scope in mind. Just drop me a line and I'll see what I can do.

                  Yes, you're right, I'm Dutch and I am located in Amsterdam.

                  Your question about why I need to export it to RTF is because we need to import it in our CMS which only supports this format. The publish engine of the CMS is InDesign Server. That's why I want these requested text lines are available in the content of the CMS. When publishing, InDesign converts these lines back to embedded images and index markers.

                   

                  This is the script for so far:

                  var doc= app.ActiveDoc;
                  
                  var myParagraphFormat = doc.NewNamedObject (Constants.FO_PgfFmt, "Beeld");
                  var myCharacterFormat = doc.NewNamedObject (Constants.FO_CharFmt, "Index");
                  
                  myParagraphFormat.Color = Constants.FV_COLOR_MAGENTA;
                  myCharacterFormat.Color = Constants.FV_COLOR_GREEN;
                  
                  ListMarkers(doc);
                  ListGraphics(doc);
                  
                  function ListMarkers(doc)
                  {
                          var myMarker = doc.FirstMarkerInDoc;
                      while (myMarker.ObjectValid()) {
                         doc.AddText(myMarker.TextLoc, myMarker.MarkerText);
                         myMarker= myMarker.NextMarkerInDoc;
                    }
                  }
                  
                  function ListGraphics(doc)
                  {
                            var toDelete = [];
                  
                            var aframe = doc.FirstGraphicInDoc;
                       while (aframe.ObjectValid()) {
                           if (aframe.constructor.name == "AFrame") {
                                                          graphic = aframe.FirstGraphicInFrame;
                                                          if ( graphic.type == Constants.FO_Inset ) {
                                                                         doc.AddText ( aframe.TextLoc, graphic.InsetFile );
                                                                         toDelete.push ( aframe );
                                                          }
                                           }
                         aframe = aframe.NextGraphicInDoc;
                    }
                            for ( i = 0; i < toDelete.length; i++ ) {
                                           toDelete[i].Delete();
                     } 
                  }
                  

                   

                  Besides I created a character and a paragraph format, I wan't to apply these formats to both of the added texts. How can I apply these formats?

                  And the 'myParagraphFormat.Color = Constants.FV_COLOR_MAGENTA' is not working!?