3 Replies Latest reply on Oct 21, 2012 8:43 AM by Laubender

    Changing a Line's Content If it Contains the "Anchored Object Marker"

    mlavie Level 1

      [CS5.0, ActionScript]


      There are instances in which I want to change a Line's content, but the current content contains an "Anchored Object Marker" (the Unicode "Object Recplacement Character" - 65532). In the debugger, that char is displayed as the tiny letters "obj" between two lines.


      For example, if a TextFrame contains an anchored TextFrame, then when I retrieve OuterTextFrame.lines.item(0).contents, I recieve the Anchored Object Marker char together with the text of the first line, because the  Anchored Object Marker marks the placement of the anchored TextFrame.


      The problem is, that if I perform any change on the OuterTextFrame.lines.item(0).contents, the anchored textFrame dissapears - even if I make sure that I put an  Anchored Object Marker at the start of the new contents.


      Even  OuterTextFrame.lines.item(0).contents =  OuterTextFrame.lines.item(0).contents causes the anchored TextFrame to dissapear.


      My question - how can I change the text in the first line in the TextFrame, without it making the anchored TextFrame dissapear.




        • 1. Re: Changing a Line's Content If it Contains the "Anchored Object Marker"
          Jump_Over Level 5



          .lines[0].contents gives a "String", so there is no more formats, object properties, anchored items, etc inside this.

          You have to catch a character (which is anchored object parent) and come back with it when .content is replaced.

          (or replace a content leaving this character untouched).


          I am not sure where your anchored object initially is and where it should be after, but...


          - we are interested in 1st anchored rectangle

          - it should come back to the beginning of lines[0] of parent paragraph

          - your texFrame name is "MF1":


          MF1 = app.activeDocument.textFrames.item("MF1");

          MF2 = app.activeDocument.textFrames.add();

          newCont = " BLAH blah nonecaectem volum blah";

          myPara = MF1.rectangles[0].parent.paragraphs[0];

          //move anchored rectangle parent character aside (a new textFrame MF2)

          myAnObjPar = MF1.rectangles[0].parent.move(LocationOptions.AT_BEGINNING, MF2.texts[0]);

          myPara.lines[0].contents = newCont;

          // come back with character keeping options

          myAnObjPar.move(LocationOptions.AT_BEGINNING, myPara.texts[0]);






          • 2. Re: Changing a Line's Content If it Contains the "Anchored Object Marker"
            mlavie Level 1

            Thanks JumpOver.


            However I think what I need here is manipulating content containing special marker chars via insertionPoints, which is something I don't know how to do yet, and have found surprisingly few examples of.



            • 3. Re: Changing a Line's Content If it Contains the "Anchored Object Marker"
              Laubender Adobe Community Professional & MVP

              @mlavie – JumpOver is absolutely right. You have to distinguish two cases here:

              1. The contents (not formatted in any case) including your "anchored object marker"

              2. The formatted text including the character that represents a specific anchored object


              If you manipulate the contents of a text frame in one go, you cannot maintain the Character Object that represents the specific anchored object.


              For that you have to use the formatted text;  more specific: a Texts Object, which can be a single Character Object.

              First approach for solving your problem:

              If you could identify  the Character Object that represents the anchored object, you could change the contents of the Texts object before it and after it. Leaving the anchored object intact.


              Second approach:
              You move the Character Object that represents the anchored object aside to another text frame, replace the contents as you want and move the anchored object back in its right place.
              (JumpOver was showing you how to do that.)


              An anchored object is nothing but a single character. No more, no less…