Results 1 to 5 of 5

Thread: Help with Regex match groups or alternate method to handle task

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    20

    Help with Regex match groups or alternate method to handle task

    Fellow forum members,

    Let me preface this with my experience level, most of my programming experience has been with numerical analysis in C, Matlab, and I have coded some stuff in VB.net. I do not program on a daily basis.....

    Below is a snippet of a CNC mill program for a certain machine. G02 and G03 are arc commands with the R word as the radius of curvature.

    I have a pile of programs I need to convert from one machine format to another. In the code below, the R word is modal, which is not typical on most other CNC machines. I'm struggling with how to save the R word as a variable and insert it at the end of the line on the next G02/03 line without an R word.

    I have tried several methods including using regex to search the R word and store as a group, but I can't figure out how to differentiate the lines without the R word and place the correct group on the line.

    Looking for some direction on how to handle this task.

    Thanks



    Code:
    T01M06
    G90G54G00X-1.0Y2.0S1500M03
    G43H2.0Z.1
    Z.1
    G01Z0.F5.0
    G40D01X0
    Y3.0
    G02X1.0Y4.0R1.0
    G01Y3.0
    G02X4.0Y3.0
    G01Y0.5
    G02X3.5Y0.R.5
    G01X.5
    G02X0Y.5
    G01Y2.0
    G03X-.5Y2.5
    G01X-1.0
    G00Z2.0M09
    G91G28Z0
    G28Y0.

  2. #2
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: Help with Regex match groups or alternate method to handle task

    Not sure I've understood properly. Do G02 and G03 maintain their own inpependant R values between changes? The following doesn't. It applies the most recent R value, irrespective of G value.

    VB.NET Code:
    1. '   create an array of the command lines
    2. '   eg. if they are stored in a file:
    3. Dim commandLines() As String = IO.File.ReadAllLines("<somefilepath>")
    4.  
    5.  
    6. '   variable to hold most recent R command
    7. '   Does this need initialising to some default value for R?
    8. Dim rPart As String = ""
    9.  
    10. '   iterate through all the command lines
    11. For indx As Integer = 0 To commandLines.Length - 1
    12.     Dim line As String = commandLines(indx)
    13.  
    14.     '   looking for lines starting "G02" or "G03"
    15.     If line.StartsWith("G02") OrElse line.StartsWith("G03") Then
    16.         '   if it contains an R command, make a note of the R command
    17.         If line.Contains("R") Then
    18.             rPart = line.Substring(line.IndexOf("R"))
    19.         Else
    20.             '   otherwise add the last noted R command to the end of the command line
    21.             commandLines(indx) = line & rPart
    22.         End If
    23.     End If
    24. Next
    25.  
    26.  
    27. '   write the ammended command lines out to a DIFFERENT file
    28. IO.File.WriteAllLines("<someOtherFilePath>", commandLines)

    Code:
    T01M06
    G90G54G00X-1.0Y2.0S1500M03
    G43H2.0Z.1
    Z.1
    G01Z0.F5.0
    G40D01X0
    Y3.0
    G02X1.0Y4.0R1.0
    G01Y3.0
    G02X4.0Y3.0R1.0
    G01Y0.5
    G02X3.5Y0.R.5
    G01X.5
    G02X0Y.5R.5
    G01Y2.0
    G03X-.5Y2.5R.5
    G01X-1.0
    G00Z2.0M09
    G91G28Z0
    G28Y0.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    20

    Re: Help with Regex match groups or alternate method to handle task

    Exactly what i'm looking for.....

    I was trying to take the contents of a textbox and turn them into an array of strings......I wasn't very successful.

    I'll try this approach, would be easier to setup a batch run....

    Thanks!

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: Help with Regex match groups or alternate method to handle task

    Quote Originally Posted by Out2thow View Post
    I was trying to take the contents of a textbox and turn them into an array of strings.....

    Have a look at the TextBox Lines property https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    20

    Re: [RESOLVED]Help with Regex match groups or alternate method to handle task

    Quote Originally Posted by Inferrd View Post
    Have a look at the TextBox Lines property https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx
    Thanks, Already looked it over, still had issues.....got it going though, thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width