Hi,
As Rob, I truly prefer simplicity!
[Personal comment removed! ...]
My script uses 2 object styles that can, since CC 2018, manage size & location.
It presents 2 parts:
• removing of all the old text frames (if already in the doc), using the 2 previous OS,
• adding of new text frames with insertion of the numbering.
Note the numbering is defined by an user-counter and not directly by the page number or index.
Of course, a global undo!
Best,
Michel, for FRIdNGE
// by FRIdNGE, october 2018
// WARNING: The user needs to previously create the 2 Object Styles ("Right"/"Left")!
app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Numbering! …");
function main()
{
var myDoc = app.activeDocument,
myPages = myDoc.pages, P = myPages.length, p,
myObjStyleRight = myDoc.objectStyles.item("Right"), myObjStyleLeft = myDoc.objectStyles.item("Left"),
//////////////////
myCounter = 1;
//////////////////
// Remove Old Num Text Frames
app.findObjectPreferences = null;
app.findObjectPreferences.appliedObjectStyles = myObjStyleRight;
myFound = app.findObject();
var F = myFound.length, f ;
for ( f = 0; f < F ; f++ ) myFound.remove();
app.findObjectPreferences.appliedObjectStyles = myObjStyleLeft;
myFound = app.findObject();
var F = myFound.length, f ;
for ( f = 0; f < F ; f++ ) myFound.remove();
app.findObjectPreferences = null;
// Add New Num Text Frames
for ( p = 0; p < P ; p++) {
var myTFrame = myPages
.textFrames.add();
myTFrame.contents = String(myCounter);
if ( p%2 == 0 ) myTFrame.applyObjectStyle(myObjStyleRight);
else {
myTFrame.applyObjectStyle(myObjStyleLeft);
myCounter++
}
}
}