How to move select anchored objects
I have a script (bottom) that I created to move the anchored object insertion points to after the first tab. It works as intended. Here are example lines before and after running the script—(~a1,2,3) would be the anchored objects, (\\t) is a tab.
Before: (~a1) foo (\\t) bar (~a2) fizzbuzz (~a3).
After: foo (\\t) (~a1) (~a2) (~a3) bar fizzbuzz.
However, occasionally there are anchored objects at the beginning of lines that i would like to omit from being moved. Here is the desired format, having moved only the anchors after the first anchored object occurrence.
Desired: (~a1) foo (\\t) (~a2) (~a3) bar fizzbuzz.
My question is how to isolate only the text and children thereof after the first occurrence of an anchored object? So in other words how can I skip the first anchored object and still move the rest?
Thanks in advance for your time.
var myanchors = app.documents[0].stories.everyItem().pageItems.everyItem().getElements();
for ( x=0; x<myanchors.length;x++)
{
var thistext = myanchors
.parent.paragraphs.item(0).contents; var tablocation=thistext.indexOf('\t');
var myIP=myanchors
.parent.paragraphs.item(0).insertionPoints.item(tablocation+1) ; myanchors
.anchoredObjectSettings.insertAnchoredObject(myIP, AnchorPosition.INLINE_POSITION); }
