• Login
Community
  • Login

Simple text clean up

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 4 Posters 2.6k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    Adam Labuš
    last edited by Sep 22, 2020, 4:49 PM

    I have exported g.code from cura to a txt file. My mission is to create a animation of 3D printing in blender with python. So I just need to do some basic deleting of the g.code and I want to leave the coordinate info behind. So I downloaded notepad++ and this is what I have to do

    G1 X184.218 Y123.524 E1.81219 - I want to keep only the info after X Y
    G1 X183.179 Y125.34 E1.83974
    M204 S625 - I want to delete everything in this section except the the last line
    M205 X10 Y10
    G0 F2571.4 X182.84 Y125.092
    M204 S500
    G1 X183.179 Y125.34 E1.83974 - Then it all repeats
    G1 X183.179 Y125.34 E1.83974

    The question is how do I do that, I know this is really simple but for the love of god I cant figure it out, so do you know how to do it?

    https://drive.google.com/file/d/1iRhHJdNw8RQ2fv7W6x-kJwG3bHUDW0qS/view?usp=sharing - The g.code

    A 1 Reply Last reply Sep 22, 2020, 5:02 PM Reply Quote 0
    • A
      Alan Kilborn @Adam Labuš
      last edited by Sep 22, 2020, 5:02 PM

      @Adam-Labuš

      Can’t you just show a before text (which I think you have) and a desired after text?

      1 Reply Last reply Reply Quote 1
      • A
        Adam Labuš
        last edited by Sep 22, 2020, 5:41 PM

        So this is how it looks like now
        G1 X184.218 Y123.524 E1.81219
        G1 X183.179 Y125.34 E1.83974
        M204 S625
        M205 X10 Y10
        G0 F2571.4 X182.84 Y125.092
        M204 S500
        G1 X183.179 Y125.34 E1.83974

        This is how it should look like

        X184.218 Y123.524
        X183.179 Y125.34
        M204 S500
        X183.179 Y125.34

        1 Reply Last reply Reply Quote 1
        • G
          guy038
          last edited by Sep 22, 2020, 6:42 PM

          Hello, @adam-labuš, @alan-kilborn and All,

          Try this regex S/R :

          SEARCH (?-si)^((?!G1).+\R)?G1\x20(X\d+\.\d+\x20Y\d+\.\d+).+|.+\R

          REPLACE \1\2

          The algorithm used is :

          • Any line, right before a line G1 X...., is just kept

          • Any line, beginning with the G1 command, is replaced with the coordinates X and Y, only

          • Any other line is simply deleted

          Best Regards,

          guy038

          M 1 Reply Last reply Sep 22, 2020, 7:11 PM Reply Quote 1
          • M
            M Andre Z Eckenrode @guy038
            last edited by Sep 22, 2020, 7:11 PM

            @Adam-Labuš said in Simple text clean up:

            G1 X184.218 Y123.524 E1.81219 - I want to keep only the info after X Y

            Not sure if @guy038 already got this worked out the way you wanted, but I was going to take a gander at this, and have downloaded a copy of your gcode for further inspection, though I have to admit that it’s far from clear to me what to keep and what to discard. Does every line that contains the X and Y values you want to keep begin with G1?

            There are also many other lines in your gcode that don’t resemble any of those in your posted examples, especially at the beginning and end of the file. Are those to be ignored in whatever operation we come up with?

            M204 S625 - I want to delete everything in this section except the the last line

            You appear to indicate that the ‘last line’ of ‘this section’ is M204 S500, since that’s the line you show as being retained in your second post, but in your gcode file, I see lots instances of lines with M205 X5 Y5 — not shown in any of your posted examples — immediately following those with M204 S500, as in the following data extracted from your gcode:

            M204 S625
            M205 X10 Y10
            G0 F2571.4 X182.84 Y125.092
            M204 S500
            M205 X5 Y5
            

            So what, exactly, defines ‘this section’?

            1 Reply Last reply Reply Quote 3
            • A
              Adam Labuš
              last edited by Sep 23, 2020, 12:53 PM

              OK so sorry for making this forum thread a mess but after a little reasearch I figured out this
              I need to keep all lines starting with G1 and G0 like these two

              G1 X181.281 Y127.145 E1.8737
              G0 F2571.4 X182.162 Y124.596

              I want to delete all of the other stuff in these lines and just keep this

              X181.281 Y127.145
              X182.162 Y124.596

              For the other lines I want to delete everything else except lines that looks like this

              ;LAYER:1

              I have tried what guy038 said and it worked WONDERFULLY but because of my unclear instructions (I am not a native speaker sorry) the result wasnt what I wanted and because I dont understand the language completely I cannnot modify its instructions to keep the lines that start with G1 and ;LAYER:1 also.
              So once again can you guys help?

              1 Reply Last reply Reply Quote 0
              • G
                guy038
                last edited by guy038 Sep 23, 2020, 6:10 PM Sep 23, 2020, 5:55 PM

                Hello, @adam-labuš, @alan-kilborn, @m_andre_z_eckenrode and All,

                Ah, OK ! With your new specifications, it’s easier to get the right regex, at once ;-))

                But when you said :

                For the other lines I want to delete everything else except lines that looks like this

                ;LAYER:1

                We don’t know if you speak of lines which begin, contain or end with ;LAYER:1 ! I suppose that it is which begin…


                Then, from this simple example, below :

                G1 X184.218 Y123.524 E1.81219
                G1 X183.179 Y125.34 E1.83974
                M204 S625
                ;LAYER:1 bla bla blah
                M205 X10 Y10
                G0 F2571.4 X182.84 Y125.092
                M204 S500
                G1 X183.179 Y125.34 E1.83974
                

                The following regex S/R

                SEARCH (?-si)^G[01].+(X\d+\.\d+\x20Y\d+\.\d+).*|^(?!;LAYER:1).+\R

                REPLACE \1

                would output this text :

                X184.218 Y123.524
                X183.179 Y125.34
                ;LAYER:1 bla bla blah
                X182.84 Y125.092
                X183.179 Y125.34
                

                Notes :

                • The in line modifiers (?-si) mean that :

                  • Any dot regex symbol represents a single standard character and not EOL chars, as \r or \n (?-s)

                  • The search is run in a non-insensitive way (?-i)

                • Then the search regex contains two alternatives, separated with the | symbol :

                  • The regex ^G[01].+(X\d+\.\d+\x20Y\d+\.\d+).*

                    • The part ^G[01] looks for strings G0 or G1, beginning current line

                    • The part .+ represents any non-null range of standard characters

                    • The part (X\d+\.\d+\x20Y\d+\.\d+) search for the exact letter X, followed with some digits \d+, followed with a literal dot \. followed by decimal digits \d+ and a space char \x20 then the exact letter Y and … ( same process than for X ). As all the part is surrounded by parentheses, its contents are stored as group 1

                    • Finally, the part .* represents any range of standard characters, possibly null

                  • The regex ^(?!;LAYER:1).+\R

                    • The part ^(?!;LAYER:1) search all the lines which not begin with the string ;LAYER:1

                    • And the part .+\R catches all the characters of any non-null line .+, with its line-break chars \R ( = \r\n for Windows files, \n for Unix files, or \r for Mac files )

                • In replacement :

                  • If the left regex matches, then the group 1 is defined and corresponds to the XY coordinates, which must be rewritten => \1

                  • Else, the right regex is used. As no group is defined, in the second alternative, the pointer to group 1 \1 return a null string. So, the current matched line is just deleted !

                Best Regards,

                guy038

                1 Reply Last reply Reply Quote 2
                3 out of 7
                • First post
                  3/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors