forked from bruderstein/PythonScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisionCodeRenamer.py
More file actions
134 lines (99 loc) · 5.33 KB
/
VisionCodeRenamer.py
File metadata and controls
134 lines (99 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# -*- coding: utf-8 -*-
# FROM https://raw.githubusercontent.com/bruderstein/PythonScript/master/scripts/Samples/
import re
# --------------------------------------------------------------------------------------------------------------------------------------
# Script "Multiples_SR.py"
# A LITTLE adaptation by guy038 from an ORIGINAL and VALUABLE script of Alan KILBORN ( January 2019 ) !
# See https://notepad-plus-plus.org/community/topic/16942/pythonscript-any-ready-pyscript-to-replace-one-huge-set-of-regex-phrases-with-others/21
# and https://notepad-plus-plus.org/community/topic/16942/pythonscript-any-ready-pyscript-to-replace-one-huge-set-of-regex-phrases-with-others/23
# This script :
# - Reads an existing "SR_List.txt" file, of the CURRENT directory, containing a list of SEARCH/REPLACEMENT strings, ONE PER line
# - Selects, one at a time, a COUPLE of SEARCH and REPLACEMENT regexes / expressions / strings / characters
# - Executes this present S/R on CURRENT edited file, in NOTEPAD++
# - Loop till the END of file
# Any PURE BLANK line or COMMENT line, beginning with '#', of the "SR_list.txt" file, are simply IGNORED
# --------------------------------------------------------------------------------------------------------------------------------------
# For EACH line, in the "SR_List.txt" file, the format is <DELIMITER><SEARCH regex><DELIMITER><REPLACE regex><DELIMITER>
## EXAMPLES :
## ¯¯¯¯¯¯¯¯
## Deletes any [ending] "; comment" / Delimiter = '!'
#!(?-s)(^.*?);.+!\1!
## Changes any LOWER-case string "notepad++" in its UPPER-case equivalent / Delimiter = '@'
#@(?-i)notepad\+\+@NOTEPAD++@
## Changes any "Smith" and 'James' strings, with that EXACT case, to, respectively, "Name" and "First name" / Delimiter = '&'
## Deletes any "TEST" string, with that EXACT case
#&(Smith)|TEST|(James)&(?1Name)(?2First name)&
## Replaces any BACKSLASH character with the "123" number, both preceded and followed with 3 SPACE characters / Delimiter = '%'
#%\\% 123 %
## or, also, the syntax %\x5c% 123 %
## Deletes any string "Fix", followed with a SPACE char, whatever its CASE / Delimiter = '+'
#+(?i)Fix ++
## Change 3 CONSECUTIVE "#" characters with 3 BACKSLASH characters / Delimiter = '*'
#*###*\\\\\\*
# --------------------------------------------------------------------------------------------------------------------------------------
# In the CODE line, right below, you may :
# - Modify the NAME of the file, containing the SEARCH and REPLACEMENT regexes
# - Indicate an ABSOLUTE or RELATIVE path, before the filename
#with open(r'SR_list.txt') as f: sr_list = f.readlines()
# You may, as well, insert the SEARCH and REPLACE regexes, directly, in THIS script :
sr_list = [
r'!G90!G90 \(Absolute Programming\)!',
r'!G40!G40 \(Kerf Off\)!',
r'!G41!G41 \(Kerf Left\)!',
r'!G42!G42 \(Kerf Right\)!',
r'!G91!G91 \(Incremental Programming\)!',
r'!G70!G70 \(Inch Mode\)!',
r'!G84!G84 \(Deselect all Stations\)!',
r'!G85\s?I(\d)(\d)\s?J(-?\d*.\d*)(\r|\n)!G85 I($1)($2) J($3) \(Fix St ($1), Move St ($2) Spacing=($3)\)!',
r'!G83\s?I(\d)\s?(\r|\n)!G83 I($1)\(Select Station ($1)\)($2)!',
r'!G83\s?I(\d)\s?J(\d)!G83 I($1) ($2)\(Select Station ($1) Clamp Mode=($2)\)!',
r'!AL\s?(-?\d*.\d*)!AL ($1) \(Tilt to ($1) Degrees\)!',
r'!(M178\s?D1)!($1) \(Send Y1 to Home\)!',
r'!(M178\s?D2)!($1) \(Send Y2 to Home\)!',
r'!G71!G71 \(Metric Mode\)!',
r'!M65!M65 \(Plasma Start\)!',
r'!M02!M02 \(Program Stop\)!',
r'!M66!M66 \(Plasma Stop\)!',
r'!M177!M177 \(Foot Up\)!',
r'!M174!M174 \(Flying Stop\)!',
r'!M176!M176 \(Foot Down\)!',
r'!M35!M35 \(Rotation look ahead 1 block\)!',
r'!M34!M34 \(Rotation skip block\)!',
r'!M58!M58 \(AVHC Enable\)!',
r'!M57!M57 \(AVHC Disable\)!',
r'!M145 D0!M145 D0 \(Straight/I ORG Selection\)!',
r'!M145 D1!M145 D1 \(Y ORG Selection\)!',
r'!M145 D2!M145 D2 \(K ORG Selection\)!',
r'!G160 P1!G160 P1 \(Plasma Process\)!',
r'!G160 P2!G160 P2 \(Oxy-Fuel Process\)!',
r'!M62!M62 \(Rotation Stop\Freeze\)!',
r'!M63!M63 \(Rotation On\)!',
r'!M64!M64 \(Rotation Off\)!',
r'!D3(\r|\n)!D3 \(Comment Block Start\)($1)!',
r'!D4(\r|\n)!D4 \(Comment Block End\)($1)!',
r'!(M129 D(.\d)*)!($1) \(Total Material Thickness\)!',
r'!(M120 D(.\d)*)!($1) \(Feature Height\)!',
r'!(T\d)!($1) \(Tool Offset Select\)!'
]
# The use of RAW strings r'.......' is also possible, in order to SIMPLIFY some regexes
# Note that these RAW regexes are strictly IDENTICAL to those, which could be contained in a "SR_List.txt" file, WITHOUT the 'r' PREFIX
#sr_list = [
# r'!(?-s)(^.*?);.+!\1!',
# r'@(?-i)notepad\+\+@NOTEPAD++@',
# r'&(Smith)|TEST|(James)&(?1Name)(?2First name)&',
# r'%\\% 123 %',
# # or the syntax r'%\x5c% 123 %',
# r'+(?i)Fix ++',
# r'*###*\\\\\\*',
# ]
editor.beginUndoAction()
console.write ('\nMODIFICATIONS on FILE "{}: "\n\n'.format(notepad.getCurrentFilename()))
# Note : Variable e is always EMPTY string ( Part AFTER the THIRD delimiter and BEFORE the END of line ! )
for line in sr_list:
if line[0] == '#' or line == '\n' : continue
(s,r,e) = line[1:].rstrip('\n').split(line[0])
console.write(' SEARCH : >{}<\n'.format(s))
console.write(' REPLACE : >{}<\n\n'.format(r))
editor.rereplace(s,r) # or editor.rereplace(s,r,re.IGNORECASE) / editor.rereplace(s,r,re.I)
editor.endUndoAction()
# END of Multiple_SR.py script