Hello Guest it is March 19, 2024, 04:47:56 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - TPS

2081
General Mach Discussion / Re: G49 on Mach3 Mill
« 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.

2082
General Mach Discussion / Re: G49 on Mach3 Mill
« 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




2083
General Mach Discussion / Re: G49 on Mach3 Mill
« 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



2084
General Mach Discussion / Re: G49 on Mach3 Mill
« 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


2085
General Mach Discussion / Re: G49 on Mach3 Mill
« 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


2086
General Mach Discussion / Re: G49 on Mach3 Mill
« 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



2087
General Mach Discussion / Re: G49 on Mach3 Mill
« 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.

2088
VB and the development of wizards / file open/save dialog box in Win7 64bit
« on: February 05, 2018, 11:59:45 AM »
after spending o couple of hour's to get a file open/save Dialog working on win7 64bit,
i post the code here in case somebody else is searching for the same Problem

Code: [Select]

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



change the variable "save", to get either a open or save Dialog

if the code causes a error run this code

Code: [Select]
'Make the MSComDlg.CommonDialog class available for use. Required for filedialog function.
function registerComDlg
    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", "", "gfjmrfkfifkmkfffrlmmgmhmnlulkmfmqkqj"
end function


in vb scripter window once to registrate MSComDlg.CommonDialog on your System

Thomas


2089
General Mach Discussion / Re: G49 on Mach3 Mill
« 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



2090
General Mach Discussion / Re: G49 on Mach3 Mill
« 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