renumbering/incremental
-
@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…
-
Writing here as a former N/C Systems programmer.
- Renumbering is usually easiest if you simply remove all the line numbers, completely, and generate a new set from scratch.
Fortunately, this is not like BASIC programs, where the numbers were referenced (GOTO, GOSUB) from other lines. (Some CNC controllers did allow that, but I never saw it used very much in actual CNC programs.)
If such references do exist, then you’d need to track down the references, and update them, too, to match. This requires good recordkeeping, and is definitely a candidate for automation.
If I recall correctly, some users would number only a selected few lines, e.g., those where a tool change occurred, or those beginning a subroutine or loop. The rest would remain unnumbered. On the other hand, if the machine found a syntax or other error, then tracking it down, without line numbers, became a major pain. There were, then, sometimes, two versions of a program: one with line numbers, used for early runs, and one without, used after the fully-numbered version had been proven reliable.
BASIC programs were often numbered in increments of 10, to allow for easy insertion of lines, without having to renumber the whole darn program. If you want to number every line, then I suggest doing the same thing here.
- Doing it for thousands of distinct program files will require two distinct automations: one to locate and enumerate all the CNC files to be changed, wherever they are in the file system, and another to renumber each one.
I recommend putting the new, renumbered versions in a new location entirely, to avoid accidentally overwriting the original files. After all, programs rarely work right the first time!
Under Windows 10, CMD.EXE’s batch language can probably handle this kind of work. The advantage being that you don’t need to install it; it’s already there. The disadvantage being that it is a horrible programming language for newbies. (And just about everyone else.)
Having several years of experience, now, with Python, I can confidently say that Python is a much better bet for writing programs that novices can actually read, understand, and update. No add-on modules are required. Moreover, for tasks like this, very little of the Python language needs to be understood, to do an adequate job.
Python is available, free, in the Windows Store, so it is virtually painless to install. And Notepad++ is an excellent editor for writing your Python programs.
The sheer volume of work to be done makes it hard for me to recommend Notepad++ – or any manually-operated editor – in any other capacity, for this particular task.
-
@Alan-Kilborn Yes, that is what I was saying could be a wrinkle. However having been up since 2am, I am realizing that having to insert lines in between is an exception to the rule, rather than the rule.
That being said, I ran that script and it worked perfectly. I am going to study (I mean its only 3 lines, but still) that script and try to understand what each part means so maybe I can go forward and make changes on my own. Really my end goal with everything is to be able to learn, so I really appreciate all of the help youve given me to get here.
The only thing I dont see, is how to run that script on ALL of the files in the workspace. When I do a find/replace, you can run it on all files open in the workspace (which I will do when I get to the point that you previously helped me with (replacing by line # within program), but I am sure that is somewhere in the python help guides!
Thank you again and I will let you know my progress and what I have learned (I know, you are waiting with bated breath)
-
@Alan-Kilborn and then I am going to do some more research on seeing if I can combine the two things you helped me with into one script (the replacing specific line thing: \A(?-s).\R.\R.*\R)
Every time I start looking for the ability to use the script to replace EVERY file in a folders info, someone comes and interrupts me (and with my ADD I have to start all over again) How do you guys do this as I am assuming you are helping dozens of people on top of your regular life? -
@Scott-Raskin said in renumbering/incremental:
Every time I start …“task x”…, someone comes and interrupts me (and with my ADD I have to start all over again) How do you guys do this as I am assuming you are helping dozens of people on top of your regular life?
Hah, well, occupational hazard I guess.
Work-from-home helps. :-)
But yea, sometimes I wish the “real world” would go away, so I could sit around and play with Notepad++ all day. :-) -
@Alan-Kilborn yeah, can’t work from home unfortunately as production of a physical product is a bit difficult remotely (until we have fully automated robots to do it all)
So, before I exhaust myself looking for naught, are either of those things possible (running the script on all of the files loaded in the workspace) and/or adding that line renumbered thing to the python code? If so. I will spend my weekend on the hunt -
@Scott-Raskin-0 said in renumbering/incremental:
are either of those things possible (running the script on all of the files loaded in the workspace) and/or adding that line renumbered thing to the python code?
Yes and yes, both are possible.
But…I think you started out talking about 1000 files…surely you aren’t going to have that many “loaded in the workspace” of Notepad++??I think you’ve put in some hard work on this solution; how about if I finish up the script for you and post it? We sort of need such a model for the next time someone asks for this frequent need. We already have a template for a similar task that I can modify…
-
@Alan-Kilborn so what I did was click load folder into workspace and loaded that folder. I think there were close to 1000 files on the tree on the left. So, if I right click on the folder and do a find/replace and then click replace in all, it will replace in all 1000 files there. As for posting the code that would be amazing (as I’ve already seen a few people with my specific problem, and I imagine others with something similar)
-
@Scott-Raskin-0 said in renumbering/incremental:
so what I did was click load folder into workspace and loaded that folder. I think there were close to 1000 files on the tree on the left. So, if I right click on the folder and do a find/replace and then click replace in all, it will replace in all 1000 files there.
OK, I understand your thinking on this now. Unfortunately, there’s no easy way to hook a script with custom-replace functionality into that action. But never fear, what I have in mind will work, albeit a bit differently.
As for posting the code that would be amazing (as I’ve already seen a few people with my specific problem, and I imagine others with something similar)
Yes, give me a bit of time to do it and post it. Although it is 4am where I am (and I’ve just arisen after my 5 hours of sleep), I have a few other tasks to get to as well. Check back here periodically…