renumbering/incremental
-
You cannot do this in Notepad++ without script programming, the most common scripting language is Python. If you’re not familiar with Python, but are with programming another language, you don’t need to use Notepad++ at all.
More information in the FAQ about this, HERE.
-
@Alan-Kilborn I am not familiar with programming at all (as is shown by the amazing help you needed to give me on my last post)
-
@Scott-Raskin said in renumbering/incremental:
is something in this program that will allow me to make the Ns in numerical order without changing the code
As @Alan-Kilborn said, the search-and-replace engine cannot do it.
However, using the Column Select mode and the Edit > Column Editor tool, you can.
If you’ve got just those 7 (or any fewer than 10) lines, and want them numbered from 00 to 07 in order:
- Use column-select (Alt+Click&Drag or Shift+Alt+ArrowKeys) to select the rightmost column of digits
- Use Edit > Column Editor (or Alt+C) to bring up the Column/Multi-Selection Editor dialog
- Choose Number to Insert
- Initial Number:
1
- Increase By:
1
- ☑ Leading Zeroes
- OK will then fill that column with
1
-7
If you have 10 or more rows (so you’ll need at least two digits, then do the selection from the upper zero to the lower right digit, like this:
The same dialog choices will then have it replace with01
thru12
=>
- Use column-select (Alt+Click&Drag or Shift+Alt+ArrowKeys) to select the rightmost column of digits
-
@Scott-Raskin is there a place I can ask for specific help with that query on a python board?
-
While Peter’s technique should work, I remember this line from the OP’s earlier THREAD:
So I have about 1000 CNC programs that I am trying to edit…
I don’t see OP applying the column editor technique this many times. :-(
-
Sorry, I didn’t remember that from the previous thread.
Mine will definitely not easily work with 1000 files.
-
@PeterJones thank you very much, but yes, as was mentioned I needed to do it for 1000s of programs. I must need python but Id have to learn that first :)
-
@Scott-Raskin said in renumbering/incremental:
must need python but Id have to learn that first
Well if you can follow a recipe, it isn’t that bad, and you aren’t forced to learn a whole programming language.
Have you had a look at the FAQ entry I linked to earlier? Specifically HERE which seems very close to your problem?
-
@Alan-Kilborn it looks like this would be similar but yes, I will look into it as I know its not exact. My wife doesnt let me cook so Im not sure how good I am at following recipes :) I also dont know if this string is all I would add but I will test a few recipes and hope I dont burn it all down
def add_1(m):
return ‘N’ + str(int(m.group(1)) + 10)editor.rereplace(‘N([00-400]+)’, add_10);
-
So there’s the recipe stuff, and then there’s getting your regular expressions correct. If you don’t get the reg. ex. correct, recipe go BOOM.
So, regexes:
Based on:
the machine that reads it MUST see the N0 in numerical order as above (N01, N02, N03 etc)
I’m not sure why you would change the code to add 10 rather than add 1??
Also, to match digits in a regular expression, you don’t do
[00-400]+
, you’d do\d+
which seems like it could work for your case, or if you want to limit it to 2 digits you could do\d{2}
or if you want 2 OR 3 digits you could do\d{2,3}
.There’s more to say, but start there. You need a regular expression that will match all of the occurrences of the data you need to change, obviously.
I’d say get an interactive replacement working first (forget the Python code for now), where you match all occurrences and replace them with a fixed string like
dummy
. That’s a big step, and after that we can adjust it so you don’t usedummy
any longer, but get the sequential numbers you are after. -
@Alan-Kilborn sorry, got confused for a second (but I did love “recipe go BOOM”) so I was realizing that simply adding a number to each line wont necessarily work: lets say if I told it to add 10 to each line: N01, N02, N03 would simply become N11, N12, N13. that TECHNICALLY works for adding code to the beginning of the program because I would be able to add10 lines before I got to the N11, so if thats the best I can do, then ok. but what I really wanted originally is for it to be incremental by 10 so N10, N20, N30 and so on, so I can put stuff in between when needed without needing to renumber again
So, N only shows up at the program number part of the program, an N doesnt show anywhere else, so having it look for anything with N followed by a # first works. (I thought I was asking it to look for anything with an N00 to an N400)
also, who are you calling a dummy :) ?
-
@Scott-Raskin said in renumbering/incremental:
for it to be incremental by 10 so N10, N20, N30 and so on, so I can put stuff in between when needed without needing to renumber again
OK, that IS a good idea. I can tell you are a non-
dummy
. :-)
And yes, you can certainly “add 10” as easily as “adding 1”.I was just confused because of your original desire. We get that a lot in back-and-forth posts here…the original “want” changes slightly and that’s fine for the person with the need, but they start talking about their “new track” without saying it is new, and, well, with everyone listening not really as “close” to the problem as the original poster…things can get confused.
-
@Alan-Kilborn thank you. I cant say I am not a little dummy-esque when it comes to this. I can build computers, have written macros, do most things within most software programs (or at least figure it out on my own), but I think with 3 boys, my 4 year old being sick, my 2 year old super enjoying waking us up at night, me waking up at 330-4 every morning and therefore averaging less than 5 hours of sleep a night, Im just not seeing it in that script why it isnt working ( i changed it a little as I realized some things when looking at the programs on a different machine that have 4 digits after the N)
in the script
def add_10(m):
return ‘N’ + str(int(m.group(1)) + 10)editor.rereplace(‘N([0000-0400]+)’, add_10);
I just dont know what is doing what and why it isnt working (as I thought I made the appropriate changes from that link you sent me) and then even THEN, once I get it working, and run the script (I already installed python and tried to run this), hw I get it to run on all open files in the workspace
so, not a “dummy” per se, but something. The thing that frustrates me the most is, its not like I have no computer knowledge, in which case I would find someone to write it for me. The frustrating part is knowing how to do things similar to this. Knowing that Im on the right path, but I lost my GPS signal a few stops short of my goal
-
That’s because there is a difference between following a recipe, and knowing how to cook. :) It’s not a slight to you, or a description of the difficulty of the task…it’s simply the difference between something you do all the time, and something you’re trying to pick up that doesn’t work like what you’re used to, even though it can get it done if you knew it better. :)
Even cooking requires going through the awkward stage of mistakes and experimentation before the knowledge is learned, beyond the concepts. :) -
@Scott-Raskin said in renumbering/incremental:
[0000-0400]
This is a nonsensical regular expression, as I tried to point out before. And if you are talking about running the script at this stage (i.e., with that expression), I can tell you didn’t heed the earlier advice about getting the replacement working without the script first. :-(
Is there any reason you didn’t try searching for
^N\d{4}
?
BTW, it looks like you might be trying to limit the number that follows theN
to the range 0 <= x <= 400 – is that right? Or are you just looking for “any 4 digits”?Things are filling with so much uncertainty it is getting hard to help.
averaging less than 5 hours of sleep a night
I feel for you, for those other problems, but I have no other such problems and I still average less than 5 hours myself. :-(
-
@Alan-Kilborn So, when I do that search string (I was at at a computer whereit only had 2 digits so I changed it to ^N\d{2} it finds the first line N00, then when I do next it finds the N01 and so on, and I can replace it with any text (I just told it to replace it with “please please please work”
As for limiting the #s, no I dont need to limit it to anything, some programs have up to N300 some have up to N150.
-
@Scott-Raskin said:
I changed it to ^N\d{2} it finds the first line N00, then when I do next it finds the N01 and so on, and I can replace it with any text
Smells like progress.
I just told it to replace it with “please please please work”
Praying can sometimes help. :-)
As for limiting the #s, no I dont need to limit it to anything, some programs have up to N300 some have up to N150.
OK, so maybe
^N\d+
is what you want.
^
: make sure we are at start of line
N
: literalN
\d+
: one or more digitsBut hold on…need to know where the digits are so we can replace them.
Go with
^N(\d+)
.
The parens “capture” what we call “group 1” data.In the script code, you can see how it uses
m.group(1)
?
That refers to whatever was found, for digits afterN
.
and you can see how the script code adds 10 to it…I think we’re ready to be scriptable; mostly based on your previous attempt, but changed slightly:
def add_10(m): return 'N' + str(int(m.group(1)) + 10) editor.rereplace(r'^N(\d+)', add_10)
-
I think I see a wrinkle in your original idea of creating some numerical spacing between entries, with your “add 10” idea.
If you had the sequence 1,2,3,… and you did a simple “add 10” replacement, you’d get 11,12,13,… But you don’t get the desired spacing between the resultant numbers. You’d want to do more of a “multiply by 10” to obtain that spacing: 10,20,30…
But maybe another problem unforeseen (or really, unthought of, in detail) to this point, is that you want to renumber, not merely increment (by ten, or whatever) an existing number.
Never fear, let’s just keep going, and we can make the adjustments for the above at the appropriate time!
-
@Alan-Kilborn
Probably a lot faster to do this in excel by dragging down column to renumber and if needed use excels macros. -
@swegmike said in renumbering/incremental:
Probably a lot faster to do this in excel by dragging down column to renumber and if needed use excels macros.
One sentence, so many things wrong with it…