4 Replies Latest reply on Dec 3, 2014 7:30 AM by 4everJang

    insert inset in anchored frame

    4everJang Level 3

      I cannot find the info on how to insert an Inset into an existing AFrame using ExtendScript. Does anyone have experience with this?

       

      Thanks

       

      Jang

        • 1. Re: insert inset in anchored frame
          Russ Ward Level 4

          Hi Jang,

           

          I thought you'd rather just fire anyone for even thinking up such an idea (inside joke, apologies to the public!)

           

          I'm not sure exactly what your requirements are, but my assumption is that you need to first insert a text frame, then import the inset into that text frame. Here is a basic function that does that, where insetPath is a fully-qualified path to the inset file. I imagine it could be expanded to account for other variations, like importing a different flow, etc.

           

          function importTextInsetToAFrame(doc, aFrame, insetPath)
          {
              if(!doc.ObjectValid() || !aFrame.ObjectValid())
              {
                  alert("Document or frame object is invalid.");
                  return;
              }
              
              //Create a new text frame in the anchored frame
              var textFrame = doc.NewGraphicObject(Constants.FO_TextFrame, aFrame);
              if(textFrame.ObjectValid())
              {
                  //Position and size the text frame to fit the anchored frame, with a two-point
                  //buffer on all sides.
                  textFrame.LocX = (2 * 65536);
                  textFrame.LocY = (2 * 65536);
                  textFrame.Width = aFrame.Width - (4 * 65536);
                  textFrame.Height = aFrame.Height - (4 * 65536);
              }
          
              //get the first paragraph in the new frame and
              //set up a text location for the import
              var pgf = textFrame.FirstPgf;
              var textLoc = new TextLoc(pgf, 0);
          
              //set up the prop vals structures and do the import.
              var importParms = GetImportDefaultParams();
              var returnParms = new PropVals();
              
              doc.Import (textLoc, insetPath, importParms, returnParms);
          }    
          

           

           

          Russ

          • 2. Re: insert inset in anchored frame
            Russ Ward Level 4

            By the way, I was assuming you want a text inset created by a file import. For a script-generated inset, I think you would use:

             

            var inset = doc.NewAnchoredTiApiClient(textloc);

             

            If you mean something totally different by "inset", then you'll need to elaborate.

             

            Russ

            • 3. Re: insert inset in anchored frame
              4everJang Level 3

              Hi Russ,

               

              I know I would have to fire myself, and believe me, I have tried many times. But my boss will not let me go :-)

               

              What I am doing is this: I walk through a document and find anchored frames. If the anchored frame contains more than one graphic (which includes referenced files, lines, text boxes and such), I convert the entire contents of the anchored frame into a single SVG, which then replaces the contents of the anchored frame. This makes the graphic object, including possible arrows, text boxes etc. suitable for conversion to structured framemaker and/or output to XML. It works fine when there is at least one referenced graphic (Inset) in the anchored frame, as I simply change its InsetFile to the newly created SVG. This works like a breeze, even though FM complains about changed image formats when I reopen the file. The SVGs are displayed correctly, so I am happy. But when I encounter a file that has no referenced graphics, just lines and text boxes and - god forbid - images that were copied in rather than referenced, I have no single Inset to change the InsetFile property of. So I will have to add an Inset to the AFrame at that point and set its InsetFile property.

               

              As you see, there is no text involved and no paragraphs available to set a text location to. If you have a bright idea about this, I would be over the moon. This type of thing has been on my mind ever since I found that FM creates an - Ugh! - CGM out of any AFrame that contains multiple graphic elements. An SVG for that purpose is infinitely better, as it will even allow me to create references to callouts from the text, or have captions inside the text boxes pick up their content from referenced elements in the text flow. Once I have the conversion to SVG perfected, there is no limit to what I can do next.

               

              Let me know if you have the info I need. I know you have been playing around with inserting graphics into an AFrame, but I need to add an Inset right there.

               

              Ciao

               

              Jang

              • 4. Re: insert inset in anchored frame
                Russ Ward Level 4

                Hi Jang,

                 

                OK, you just want to establish a new imported graphic within an anchored frame? That is, you want your new SVG to replace all current frame contents, as a referenced image? If that's all, I think it might be very simple. After you delete all current contents, just select the frame (frame.GraphicIsSelected = true), then do a doc.Import(<your SVG>). Just like in the GUI. You'll get a new inset as a child of the anchored frame. Just remember to make sure to deselect all other graphics first.

                 

                This solution seems so simple that I think I might still be missing something. Let me know.

                 

                Russ

                • 5. Re: insert inset in anchored frame
                  Russ Ward Level 4

                  One addendum, again. The Import() method asks for a text location as the first parameter, perhaps that's a source of confusion. If I specify doc.TextSelection.beg or just null, it works fine. Either is invalid and the selected frame takes precedence.

                  • 6. Re: insert inset in anchored frame
                    4everJang Level 3

                    Hi Russ,

                     

                    Simple, indeed, and the TextLoc parameter is confusing. If you post your reply to the forum I can award 10 points for the correct answer - and others will be able to see the answer, too. You replied by a message, so I cannot see the replies on the forum.

                     

                    Ciao

                     

                    Jang

                    • 7. Re: insert inset in anchored frame
                      Russ Ward Level 4

                      Hi Jang,

                       

                      Here is the solution summed up.

                       

                      To insert a new inset (that is, a new referenced graphic) into an anchored frame, you need to:

                       

                      - Deselect all graphic objects in the document, then select just the anchored frame (set frame.GraphicIsSelected=true, all other graphics to false).

                      - Use doc.Import() in a standard manner, except don't worry about a valid textLocP parameter. Just specify doc.TextRange.beg or null.

                       

                      The result will be a new referenced graphic as a child of the anchored frame. Note that this methodology follows the GUI-based procedure.

                       

                      Russ

                      • 8. Re: insert inset in anchored frame
                        frameexpert Level 4

                        When targeting an existing anchored frame, I usually do this:

                         

                        1) Create a temporary text frame on the document's first master page. Every document has to have a FirstMasterPageInDoc.

                         

                        2) Create a TextLoc at the beginning of the temporary frame's first paragraph.

                         

                        3) Import the graphic at the TextLoc.

                         

                        4) Find the anchored frame and FirstGraphicInFrame, which is my new inset.

                         

                        5) Change the new inset's FrameParent to the existing anchored frame object. This "moves" the new inset to the existing anchored frame. Then I can set its LocX, LocY, etc. properties to match that of the original graphic. Then I can delete the original graphic.

                         

                        6) If you have more than one graphic to import, keep the temporary text frame and just delete its FirstPgf and repeat steps 2-5.

                         

                        7) When you are done, delete the temporary text frame from the master page.

                         

                        This may seem complicated, but I have done it in dozens of scripts over the years and have found it to be the most reliable, especially when your target document is invisible. Please let me know if you have any questions or comments. -Rick

                        • 9. Re: insert inset in anchored frame
                          4everJang Level 3

                          OK, I have it working now. There is just one glitch I cannot get to work properly, as it appears to be a bug in the SVG import. When importing the SVG that is built out of all the graphic components in the anchored frame, the height of the SVG is correct but the width is not. There is whitespace on either side of the original graphic and there is no way I can get rid of that. I inspected the SVG in a viewer and it looks fine, without the white space. When importing that file in FM, there is a lot of extra space and this causes FM to scale the image down.

                           

                          As I do not really need the FM layout to be correct - FM is to be used as the structured editor, not the publishing engine - I won't spend any more time on this right now. I might figure something out in the future and then make the code available as a plug-in. At that point I will want to include references between the text and the callouts in the graphic, and some more goofy stuff that might be useful when publishing to XML and interactive HTML.

                           

                          Ciao

                           

                          Jang