.lines.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 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.parent.paragraphs;
//move anchored rectangle parent character aside (a new textFrame MF2)
myAnObjPar = MF1.rectangles.parent.move(LocationOptions.AT_BEGINNING, MF2.texts);
myPara.lines.contents = newCont;
// come back with character keeping options
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.
@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.
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…