Custom search and replace



  • I’m trying to build a macro to search for lines that begin with G1 and don’t contain an E in the line and then replace the G1 with G0. This is for gcode for CAD machines. I’ve created search and replace blank lines and got rid of all comments, now I want to replace G1 commands for those commands that don’t involve the extruder, in those cases the G0 command is the correct / appropriate command. So I want to search for all lines with G1 and in those lines if there is no E in the line then replace G1 with G0.



  • @Steve-Allen-0 ,

    You don’t give much in the way of examples to help us understand.

    Please follow the advice below – especially in regard to including example before and after data, and how to format the data so we understand it and the forum doesn’t mangle it – in order to get a better answer to your question.

    ----

    Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the </> toolbar button or manual Markdown syntax. To make regex in red (and so they keep their special characters like *), use backticks, like `^.*?blah.*?\z`. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.



  • @Steve-Allen-0
    I’ll expand on this post a bit.

    Here’s an example of part of the code;
    G1 Y285.500 E1.1134
    G1 X309.500 E2.7140
    G1 Y309.500 E1.1134
    G1 X251.000
    G1 X251.500 Y309.000 E0.0328

    I would want this to be
    G1 Y285.500 E1.1134
    G1 X309.500 E2.7140
    G1 Y309.500 E1.1134
    G0 X251.000
    G1 X251.500 Y309.000 E0.0328

    Now, the non-E lines may have an Xnumber, a Ynumber or and Xnumber and a Ynumber like this
    G1 X305.200 Y270.300
    G1 X324.700
    G1 Y170.400
    The above would all need to be G0 not G1.



  • @Steve-Allen-0 said in Custom search and replace:

    That helps

    FIND = ^G1(?=((?!E).)*$)
    REPLACE = G0
    SEARCH MODE = regular expression

    G1 Y285.500 E1.1134
    G1 X309.500 E2.7140
    G1 Y309.500 E1.1134
    G1 X251.000
    G1 X251.500 Y309.000 E0.0328
    
    G1 X305.200 Y270.300
    G1 X324.700
    G1 Y170.400
    
    END
    

    becomes

    G1 Y285.500 E1.1134
    G1 X309.500 E2.7140
    G1 Y309.500 E1.1134
    G0 X251.000
    G1 X251.500 Y309.000 E0.0328
    
    G0 X305.200 Y270.300
    G0 X324.700
    G0 Y170.400
    
    END
    

    concepts =



  • All I can say is Thanks! That works perfectly!


Log in to reply