Hello Guest it is May 11, 2021, 10:10:42 PM

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

0 Members and 1 Guest are viewing this topic.

Offline TPS

*
  •  2,129 2,129
    • View Profile
Re: G49 on Mach3 Mill
« Reply #30 on: February 05, 2018, 09:39:07 AM »
ok next Version witch has got a "better" file open Dialog box:

Code: [Select]
Sub Main()

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.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 Exit Sub

'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)

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

'seperate filename and extension
blancfilename = Mid(myfilename,1,last-1)
extension = Mid(myfilename,last,Len(FileName)-last)

'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\" + blancfilename + "_filtered" + extension 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.

LoadFile( "C:\Mach3\GCode\" + blancfilename + "_filtered" + extension)

End Sub




if this code is causing error's please run this code once in VB scripter window to Register MSComDlg.CommonDialog :

Code: [Select]
   Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
    objRegistry.CreateKey &H80000001, "Software\CLASSES\Licenses\4D553650-6ABE-11cf-8ADB-00AA00C00905"
    objRegistry.SetStringValue &H80000001, "Software\CLASSES\Licenses\4D553650-6ABE-11cf-8ADB-00AA00C00905


Thomas,
who never thought a simple open file Dialog will drive him crazy.

« Last Edit: February 05, 2018, 09:41:23 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
    • DD Metal Products Ltd
Re: G49 on Mach3 Mill
« Reply #31 on: February 05, 2018, 09:51:10 AM »
Now, that is outstanding :)

Nicely done.

Ok, so next mini-bug fix is to make the import/load skip straight to the LoadFile part IF the file selected already has "_filtered" in the name - what happens is, next time it is loaded, you get "_filtered_filtered"  and so on :)

Looking damn good though, many thanks.
Bridgeport Mill, Mach3 V062, CSMIO-IP/A controller, AC Servo Drives.
Plasma table, Mach3 V062, Step motors, C&CNC THC.

Offline TPS

*
  •  2,129 2,129
    • View Profile
Re: G49 on Mach3 Mill
« Reply #32 on: February 05, 2018, 10:15:04 AM »
here we go:

file is stored in c:\mach3\gcode with original filename

Code: [Select]
Sub Main()

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.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 Exit Sub

'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)

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

'seperate filename and extension
blancfilename = Mid(myfilename,1,last-1)
extension = Mid(myfilename,last,Len(FileName)-last)

'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"
destfile  = "C:\Mach3\GCode\" + myfilename

FileCopy SourceFile, destfile ' Copy source to target.
Kill SourceFile
LoadFile( "C:\Mach3\GCode\" + myfilename)

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
    • DD Metal Products Ltd
Re: G49 on Mach3 Mill
« Reply #33 on: February 05, 2018, 10:53:32 AM »
Very nicely done :)
Much appreciated BTW


Can you go a step further ? :)

Add in a "save as" dialogue box so we can choose to put file anywhere - some of my jobs consist of multiple files within a job folder, cant have them piled into Code folder alone :)

Bridgeport Mill, Mach3 V062, CSMIO-IP/A controller, AC Servo Drives.
Plasma table, Mach3 V062, Step motors, C&CNC THC.

Offline TPS

*
  •  2,129 2,129
    • View Profile
Re: G49 on Mach3 Mill
« Reply #34 on: February 05, 2018, 11:39:23 AM »
ok, everything selectable by dialogbox

Code: [Select]
Sub Main()
'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.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



'get the destination folder
Dim destfolder As String
Dim destfile As String

    Dialog1.DialogTitle = "select destination folder and filename"

    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

destfolder = CurDir
destfile = Dialog1.FileName

If Len(FileName) = 0 Then Exit Sub
If Len(destfolder) = 0 Then Exit Sub
If Len(destfile) = 0 Then Exit Sub

'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)

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
    • DD Metal Products Ltd
Re: G49 on Mach3 Mill
« Reply #35 on: February 05, 2018, 12:41:59 PM »
WOW, now that is getting slick ;)

Nicely done there.


Without taking the P which is totally not my intention, can i suggest a luxury add-on, only if it is possible of course?...

Is there a way that when you set the file dialogues, it sets a variable that would remember the path to each dialogue chosen so on the next file it opens in that directory?

Purely a luxury and i know how dodgy variables are in Mach but... ;)




One other tiny little thing - when in the file dialogues if you press "cancel", make it abort the whole loop. ;)
Bridgeport Mill, Mach3 V062, CSMIO-IP/A controller, AC Servo Drives.
Plasma table, Mach3 V062, Step motors, C&CNC THC.

Offline TPS

*
  •  2,129 2,129
    • View Profile
Re: G49 on Mach3 Mill
« Reply #36 on: February 05, 2018, 01:19:16 PM »
have you used any UserLabel's ?
if yes, witch ?
probably i can use two free ones to store the last pathe's in.
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline TPS

*
  •  2,129 2,129
    • View Profile
Re: G49 on Mach3 Mill
« Reply #37 on: February 05, 2018, 01:30:06 PM »
ok here is the Version with pathes remembered and Abort on the wright place

used Userlabel 200 and 201 just Change if allready in use

Code: [Select]
Sub Main()
'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"
    '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)

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
    • DD Metal Products Ltd
Re: G49 on Mach3 Mill
« Reply #38 on: February 05, 2018, 01:52:14 PM »
Persistent file dialogues look good, however the cancel buttons appear to have the same effect as the ok buttons ;)


Getting there though :)
Bridgeport Mill, Mach3 V062, CSMIO-IP/A controller, AC Servo Drives.
Plasma table, Mach3 V062, Step motors, C&CNC THC.

Offline TPS

*
  •  2,129 2,129
    • View Profile
Re: G49 on Mach3 Mill
« Reply #39 on: February 05, 2018, 02:26:14 PM »
--> cancel buttons appear to have the same effect as the ok buttons Wink

that is a "side" effect from --> Persistent file dialogues

because the Dialog1.FileName has now allready a value in.

i will have a look tomorrow, how to get the value out witch button was pressed.
 
Thomas

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