Hello Guest it is March 28, 2024, 03:46:49 PM

Author Topic: G49 on Mach3 Mill  (Read 11726 times)

0 Members and 1 Guest are viewing this topic.

Offline Davek0974

*
  •  2,606 2,606
    • View Profile
Re: G49 on Mach3 Mill
« Reply #40 on: February 05, 2018, 02:34:16 PM »
Ah, ok.

I'm unsure how the dialogues you are using function, in VB6 they have a return value which is either false if cancel is pressed or contains a string if a target is entered and ok pressed. I also test for null strings incase user presses ok but does not enter a filename.

No worries, its damn good and very tidy, thanks so far for the massive effort.

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: G49 on Mach3 Mill
« Reply #41 on: February 06, 2018, 02:46:47 AM »
next try

Code: [Select]
Sub Main()
On Error GoTo errhandler

'get the source file
Dim Filename As String
Dim Dialog1

    Set Dialog1 = CreateObject("MSComDlg.CommonDialog")
    Dialog1.MaxFileSize = 256
    Dialog1.Filter = "GCode Files (*.tap)|*.tap"
    Dialog1.FilterIndex = 1
    Dialog1.DialogTitle = "select GCode file"
    Dialog1.InitDir = "C:\Mach3\GCode"
    Dialog1.CancelError = True
    'get the last selection
    Dialog1.FileName = GetUserLabel(200)
    save = false
    If save = true Then
        Dialog1.DefaultExt = def
        Dialog1.Flags = &H800 + &H4
        discard = Dialog1.ShowSave()
    Else
        Dialog1.Flags = &H1000 + &H4 + &H800
        discard = Dialog1.ShowOpen()
    End If

FileName = Dialog1.FileName
If Len(FileName) = 0 Then Exit Sub
'store last selection
SetUserLabel(200,FileName)

'get the destination folder
Dim destfile As String

    Dialog1.DialogTitle = "select destination folder and filename"
    'get the last selection
    Dialog1.FileName = GetUserLabel(201)

    save = true
    If save = true Then
        Dialog1.DefaultExt = def
        Dialog1.Flags = &H800 + &H4
        discard = Dialog1.ShowSave()
    Else
        Dialog1.Flags = &H1000 + &H4 + &H800
        discard = Dialog1.ShowOpen()
    End If

destfile = Dialog1.FileName

If Len(destfile) = 0 Then Exit Sub
'store last selection
SetUserLabel(201,destfile)

'open input file
FNumInput    = FreeFile 'Determine next file number.
Open FileName For Input As FNumInput

'open output file
FNumOutput = FreeFile 'Determine next file number.
Open "C:\Mach3\GCode\import.txt" For Output As FNumOutput

'go through To whole file
Do While Not EOF(FNumInput)
Line Input #FNumInput, FileData ' Read a line of data.
If ((InStr(FileData,"G43") <> 0) And (Left(FileData,1) <> "(")) Then
Print #FNumOutput, "( " + FileData + " )"
Else
Print #FNumOutput, FileData
End If
Loop


Close ' Close all open files.
DoOEMButton(169) 'close Mach3 files just in case
SourceFile = "C:\Mach3\GCode\import.txt"

FileCopy SourceFile, destfile ' Copy source to target.
Kill SourceFile
LoadFile( destfile)

errhandler:

End Sub

anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline Davek0974

*
  •  2,606 2,606
    • View Profile
Re: G49 on Mach3 Mill
« Reply #42 on: February 06, 2018, 03:08:18 AM »
Nice one:) Nailed that bit.

Ok, how about this...  ;)

where you have it remembering the file/path that was last loaded, is there a way to make it only remember the actual path not the file?
what happens is, you load the first time and its all 100% but second file load goes to the correct folder but also has the last file name pre-loaded where it should be blank :)

Getting down to the nitty-gritty now :)
Don't forget to add a block of comments at the top showing who developed it and when - its a great bit of code i think.

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: G49 on Mach3 Mill
« Reply #43 on: February 06, 2018, 03:36:27 AM »
next test
Code: [Select]

' ---------------------------------------------------------------------------------
' TPS 02/2018 
' macro to open GCode file and comment out all G43
' ---------------------------------------------------------------------------------
Sub Main()
On Error GoTo errhandler

'get the source file
Dim Filename As String
Dim Dialog1

    Set Dialog1 = CreateObject("MSComDlg.CommonDialog")
    Dialog1.MaxFileSize = 256
    Dialog1.Filter = "GCode Files (*.tap)|*.tap"
    Dialog1.FilterIndex = 1
    Dialog1.DialogTitle = "select GCode file"
    Dialog1.InitDir = "C:\Mach3\GCode"
Dialog1.CancelError = True
    'get the last selection
    Dialog1.FileName = GetUserLabel(200)
    save = false
    If save = true Then
        Dialog1.DefaultExt = def
        Dialog1.Flags = &H800 + &H4
        discard = Dialog1.ShowSave()
    Else
        Dialog1.Flags = &H1000 + &H4 + &H800
        discard = Dialog1.ShowOpen()
    End If

FileName = Dialog1.FileName
If Len(FileName) = 0 Then
message "no source file selected"
Exit Sub
End If
'store last selection
SetUserLabel(200,FileName)

'get the destination folder
Dim destfile As String

    Dialog1.DialogTitle = "select destination folder and filename"
    'get the last selection
    Dialog1.FileName = ""
    Dialog1.InitDir = GetUserLabel(201)

    save = true
    If save = true Then
        Dialog1.DefaultExt = def
        Dialog1.Flags = &H800 + &H4
        discard = Dialog1.ShowSave()
    Else
        Dialog1.Flags = &H1000 + &H4 + &H800
        discard = Dialog1.ShowOpen()
    End If

destfile = Dialog1.FileName

If Len(destfile) = 0 Then
message "no destination file selected"
  Exit Sub
End If
  'store last selection
SetUserLabel(201,CurDir)

'open input file
FNumInput    = FreeFile 'Determine next file number.
Open FileName For Input As FNumInput

'open output file
FNumOutput = FreeFile 'Determine next file number.
Open "C:\Mach3\GCode\import.txt" For Output As FNumOutput

actions = 0
'go through To whole file
Do While Not EOF(FNumInput)
Line Input #FNumInput, FileData ' Read a line of data.
If ((InStr(FileData,"G43") <> 0) And (Left(FileData,1) <> "(")) Then
Print #FNumOutput, "( " + FileData + " )"
actions = actions + 1
Else
Print #FNumOutput, FileData
End If
Loop


Close ' Close all open files.
message CStr(actions) + " G43 have been found"
DoOEMButton(169) 'close Mach3 files just in case
SourceFile = "C:\Mach3\GCode\import.txt"

FileCopy SourceFile, destfile ' Copy source to target.
Kill SourceFile
LoadFile( destfile)
Exit Sub
errhandler:
message "user cancel"
End Sub


anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline Davek0974

*
  •  2,606 2,606
    • View Profile
Re: G49 on Mach3 Mill
« Reply #44 on: February 06, 2018, 03:44:35 AM »
Almost :)

The first dialogue still retains the last file name but the second is blank, I think what it should do is ...

First dialogue = empty but retains path chosen last - ready to select a new file
Second dialogue = Filename chosen in first dialogue but in path selected in second dialogue - usually would save with same name as loaded


dave

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: G49 on Mach3 Mill
« Reply #45 on: February 06, 2018, 03:53:43 AM »
Code: [Select]
' ---------------------------------------------------------------------------------
' TPS 02/2018 
' macro to open GCode file and comment out all G43
' ---------------------------------------------------------------------------------
Sub Main()
On Error GoTo errhandler

'get the source file
Dim Filename As String
Dim Dialog1

    Set Dialog1 = CreateObject("MSComDlg.CommonDialog")
    Dialog1.MaxFileSize = 256
    Dialog1.Filter = "GCode Files (*.tap)|*.tap"
    Dialog1.FilterIndex = 1
    Dialog1.DialogTitle = "select GCode file"
    Dialog1.InitDir = GetUserLabel(200)
    Dialog1.CancelError = True
    'get the last selection
    Dialog1.FileName = ""
    save = false
    If save = true Then
        Dialog1.DefaultExt = def
        Dialog1.Flags = &H800 + &H4
        discard = Dialog1.ShowSave()
    Else
        Dialog1.Flags = &H1000 + &H4 + &H800
        discard = Dialog1.ShowOpen()
    End If

FileName = Dialog1.FileName
If Len(FileName) = 0 Then
message "no source file selected"
Exit Sub
End If
'store last selection
SetUserLabel(200,CurDir)

'find the last "\" in filename
For i = 1 To Len(FileName)
If Mid(FileName,i,1) = "\" Then
last = i
End If
Next i

'extract filename
myfilename = Mid(FileName,last+1,Len(FileName)-last)

'get the destination folder
Dim destfile As String

    Dialog1.DialogTitle = "select destination folder and filename"
    'get the last selection
    Dialog1.FileName = GetUserLabel(201) + "\" + myfilename
    Dialog1.InitDir = GetUserLabel(201)

    save = true
    If save = true Then
        Dialog1.DefaultExt = def
        Dialog1.Flags = &H800 + &H4
        discard = Dialog1.ShowSave()
    Else
        Dialog1.Flags = &H1000 + &H4 + &H800
        discard = Dialog1.ShowOpen()
    End If

destfile = Dialog1.FileName

If Len(destfile) = 0 Then
message "no destination file selected"
  Exit Sub
End If
  'store last selection
SetUserLabel(201,CurDir)

'open input file
FNumInput    = FreeFile 'Determine next file number.
Open FileName For Input As FNumInput

'open output file
FNumOutput = FreeFile 'Determine next file number.
Open "C:\Mach3\GCode\import.txt" For Output As FNumOutput

actions = 0
'go through To whole file
Do While Not EOF(FNumInput)
Line Input #FNumInput, FileData ' Read a line of data.
If ((InStr(FileData,"G43") <> 0) And (Left(FileData,1) <> "(")) Then
Print #FNumOutput, "( " + FileData + " )"
actions = actions + 1
Else
Print #FNumOutput, FileData
End If
Loop


Close ' Close all open files.
message CStr(actions) + " G43 have been found"
DoOEMButton(169) 'close Mach3 files just in case
SourceFile = "C:\Mach3\GCode\import.txt"

FileCopy SourceFile, destfile ' Copy source to target.
Kill SourceFile
LoadFile( destfile)
Exit Sub
errhandler:
message "user cancel"
End Sub



anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline Davek0974

*
  •  2,606 2,606
    • View Profile
Re: G49 on Mach3 Mill
« Reply #46 on: February 06, 2018, 04:04:57 AM »
Aaah nice but,,,

The load is now 100% sensible but Its broken the cancel buttons again :(

Pressing cancel is the same as pressing load.

Offline rcaffin

*
  •  1,052 1,052
    • View Profile
Re: G49 on Mach3 Mill
« Reply #47 on: February 06, 2018, 04:12:26 AM »
Purely as an aside, and said with great humour:
If it can take this many cycles to get a FileLoad screen right, what hope is there for multi-million dollar software projects?
To answer my own Q - about half of them never complete, while most of the rest only deliver a poor fraction of the target.

Keep going guys!

cheers
Roger

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: G49 on Mach3 Mill
« Reply #48 on: February 06, 2018, 04:14:20 AM »
Aaah nice but,,,

The load is now 100% sensible but Its broken the cancel buttons again :(

Pressing cancel is the same as pressing load.

courios not so here, everytime i press the cancel button, script does nothing and
"user cancel" is displayed in Status line ?

maybe you can debug in VB Scripter window.
« Last Edit: February 06, 2018, 04:17:22 AM by TPS »
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline Davek0974

*
  •  2,606 2,606
    • View Profile
Re: G49 on Mach3 Mill
« Reply #49 on: February 06, 2018, 04:24:43 AM »
Purely as an aside, and said with great humour:
If it can take this many cycles to get a FileLoad screen right, what hope is there for multi-million dollar software projects?
To answer my own Q - about half of them never complete, while most of the rest only deliver a poor fraction of the target.

Keep going guys!

cheers
Roger


I've been messing with VB6 apps for many years at work and I can say that this is nothing compared to debugging a major build :)

I think this script might be useful to others down the line and I'm very grateful for TPS putting in so much time on it.