Estoy haciendo algunas instrucciones de máquina de Gcode y necesito agregar una instrucción al principio de la línea donde cada primera instancia F 180.0
pero omitir la segunda
p.ej
G00 X 0.0000 Y 0.0000 Z 10.0000
G00 X 24.5230 Y 44.6619 Z 5.0000
G01 X 24.5230 Y 44.6619 Z 0.0000 F 180.0
G01 X 24.5585 Y 45.2432 Z 0.0000 F 180.0
G01 X 24.6723 Y 45.8451 Z 0.0000
Se convertiría
G00 X 0.0000 Y 0.0000 Z 10.0000
G00 X 24.5230 Y 44.6619 Z 5.0000
M03 G01 X 24.5230 Y 44.6619 Z 0.0000 F 180.0
G01 X 24.5585 Y 45.2432 Z 0.0000 F 180.0
G01 X 24.6723 Y 45.8451 Z 0.0000
Supongo que se podría usar el mismo principio, pero luego necesito agregar a cada línea que tengaZ5.0000
G00 X 0.0000 Y 0.0000 Z 10.0000
M05 G00 X 24.5230 Y 44.6619 Z 5.0000
M03 G01 X 24.5230 Y 44.6619 Z 0.0000 F 180.0
G01 X 24.5585 Y 45.2432 Z 0.0000 F 180.0
G01 X 24.6723 Y 45.8451 Z 0.0000
Respuesta1
- Ctrl+H
- Encontrar que:
\A(?:(?:(?!\bF 180\.0\b).)+\R)+\K^(?=.+?\bF 180\.0\b)
- Reemplazar con:
M03
<-- hay un espacio después de M03 - CONTROLAR caso de partido
- CONTROLAR Envolver alrededor
- CONTROLAR Expresión regular
- DESMARCAR
. matches newline
* - Replace all
Explicación:
\A # beginning of file
(?: # non capture group ()
(?: # non capture group (1 line that doesn't contain F 180.0)
(?! # negative lookahead, make sure we haven't after:
\b # word boundary
F 180\.0 # literally
\b # word boundary
) # end lookahead
. # any character but newline
)+ # end group, may appear 1 or more times
\R # any kind of line break
)+ # end group, may appear 1 or more times
\K # forget all we have seen until this position(i.e. skip all lines before the first occurrence of F 180.0)
^ # beginning of line
(?= # positive lookahead, make sure we have after:
.+? # 1 or more any character but newline, not greedy
\b # word boundary
F 180\.0 # literally
\b # word boundary
) # end lookahead
Captura de pantalla (antes):
Captura de pantalla (después):
El segundo reemplazo es similar pero más simple:
- Encontrar que:
^(?=.+?\bZ 5.0000\b)
- Reemplazar con:
M03
Captura de pantalla (después):