- AuthorPosts
- August 18, 2009 at 6:38 pm #7562blackhawkParticipant
Has anyone created (or know of a good approach to) a macro that will append numbers vertically? (Abililty to re-number would also be great!)
I seem to deal a lot with the following pseudo-code that needs to be duplicated an then numbered for as many times as is needed. In some cases, the code is a single line of text and others it is a block of code.
At the moment, I seem to have to create a unique recorded macro for each situation in order to make the changes repeatable.
Is there a better way?
Example:
Code to be repeated:
var# = Item#.Lookup('Name#');
Output:
var1 = Item1.Lookup('Name1');
var2 = Item2.Lookup('Name2');
var3 = Item3.Lookup('Name3');
var4 = Item4.Lookup('Name4');
var5 = Item5.Lookup('Name5');
var6 = Item6.Lookup('Name6');
var7 = Item7.Lookup('Name7');
var8 = Item8.Lookup('Name8');
var9 = Item9.Lookup('Name9');
var10 = Item10.Lookup('Name10');
var11 = Item11.Lookup('Name11');
August 25, 2009 at 2:30 pm #7577crowdyMembertry this
// save current position
var g_curX = document.selection.GetActivePointX(eePosLogical);
var g_curY = document.selection.GetActivePointY(eePosLogical);
function newLine() {
// make new line
document.selection.EndOfLine(false,eeLineView);
document.selection.NewLine(1);
}
function main() {
var line;
if (document.selection.IsEmpty) {
// get current single line
document.selection.StartOfLine(false, eeLineLogical);
document.selection.EndOfLine(true, eeLineLogical);
line = document.selection.Text;
} else {
line = document.selection.Text;
}
if (line.indexOf('#')>0) {
var strNum = prompt("how many times do you want to repeat?", "10");
repeatnum = parseInt(strNum);
// is it numeric?
if (!isNaN(repeatnum)) {
newLine();
// do repeat
for (var i=1; i<=repeatnum; i++) {
document.writeln(line.replace(/#/g, i));
}
}
}
document.selection.Collapse();
document.selection.SetActivePoint(eePosLogical, g_curX, g_curY);
}
main();
August 25, 2009 at 4:02 pm #7578blackhawkParticipantFirst of all:
Thank you for your post!!Interesting approach. The part that is a challenge though is how do we re-number them once it has been numbered? That is where I got stuck.
The other goofy part is that you cannot count on the digits being the same number or in the same location for each line, so you can’t just go down the lines and update the numbers.
Brain burner.
August 26, 2009 at 12:41 am #7579crowdyMemberhow do we re-number them once it has been numbered?
I wonder if this might help
var src = "var17 = Item17.Lookup('Name17');"
var re = /d+/g;
var arr;
while ((arr = re.exec(src)) != null)
document.writeln(arr.index + "-" + arr.lastIndex + "t" + arr);
this shows
3-5 17
12-14 17
27-29 17
August 26, 2009 at 2:23 am #7580blackhawkParticipantI think you are on to something here.
Some kind of combination of your previous script and this one, based on whether or not you have a selection(?) perhaps?
I.e. If you have a selection it does a replacement (above script). And if no selection, it pops up a dialog box and prompts you for the number of times to replicate the current line (previous script), replacing the digits. (So long as there are no other digits in the text).
Hmmmmm……
Thanks again for your feedback!
- AuthorPosts
- You must be logged in to reply to this topic.