@Radomir-Stojanović said in Need help for CNC code.:
I have a recurring issue with the beginning and end of my code. I always have to replace the generic text with ‘%’ and manually add an ‘E’ at the end of the program whenever I rewrite it. Is there a way to automate this process?
Whenever I get a new program, I have to correct F400. F200. (or any Fxxx. not to have a period at the end of Fxxx). Can I automate that as well?
This can easily be done with 3 regular expressions (regex), however the 3rd one won’t be completely sorted, I will speak to that later.
So using the Replace function we have the first one which deals with the “generic text issue”.
Search mode must be regular expression for all 3 regex I’m showing.
Find What:(?-s)\A(\([^)]+\)(\R))+
Replace With:N0 %${2}
Click on Replace All
Now we deal with all the Fxxx. sequences.
Find What:(F\d+)\.
Replace With:${1}
Again click on Replace All
Finally the end line for the code. The primary problem here is that regex cannot count. So there isn’t an easy way for the regex to add 1 to the last line and write a new line with the incremented number and and E. So what my regex does is to write it with xx as the line number. So you would still need to change the xx for the real line number. Although I have provided this regex, I think it would be of limited value as you would still need to edit that last line.
Find What:(?-s)(\R).+\K\z
Replace With:${1}Nxx E
These 2 (or 3) regex can be combined into a macro which is essentially the keystrokes recorded as you type them and once saved (with a name) can be re-run whenever you wish.
Terry