1 Reply Latest reply on Jun 19, 2008 7:06 AM by (Olav_Kvern)

    How to create Anchored Object using Javascript

    Level 1
      Hi all,

      Instead of adding a new textframe and setting it to an anchored object, is there any possible way to create an Anchored Object directly using Javascript. It may be in either CS2 or CS3.

      Thanks,
      Hemi
        • 1. Re: How to create Anchored Object using Javascript
          Level 1
          Hi Hemi,

          Sure--tell the insertion point to create the object. For example, to add a text frame:

          //Given a reference to an insertion point "myInsertionPoint"...
          var myFrame = myInsertionPoint.textFrames.add();

          Now you have a text frame anchored/inline in the story. Next, recompose the story containing the frame:

          myInsertionPoint.parentStory.recompose();

          ...and resize the frame.

          //Given a frame width and height "myFrameWidth" and "myFrameHeight"...
          var myX1 = myFrame.geometricBounds[1];
          var myY1 = myFrame.geometricBounds[0];
          var myX2 = myX1 + myFrameWidth;
          var myY2 = myY1 + myFrameHeight;
          myFrame.geometricBounds = [myY1, myX1, myY2, myX2];

          At this point, you can adjust the frame's anchored object settings (your settings will probably vary, but this should give you the idea).

          var myAnchoredProperties = myFrame.anchoredObjectSettings;
          myAnchoredProperties.anchorPoint = AnchorPoint.topLeftAnchor;
          myAnchoredProperties.anchoredPosition = AnchorPosition.anchored;
          //NOTE inconsistent "o" in "offset".
          myAnchoredProperties.anchorXoffset = 0;
          myAnchoredProperties.anchorYoffset = -13;

          Hope this helps!

          Thanks,

          Ole