Public Class Formcnc Dim listitems() As String Dim enditems() As String Dim vectorZn() As Double Dim vectseparator() As Integer Dim newlistitems() As String Private Sub readfile() Try listitems = System.IO.File.ReadAllLines(OpenFileDialog1.FileName) Codein.Items.Clear() Codein.Items.AddRange(listitems) proceed.Enabled = True Catch ex As Exception MessageBox.Show("fichier introuvable") End End Try End Sub Private Sub SearchEndCode() Dim array1() As String Dim iter As Integer iter = listitems.Length - 1 Do Until listitems(iter).IndexOf("G0 Z") >= 0 iter -= 1 Loop ReDim enditems(listitems.Length - 1 - iter) Array.Copy(listitems, iter, enditems, 0, listitems.Length - iter) ReDim array1(iter - 1) Array.Copy(listitems, 0, array1, 0, array1.Length) ReDim listitems(array1.Length - 1) Array.Copy(array1, listitems, array1.Length) End Sub Private Function GetdecimalSeparator() As Char Dim sp As String sp = 1 / 2 Return (sp.Substring(1, 1)) End Function Private Sub CreateZvector() 'vectorZn contient tous les cotes des GO Z Dim sp As Char Dim zn As Double Dim iterzn As Integer Dim iter As Long Dim iternewlist As Long sp = GetdecimalSeparator() iternewlist = 0 iterzn = 0 ReDim vectorZn(iterzn) For iter = 0 To listitems.Length - 1 If listitems(iter).IndexOf("G0 Z") >= 0 Then If sp <> "." Then listitems(iter) = listitems(iter).Replace(".", sp) End If 'zn le nombre du Go Z Try zn = Double.Parse(listitems(iter).Substring("G0 Z".Length)) If Not vectorZn.Contains(zn) Then ReDim Preserve vectorZn(iterzn) vectorZn(iterzn) = zn iterzn += 1 End If Catch ex As Exception MessageBox.Show("ERROR CODE G0") End End Try End If Next Array.Sort(vectorZn) End Sub Private Sub GroupGoZ() Dim iterz As Integer Dim iterlist As Integer Dim itergroup As Integer Dim start As Integer Dim countseparator As Integer Dim flagfirst As Boolean Dim str As String Dim sp As Char sp = GetdecimalSeparator() flagfirst = False countseparator = 0 For iterz = 0 To vectorZn.Length - 1 If Math.Truncate(vectorZn(iterz)) - vectorZn(iterz) = 0 Then str = "G0 Z" & vectorZn(iterz).ToString("#0.0") Else str = "G0 Z" & vectorZn(iterz).ToString() End If start = 0 iterlist = 0 Do Until iterlist > listitems.Length - 1 If listitems(iterlist).IndexOf(str) >= 0 Then If Not flagfirst Then ReDim Preserve newlistitems(iterlist + 1) System.Array.Copy(listitems, newlistitems, iterlist) flagfirst = True newlistitems(iterlist) = "*".PadLeft(60, "*") ReDim Preserve vectseparator(countseparator) vectseparator(countseparator) = iterlist listitems(iterlist) = listitems(iterlist).Replace(sp, ".") newlistitems(iterlist + 1) = listitems(iterlist) End If itergroup = iterlist + 1 listitems(iterlist) = listitems(iterlist).Replace(sp, ".") newlistitems(newlistitems.Length - 1) = listitems(iterlist) Do While listitems(itergroup).IndexOf("G0 Z") < 0 ReDim Preserve newlistitems(newlistitems.Length) newlistitems(newlistitems.Length - 1) = listitems(itergroup) itergroup += 1 If itergroup = listitems.Length Then Exit Do End If Loop ReDim Preserve newlistitems(newlistitems.Length) countseparator += 1 ReDim Preserve vectseparator(countseparator) vectseparator(countseparator) = newlistitems.Length - 1 newlistitems(newlistitems.Length - 1) = "-".PadLeft(60, "-") iterlist = itergroup ReDim Preserve newlistitems(newlistitems.Length) End If iterlist += 1 Loop Next ReDim Preserve newlistitems(newlistitems.Length - 1 + enditems.Length - 1) Array.Copy(enditems, 0, newlistitems, newlistitems.Length - enditems.Length, enditems.Length) End Sub Private Sub SaveGcode() RemoveSeparator() If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Try System.IO.File.WriteAllLines(SaveFileDialog1.FileName, newlistitems) Catch ex As Exception MessageBox.Show("problème de sauvegarde") End Try End If End Sub Private Sub RemoveSeparator() Dim iter As Integer Dim indextemplistitem As Integer Dim templistitem() As String ReDim templistitem(0) indextemplistitem = 0 For iter = 0 To newlistitems.Length - 1 If Not vectseparator.Contains(iter) Then ReDim Preserve templistitem(indextemplistitem) templistitem(indextemplistitem) = newlistitems(iter) indextemplistitem += 1 End If Next ReDim newlistitems(templistitem.Length - 1) Array.Copy(templistitem, newlistitems, templistitem.Length) End Sub Private Sub GcodeIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileGcodeName.Click Save.Enabled = False If OpenFileDialog1.ShowDialog() = DialogResult.OK Then readfile() End If End Sub Private Sub Formcnc_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load With FileGcodeName .Left = Me.Width / 2 - FileGcodeName.Width / 2 .Top = Me.Top + FileGcodeName.Height End With With proceed .Enabled = False .Left = Me.Width / 2 - proceed.Width / 2 .Top = FileGcodeName.Bottom + 2 End With With Save .Enabled = False .Left = Me.Width / 2 - Save.Width / 2 .Top = proceed.Bottom + 2 End With With Codein .Visible = True .Left = Me.Location.X + 6 .Top = FileGcodeName.Top .Width = Me.Width / 2 - 3 * FileGcodeName.Width / 4 .Height = Me.Height - FileGcodeName.Height * 2 End With With codeout .Left = FileGcodeName.Right + 3 .Top = FileGcodeName.Top .Width = Me.Width / 2 - 3 * FileGcodeName.Width / 4 .Height = Me.Height - FileGcodeName.Height * 2 codeout.Visible = False End With End Sub Private Sub proceed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles proceed.Click SearchEndCode() CreateZvector() GroupGoZ() codeout.Visible = True codeout.Items.Clear() codeout.Items.AddRange(newlistitems) proceed.Enabled = False Save.Enabled = True End Sub Private Sub Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save.Click SaveGcode() End Sub End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class Formcnc Dim listitems() As String Dim enditems() As String Dim vectorZn() As Double Dim vectseparator() As Integer Dim newlistitems() As String Private Sub readfile() Try listitems = System.IO.File.ReadAllLines(OpenFileDialog1.FileName) Codein.Items.Clear() Codein.Items.AddRange(listitems) proceed.Enabled = True Catch ex As Exception MessageBox.Show("fichier introuvable") End End Try End Sub Private Sub SearchEndCode() Dim array1() As String Dim iter As Integer iter = listitems.Length - 1 Do Until listitems(iter).IndexOf("G0 Z") >= 0 iter -= 1 Loop ReDim enditems(listitems.Length - 1 - iter) Array.Copy(listitems, iter, enditems, 0, listitems.Length - iter) ReDim array1(iter - 1) Array.Copy(listitems, 0, array1, 0, array1.Length) ReDim listitems(array1.Length - 1) Array.Copy(array1, listitems, array1.Length) End Sub Private Function GetdecimalSeparator() As Char Dim sp As String sp = 1 / 2 Return (sp.Substring(1, 1)) End Function Private Sub CreateZvector() 'vectorZn contient tous les cotes des GO Z Dim sp As Char Dim zn As Double Dim iterzn As Integer Dim iter As Long Dim iternewlist As Long sp = GetdecimalSeparator() iternewlist = 0 iterzn = 0 ReDim vectorZn(iterzn) For iter = 0 To listitems.Length - 1 If listitems(iter).IndexOf("G0 Z") >= 0 Then If sp <> "." Then listitems(iter) = listitems(iter).Replace(".", sp) End If 'zn le nombre du Go Z Try zn = Double.Parse(listitems(iter).Substring("G0 Z".Length)) If Not vectorZn.Contains(zn) Then ReDim Preserve vectorZn(iterzn) vectorZn(iterzn) = zn iterzn += 1 End If Catch ex As Exception MessageBox.Show("ERROR CODE G0") End End Try End If Next Array.Sort(vectorZn) End Sub Private Sub GroupGoZ() Dim iterz As Integer Dim iterlist As Integer Dim itergroup As Integer Dim start As Integer Dim countseparator As Integer Dim flagfirst As Boolean Dim str As String Dim sp As Char sp = GetdecimalSeparator() flagfirst = False countseparator = 0 For iterz = 0 To vectorZn.Length - 1 If Math.Truncate(vectorZn(iterz)) - vectorZn(iterz) = 0 Then str = "G0 Z" & vectorZn(iterz).ToString("#0.0") Else str = "G0 Z" & vectorZn(iterz).ToString() End If start = 0 iterlist = 0 Do Until iterlist > listitems.Length - 1 If listitems(iterlist).IndexOf(str) >= 0 Then If Not flagfirst Then ReDim Preserve newlistitems(iterlist + 1) System.Array.Copy(listitems, newlistitems, iterlist) flagfirst = True newlistitems(iterlist) = "*".PadLeft(60, "*") ReDim Preserve vectseparator(countseparator) vectseparator(countseparator) = iterlist listitems(iterlist) = listitems(iterlist).Replace(sp, ".") newlistitems(iterlist + 1) = listitems(iterlist) End If itergroup = iterlist + 1 listitems(iterlist) = listitems(iterlist).Replace(sp, ".") newlistitems(newlistitems.Length - 1) = listitems(iterlist) Do While listitems(itergroup).IndexOf("G0 Z") < 0 ReDim Preserve newlistitems(newlistitems.Length) newlistitems(newlistitems.Length - 1) = listitems(itergroup) itergroup += 1 If itergroup = listitems.Length Then Exit Do End If Loop ReDim Preserve newlistitems(newlistitems.Length) countseparator += 1 ReDim Preserve vectseparator(countseparator) vectseparator(countseparator) = newlistitems.Length - 1 newlistitems(newlistitems.Length - 1) = "-".PadLeft(60, "-") iterlist = itergroup ReDim Preserve newlistitems(newlistitems.Length) End If iterlist += 1 Loop Next ReDim Preserve newlistitems(newlistitems.Length - 1 + enditems.Length - 1) Array.Copy(enditems, 0, newlistitems, newlistitems.Length - enditems.Length, enditems.Length) End Sub Private Sub SaveGcode() RemoveSeparator() If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Try System.IO.File.WriteAllLines(SaveFileDialog1.FileName, newlistitems) Catch ex As Exception MessageBox.Show("problème de sauvegarde") End Try End If End Sub Private Sub RemoveSeparator() Dim iter As Integer Dim indextemplistitem As Integer Dim templistitem() As String ReDim templistitem(0) indextemplistitem = 0 For iter = 0 To newlistitems.Length - 1 If Not vectseparator.Contains(iter) Then ReDim Preserve templistitem(indextemplistitem) templistitem(indextemplistitem) = newlistitems(iter) indextemplistitem += 1 End If Next ReDim newlistitems(templistitem.Length - 1) Array.Copy(templistitem, newlistitems, templistitem.Length) End Sub Private Sub GcodeIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileGcodeName.Click Save.Enabled = False If OpenFileDialog1.ShowDialog() = DialogResult.OK Then readfile() End If End Sub Private Sub Design() With Codein .Visible = True .Left = Me.Width / 2 - (Codein.Width + codeout.Width + FileGcodeName.Width + 6) / 2 .Top = 6 .Width = Me.Width / 2 - 3 * FileGcodeName.Width / 4 .Height = Me.Height - FileGcodeName.Height * 2 End With With FileGcodeName .Left = Codein.Right + 3 .Top = 6 End With With proceed .Left = Codein.Right + 3 .Top = FileGcodeName.Bottom + 2 End With With Save .Left = Codein.Right + 3 .Top = proceed.Bottom + 2 End With With codeout .Left = FileGcodeName.Right + 3 .Top = 6 .Width = Me.Width / 2 - 3 * FileGcodeName.Width / 4 .Height = Me.Height - FileGcodeName.Height * 2 End With End Sub Private Sub Formcnc_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Design() proceed.Enabled = False Save.Enabled = False codeout.Visible = False End Sub Private Sub proceed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles proceed.Click SearchEndCode() CreateZvector() GroupGoZ() codeout.Visible = True codeout.Items.Clear() codeout.Items.AddRange(newlistitems) proceed.Enabled = False Save.Enabled = True End Sub Private Sub Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save.Click SaveGcode() End Sub Private Sub Formcnc_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize, Codein.Resize, codeout.Resize, FileGcodeName.Resize, proceed.Resize, Save.Resize Design() End Sub End Class
Là je me rend compte que dans la première tranche on trouve un petit groupe d'instructions qui ne se retrouvent pas dans la suite du g-code :
J'espère que je ne t'ai pas trop saoulé...
mieux pour automatiser l'insertion des instructions