Copy link to clipboard
Copied
Hi Forum,
I tried to create and anchor the textFrame, before the word ("WHAT IS COVERED."), which I find...
But the anchored text Frame is inserted at the end of the text or at the beginning of the next paragraphs, which i find (""WHAT IS COVERED."). (screenshot attached for referencing the false place)
Could can body fix this... Pls.
here is my code.....
myDocument = app.activeDocument;
var nF = app.activeDocument.textFrames.add()
nF.geometricBounds = [50,50,30,30];
try {
var myOStyle = myDocument.objectStyles.item("LeftAlign");
myOStyle.name;
} catch (e) {
var myOStyle = myDocument.objectStyles.add({name: "LeftAlign"});
}
nF.applyObjectStyle(myOStyle)
app.select(nF);
app.cut();
//app.cut();
app.findGrepPreferences.findWhat = "What is covered.";
found = app.findGrep();
for (i=0; i<found.length; i++) {
fnd = found
sel = app.select(fnd);
mySourceFrame = app.activeDocument.pages.item(0).textFrames.item(0).parentStory.paragraphs.everyItem();
app.paste(LocationOptions.AT_BEGINNING, fnd.insertionPoints[0]);
}
Advance thanks & regards,
rkids...
Ok
I see from your screenshot that you have cs3 so you can't use isValid to test for the object style so you should use the try catch in the way you did
Copy link to clipboard
Copied
(Without trying)
Is this perhaps because you are changing the text by inserting the text frame, and therefore from the first one off, all "next" stored FindGrep occurrences are invalid? If so, your very first inserted text frame would be in the correct position; the next off by one character, then off by two, etc.
Try with this instead:
found = app.findGrep(true);
meaning the resulting array is in last-to-first order. Changing the last item first will not mess up the rest of the array.
Copy link to clipboard
Copied
Hi rkids,
Oh dear, oh dear, oh dear, sigh, sigh, sigh ![]()
2 points..
1) In scripting it is very rare that you have to select, copy and paste, your's is certainly not one of them.
2) After 80 posts it is about time that you learnt how to format your scripts on the forum, it makes them easier to read. See screenshots.

Anyway this is more or less the correct way to do what you want.
var myDocument = app.activeDocument;
var myOStyle = (myDocument.objectStyles.item("LeftAlign").isValid) ? myDocument.objectStyles.item("LeftAlign") : myDocument.objectStyles.add({name: "LeftAlign"});
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "What is covered.";
var myFinds = myDocument.findGrep();
l = myFinds.length;
while (l--) myFinds
.insertionPoints[0].textFrames.add({geometricBounds: [50,50,30,30], appliedObjectStyle: myOStyle}) // IMPORTANT LOOP BACKWARDS!!!
Note also that you don't have to declare a varible for the textframe and then give its dimention and then its object style, you can do it all in one shot.
Regards
Trevor
P.s. Sorry for being somewhat condescending.
Copy link to clipboard
Copied
Hi Jongware,
Didn't see you there,
You are so much kinder than me.
Copy link to clipboard
Copied
Ok
I see from your screenshot that you have cs3 so you can't use isValid to test for the object style so you should use the try catch in the way you did
Copy link to clipboard
Copied
Waugh!,
As sir ~Trevor~ said,
I dont know the methods of updating screenshot.. sorry for that... and thanks for what I have learnt from you sir..... Definately a new learnings...
Hi Jongware!...thanks for your patience of reading such a long and ugly script, which I produced, instead of directly asking for help!... Please bare with this, as im the beginner, still...
Sir (Jongware & Trevor) I will test this in CS5.5 and let you know, if any problem..
Please help me in my future request to understand more about the concept of Anchor objects.
thanks so much for your kindness post..
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more