-
May 19th, 2015, 12:13 PM
#1
Thread Starter
Junior Member
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.
-
May 19th, 2015, 01:26 PM
#2
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:
' create an array of the command lines ' eg. if they are stored in a file: Dim commandLines() As String = IO.File.ReadAllLines("<somefilepath>") ' variable to hold most recent R command ' Does this need initialising to some default value for R? Dim rPart As String = "" ' iterate through all the command lines For indx As Integer = 0 To commandLines.Length - 1 Dim line As String = commandLines(indx) ' looking for lines starting "G02" or "G03" If line.StartsWith("G02") OrElse line.StartsWith("G03") Then ' if it contains an R command, make a note of the R command If line.Contains("R") Then rPart = line.Substring(line.IndexOf("R")) Else ' otherwise add the last noted R command to the end of the command line commandLines(indx) = line & rPart End If End If Next ' write the ammended command lines out to a DIFFERENT file 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.
-
May 19th, 2015, 02:40 PM
#3
Thread Starter
Junior Member
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!
-
May 19th, 2015, 02:45 PM
#4
Re: Help with Regex match groups or alternate method to handle task
Originally Posted by Out2thow
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
-
May 19th, 2015, 03:42 PM
#5
Thread Starter
Junior Member
Re: [RESOLVED]Help with Regex match groups or alternate method to handle task
Originally Posted by Inferrd
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|