4 Replies Latest reply on Jul 18, 2014 5:23 AM by Apollo102

    Add elements to doc




      I want to know if this is possible to manipulate fm objects to add existing elements (instanciated objects) to a document.


      I saw multiple ways to create doc objects but I can't found any way to add it anything but text.

      I saw in the api some functions to create new elements, F_ApiNewGraphicObject(), F_ApiNewAnchoredObject(), F_ApiNewElement()... but none to add an existing element...


      Is there a way to do that ? If not is it possible to clone an object ?

        • 1. Re: Add elements to doc
          Russ Ward Level 4



          To insert a completely new element, you would use F_ApiNewElement() or F_ApiNewElementInHierarchy(). For some reason, neither of these appear in the PDF bookmarks of the latest FDK reference, but they are described in the text.


          You also say something about an "existing" element and "cloning", so I'm not exactly clear on what you want. To copy an existing element, you can select it and use F_ApiCopy() / F_ApiPaste.


          One thing I would note, though, is that you are using words that are associated with objects in an object-oriented program. FrameMaker objects are not really the same... they are just things in the session that have properties. There is no real concept of "cloning" or "instantiation" with a FrameMaker object.



          • 2. Re: Add elements to doc
            Apollo102 Level 1



            adding elements seems to be not so simple. The element object offers only delete and no add method.


            How do you use in ES commands from the FDK (like F_ApiNewElement() or F_ApiNewElementInHierarchy())? Unfortunately I could not find anything useful about this. Or is it definitely in ES completely different how to add elements?


            Thank you for your any pointer.





            • 3. Re: Re: Add elements to doc
              frameexpert Level 4

              NewElement() is a method of an ElementDef object. So to add an element at the current insertion point, you can do something like this:


              #target framemaker
              var doc = app.ActiveDoc;
              var elementDef = doc.GetNamedElementDef ("p");
              var element = elementDef.NewElement (doc.TextSelection.beg);



              • 4. Re: Add elements to doc
                Apollo102 Level 1

                Hi Rick,


                thank you very much. It works perfectly. It is also doing the validation.