Hide comment
-
I need to hide the comments, because I want to numbering only the code lines.
Or if somebody have an idea to numbering all the program lines only, please answer me.It look like this:
;comment
;comment
;comment
N10 G1 X300
N20 G1 X0
;comment
;comment
N30 G0 Z200
N40 G1X400
… -
if semicolon is only once in every line and only within the comment line than
you can search for semicolon and count it, abstract from total number of lines and
you should get the number of code lines.Cheers
Claudia -
Hello, @marcel-lindig,
Even more simple ! From your post, I supposed that, in your language, your comment lines, begin with a semicolon symbol. Now :
-
Open the Find dialog (
Ctrl + F
) -
Type
^[^;\r\n]
, in the Find what: box -
Choose the Regular expression search mode ( IMPORTANT )
-
Click on the Count button
=> You, automatically, get the number of NO-comment lines. ( I supposed that complete blank lines are considered as comment lines ! )
Et voilà !!
Now, if the Python script is installed , in your N++ configuration, you may use, on the other hand, the Claudia’s script, from the link, below :
https://notepad-plus-plus.org/community/topic/13754/replace-1-lines/12
-
Add the comment line
;^[^;\r\n]
, anywhere in your file -
Select the part
^[^;\r\n]
,without
the leading semicolon -
Run the Claudia’s script
=> You, automatically, get, the number of NO-comment lines, again :-D
Best Regards,
guy038
-
-
hm you don´t understand me correctly.
First I wrote this:
;comment
;comment
;comment
G1 X300
G1 X0
;comment
;comment
G0 Z200
G1X400then I want automatically this:
;comment
;comment
;comment
N10 G1 X300
N20 G1 X0
;comment
;comment
N30 G0 Z200
N40 G1X400 -
if you are williing to install python script plugin,
these script may do what you wantnew_cnc_code = '' counter = 10 def add_text(content, line, total): global new_cnc_code global counter if content.startswith(';'): new_cnc_code += content else: new_cnc_code += 'N{0} {1}'.format(counter, content) counter += 10 editor.forEachLine(add_text) # loop through existing text editor.beginUndoAction() # set an undo start point editor.clearAll() # delete the complete content editor.appendText(new_cnc_code) # add the newly created code editor.endUndoAction() # set an undo end point
In case anything goes wrong you should be able to revert everything by pressing undo button.
Don’t know your python knowledge - if something is unclear, let us know.Cheers
Claudia -
Hello, @marcel-lindig,
Of course, the Clauda’s Python script is, certainly, the more simple method to achieve it. But, if you don’t want to use any plugin, here is a procedure, using native N++ commands, only. However, this method will need some steps for the user to do !!
It, mainly, uses :
-
Automatic column numbering, with the Column Editor
-
Search / Replace actions, with the Replace dialog
-
Ascending Lexical Sort
So, let’s start with the original text, below :
;comment 1 ;comment 2 ;comment 3 G1 X300 G1 X0 ;comment 4 ;comment 5 G0 Z200 G1X400 ;comment 6 G2Y100 G3 H500 G2 K200 ;comment 7 ;comment 8 G0 F50 ;comment 9 G3 F100 ;comment 10 G1M100 G1P10 G2 V700 G5 D1000
-
Place the caret to the very beginning of your file, column 1, Line 1 (
Ctrl + Origin
) -
Then, move with the vertical scroll bar, on the right, exclusively, to the last line, column 1
-
Use the
Alt + Maj + Left click
shortcut to get a zero-length rectangular selection, at column 1 -
Hit, twice, on the space key, to add 2 space characters
-
Hit, once, on the
Left Arrow
key, to move back, line 1, column 2 -
Select the option Edit > Column Editor… (
Alt + C
)-
Select the option Number to Insert
-
Type
1
in the two fields Initial number and Increase by -
Check the Leading zeros box
-
If necessary, select the Dec radio button
-
Click on the OK button
-
Delete, possibly, the last non-significant number
-
You should have the modified text, below :
01 ;comment 1 02 ;comment 2 03 ;comment 3 04 G1 X300 05 G1 X0 06 ;comment 4 07 ;comment 5 08 G0 Z200 09 G1X400 10 ;comment 6 11 G2Y100 12 G3 H500 13 G2 K200 14 ;comment 7 15 ;comment 8 16 G0 F50 17 ;comment 9 18 G3 F100 19 ;comment 10 20 G1M100 21 G1P10 22 G2 V700 23 G5 D1000
-
Add TWO complete blank lines, at the end of file, WITHOUT leading spaces
-
Move back, to the very beginning of the file (
Ctrl + Origin
) -
Open the Replace dialog (
Ctrl + H
)-
SEARCH
(?-s)((?:^ \d+ [^;].+\R)++)(?s)(.+)
-
REPLACE
\2\1
-
UN-check the Wrap around option
-
Select the Regular expression search mode
-
Click on the Replace All button, SEVERAL times, till the message
Replace All: 0 occurrences were replaced
occurs
-
Now, your text is changed into the one below :
01 ;comment 1 02 ;comment 2 03 ;comment 3 06 ;comment 4 07 ;comment 5 10 ;comment 6 14 ;comment 7 15 ;comment 8 17 ;comment 9 19 ;comment 10 04 G1 X300 05 G1 X0 08 G0 Z200 09 G1X400 11 G2Y100 12 G3 H500 13 G2 K200 16 G0 F50 18 G3 F100 20 G1M100 21 G1P10 22 G2 V700 23 G5 D1000
-
Move to the first NO-comment line, column 1
-
Locate the caret, right after the digits and the space character, located after
-
Select, again, the option Edit > Column Editor… (
Alt + C
)-
Select the option Number to Insert
-
Type, this time,
10
in the two fields Initial number and Increase by -
Use the same options as above, and click on the OK button
-
Delete, possibly, the last non-significant number
-
-
Move, again, to the first NO-comment line, at column 1
-
Then, open the Replace dialog (
Ctrl + H
)-
SEARCH
^( \d+ )(\d+)
-
REPLACE
\1N\2\x20
-
Use the same options as above and click, ONCE, on the Replace All button
-
After the numbering and S/R actions, you should get the text :
01 ;comment 1 02 ;comment 2 03 ;comment 3 06 ;comment 4 07 ;comment 5 10 ;comment 6 14 ;comment 7 15 ;comment 8 17 ;comment 9 19 ;comment 10 04 N010 G1 X300 05 N020 G1 X0 08 N030 G0 Z200 09 N040 G1X400 11 N050 G2Y100 12 N060 G3 H500 13 N070 G2 K200 16 N080 G0 F50 18 N090 G3 F100 20 N100 G1M100 21 N110 G1P10 22 N120 G2 V700 23 N130 G5 D1000
-
Now, move back at the first line of your file, column 1 (
Ctrl + Origin
) -
Perform a sort, with the menu option Edit > Line Operations > Sort Lines Lexicographically Ascending
-
Move, once more, at the very beginning of your file (
Ctrl + Origin
) -
Delete, if necessary, the pure blank lines, at beginning of the file
-
Finally, open the Replace dialog (
Ctrl + H
)-
SEARCH
^\x20\d+\x20
-
REPLACE
Leave EMPTY
-
Use the same options as above and click, ONCE, on the Replace All button
-
Et voilà ! You should obtain the expected text, below :
;comment 1 ;comment 2 ;comment 3 N010 G1 X300 N020 G1 X0 ;comment 4 ;comment 5 N030 G0 Z200 N040 G1X400 ;comment 6 N050 G2Y100 N060 G3 H500 N070 G2 K200 ;comment 7 ;comment 8 N080 G0 F50 ;comment 9 N090 G3 F100 ;comment 10 N100 G1M100 N110 G1P10 N120 G2 V700 N130 G5 D1000
BTW, from my first S/R above, here is the general way to separate file contents, in TWO parts, according to a criterion ( or more ! ) , with the INITIAL order KEPT. The generic regex is :
SEARCH
(?-s)((?:^
Regex.*\R)++)(?s)(.+)
REPLACE
\2\1
For instance, let’s suppose that you want to separate a text in two parts, each of them keeping the initial order, with the simple condition : a digit, at column 7. Thus, the regex, to include into the generic one, is the regex
.{6}\d
, giving the final S/R :SEARCH
(?-s)((?:^.{6}\d.*\R)++)(?s)(.+)
REPLACE
\2\1
After the replacement :
-
The first part will contain all the lines, which do NOT have a digit, at column 7
-
The second part will contain all the lines, which DO have a digit, at column 7
So, from the example text, with a line break, after the last line, below :
Val : 7 this is a Val : 3 simple text Val : A THIS IS A Val : 4 which should Val : Z SIMPLE TEXT Val : L WHICH SHOULD Val : 9 be readable Val : F BE READABLE Val : C AFTER THE Val : 0 after the Val : 4 search/replacement Val : X SEARCH/REPLACEMENT
After SEVERAL clicks on the Replace All button, till the message
Replace All: 0 occurrences were replaced
occurs, you should get the modified text, below :Val : A THIS IS A Val : Z SIMPLE TEXT Val : L WHICH SHOULD Val : F BE READABLE Val : C AFTER THE Val : X SEARCH/REPLACEMENT Val : 7 this is a Val : 3 simple text Val : 4 which should Val : 9 be readable Val : 0 after the Val : 4 search/replacement
Important :
In the generic search regex,
(?-s)((?:^
Regex.*\R)++)(?s)(.+)
, just note that I use a possessive quantifier, which does NOT allow any backtracking phase.So, when, after some permutations, it remains, only, lines with a digit at column 7, at the end of file, the regex, after catching all these lines, cannot match, , with the second part
(?s)(.+)
, any additional character and fails immediately ! So, the S/R process ends, as expected, with the normal messageReplace All: O occurrences were replaced
If you would use the regex
(?-s)((?:^.{6}\d.*\R)+)(?s)(.+)
, with, instead, a greedy quantifier, the S/R process would NEVER end !Best regards,
guy038
-
-
Thanks a lot.
It works fine.
I will modify it for some other functions.