Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: Davek0974 on January 28, 2018, 11:11:42 AM

Title: G49 on Mach3 Mill
Post by: Davek0974 on January 28, 2018, 11:11:42 AM
Just a quickie - if i have a file with G49 at the start does Mach then ignore all G43 Hxx calls?

I am now passing all tool length compensation to the knee on my mill, any G43 Hxx will cause a crash.

I could edit the post but I thought it safer to maybe add G49 to my Mach INIT line in general config
Title: Re: G49 on Mach3 Mill
Post by: TOTALLYRC on January 28, 2018, 05:32:48 PM
I think the G49 just cancels the offset until the next G43 is used.


Mike
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on January 29, 2018, 02:21:33 AM
Ah, that won't work then, looking for a global G43 killer :)
Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 02, 2018, 04:54:53 PM
I can't give you a global G43 killer, but there is another way. There usually is.
You can set tool n offsets all to 0 using G10 L1 Pn X0 Z0 A0.
Create a little do loop to cycle n from 0 to 255 to clear all tools. (I think Tool 0 is always zero anyhow.)

Cheers
Roger
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 02, 2018, 05:05:38 PM
Hmm that G10 looks powerful ;)

Maybe not what i want though - I do need the tool offset as i pass it to the knee axis, what i dont want is any G43 Hnn input coming from the Gcode.
Title: Re: G49 on Mach3 Mill
Post by: TOTALLYRC on February 02, 2018, 05:50:00 PM
The best way is to just modify your post processor. Possible someone out there knows how to prevent the G43 from becoming active even if it creeps into your code.

Mike
Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 02, 2018, 06:00:05 PM
Um. In that case I don't think I understand exactly what it is you want.
Forgive me, but I am not sure you have adequately defined what YOU want either. The tool offsets will control the Z axis which has the spindle mounted on it, but if you also have a 'knee axis', then in practice that is separate from the Z or spindle axis.

If you want to make complex decisions about whether the required vertical movement can be handled by the Z/spindle axis, or whether you will ALSO need to move the knee up/down to get within range - that is going to require a rather complex macro. This macro may end up setting a tool offset to handle the movement of the knee.

Or am I way off target again?

Cheers
Roger
Title: Re: G49 on Mach3 Mill
Post by: TPS on February 03, 2018, 02:58:43 AM
maybe a way to put a macro "behind" the LOAD FILE button,
witch elemenates the G43 ?
Thomas
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 03, 2018, 02:59:50 AM
Its a good one ;)

When i or the code calls M6 Txx my setup reads the tool length parameter direct from the TT and sends it to the knee axis C, the G43 Hxx is totally unwanted and would be naughty if it was used as it would send TLC to the Z axis too - a double whammy.

I modded my F360 post to output H0 as that is the same as not being there so i read. However i also use Sheetcam and Vectric Aspire, but these are also used on other setups so i dont really want to go pulling the posts apart or having to switch posts etc.

Making Mach ignore a G43 seemed the safest way but maybe cannot be done.


Another builder added a custom M843 Hxx call that bypassed the G43 Hxx call but this still needs custom posts etc and you could not use the MDI to call a tool whereas I can as its all handled inside M6Start and M6End

Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 03, 2018, 03:00:43 AM
maybe a way to put a macro "behind" the LOAD FILE button,
witch elemenates the G43 ?
Thomas

Yes, that would be a good way to totally eradicate the risk. But at present I'm not sure how that would scan and alter etc
Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 03, 2018, 05:01:30 AM
Ah so. I see.

You could write a small VB program to read your file in and write it back out again, skipping every G43 found along the way.
I will assume that any g43 instruction will appear as G43 H~, so you would really have to find "G43 H" and any following number.
Fairly mechanical in use. Testing to be done with a large block of foam.

Cheers
Roger
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 03, 2018, 05:54:00 AM
My post seems to go G43 Zfeed start height Hnn

IIRC there needs to be an axis call on the G43 line, maybe wrong though, either way it works fine with the G43's deleted.
Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 03, 2018, 03:49:17 PM
Hi Dave
With all due respect to whoever wrote your postP, writing G43 Zfeed start height Hnn is just plain obscure.
I know some manuals pack up instructions from different groups - maybe to reduce the number of lines in the program, but today there is no justification for that. The Haas manual uses G43 H01 Z0.1 M08 (M08 = coolant on) as an example, but it is not clear whether the Zn is applied before or after the G43 H01 is applied.

Well, you could just filter out the entire G43 line and optionally leave the Z bit in.

Cheers
Roger
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 03, 2018, 04:15:32 PM
It was the original post that comes with F360, no idea of author ;)

Looks like this...
Code: [Select]
(T3  D=6. CR=0. TAPER=90DEG - ZMIN=-2. - CENTER DRILL)
(T6  D=12. CR=0. - ZMIN=-2.5 - FLAT END MILL)
(T8  D=8.1 CR=0. TAPER=118DEG - ZMIN=-10. - DRILL)
(T10  D=6.1 CR=0. TAPER=118DEG - ZMIN=-10. - DRILL)
(T15  D=10. CR=0. TAPER=45DEG - ZMIN=-2. - CHAMFER MILL)
(T98  D=6. CR=0. - ZMIN=-10. - RIGHT HAND TAP)
N10 G90 G94 G91.1 G40 G49 G17
N15 G21
N20 G53 G0 Z0.
N25 G90

(DRILL1)
N30 M5
N35 M9
N40 T3 M6
N45 S3000 M3
N50 G54
N55 M7
N65 G0 X6.259 Y43.837
N70 G43 Z25. H0
N80 Z5.
N85 G98 G81 X6.259 Y43.837 Z-2. R5. F535.

It's always followed by another Z call so the one on the G43 line is always not needed and it runs fine if i just delete those lines.

I could build a small VB6 app that scans and deletes or maybe one that copies all the g-code from my transport USB stick to the hard drive and  at the same time filters them, wouldn't be hard.

Wouldn't know how to build the code into the "File Open" function though :)

And this is the Vectric Aspire Post....
Code: [Select]
(Toolpaths used in this file:)
(Slots)
(Profile 1)
(Tools used in this file: )
(1 = T1 - 2mm Carbide YG)
N110 G00 G21 G17 G90 G40 G49 G80
N120 G71 G91.1
N130 T1 M06
N140 (T1 - 2mm Carbide YG)
N150 G00 G43 Z23.000 H1
N160 G00 Z23.000
N170 S23200 M03
N180 M07
N190 (Toolpath:- Slots)
Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 03, 2018, 06:02:56 PM
I doubt it can be put into 'File Open' in Mach3: the hooks are not there.
VB is probably the way to go. I have done that before to filter stuff out of a file produced by LazyCam.

I note you point that the G43 is followed by the same move command on the next line. I suspect the author of the post did not know what to do there either! The Haas manual includes a Z~ but does NOT explain it adequately; the Mach3 manual omits the Z~ from the G43 line. Me, I strongly favour simple program lines - partly because of my programming style.

Cheers
Roger
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 04, 2018, 03:02:00 AM
Yes, i might write a little import app to filter it out.

I am sure i read somewhere that Mach ignored the G43 line unless there was an axis move in the same block.
Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 04, 2018, 03:25:35 AM
Mach ignored the G43 line unless there was an axis move in the same block
I haven't seen anything like that, but I miss things. If you ever find the source, please post it.
I can't find it in the Mach3Mill_1.84 manual though.
But then ... there are more than a few things missing! For instance, don't try creating a macro with the name M60.

Cheers
Roger
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 04, 2018, 03:31:46 AM
LOL, thats like saying "try creating a macro called M60 ...." :) :)


I'll try find it again but then i tend to read so much it might even have been in a manual for Fadal, Haas, who knows :)

It cant just be a spoof memory though as both the posts I use mainly have the Z move in the G43 line followed by another Z move.

I might try sheet-cam later on, i only use that on the plasma so no tools anyway but it has a Mach post IIRC.
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 04, 2018, 03:54:49 AM
Does seem pretty common, here's a link to some Fanuc shortcodes...
http://www.mmattera.com/g-code/gcodes.html

It lists an axis move on all compensation moves.
Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 04, 2018, 03:57:39 AM
both the posts I use mainly have the Z move in the G43 line followed by another Z move.
Could be copied from the Haas/Fanuc manual - as you have noted.

I spent two days trying to get my M60 macro to work, but it kept coming up with a weird error msg. I changed the name to M70 and it worked immediately. I think there may be something in the archive here about M60 as well. I suspect 'they' reserved it but never got the code (in Mach3) finished.

Cheers
Roger
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 04, 2018, 10:20:18 AM
Ok, sorted.

Simple little VB6 app created that i can run on the mill, it will read the files from the USB stick, comment out and G43/G44 lines and output the files to the hard drive ready to run.

:)
Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 04, 2018, 03:13:30 PM
Chips!
Title: Re: G49 on Mach3 Mill
Post by: TPS on February 05, 2018, 05:57:11 AM
ok here is my Little solution to run in a button script:

Code: [Select]
Sub Main()

Set objFiles = CreateObject("Excel.Application")
Dim Filename As String


'set default open file folder
ChDrive "C:"
ChDir   "C:\Mach3\GCode"

FileName = objFiles.Application.GetOpenFilename("GCodeFiles (*.TAP), *.tap")
 
If FileName = "False" 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 hole file
Do While Not EOF(FNumInput)
Line Input #FNumInput, FileData ' Read a line of data.
If InStr(FileData,"G43") = 0 Then
Print #FNumOutput, FileData
Else
Print #FNumOutput, "( " + FileData + " )"
End If
Loop


Close ' Close all open files.

End Sub




it will only work on a machine where Excel is present,
because all my known openfile dialogs (in VBScript) where
not working on a 64bit OS
 
Thomas

so if anybody has a working fileopen Dialog, would be nice to share it.
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 05, 2018, 06:12:19 AM
Well, if that does indeed work (i'll test it this afternoon) it will solve the issue 99%

Its VBA which is the same as VB6 uses so it all makes sense to me, Excel uses VBA thats why it needs to installed but any VB app installer will load the VB runtime which holds the key to VBA.

Very nice.

BTW, I only gave it 99% as each time you load the file it will append more () so third time round it will look like (((G43..........))) etc
That could be fixed though if it runs.

Nice
Title: Re: G49 on Mach3 Mill
Post by: TPS on February 05, 2018, 06:17:52 AM
Little bugfix,  (((G43..........)))  problem:

Code: [Select]

'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


Title: Re: G49 on Mach3 Mill
Post by: TPS on February 05, 2018, 06:30:40 AM
next Little bugfix,

add

Code: [Select]

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


at the end, to load "cleaned" file imediatelly.
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 05, 2018, 08:18:13 AM
Hmm, ok my thoughts on it running using VB6 core did not work, is there a way to make this work if you have no Excel etc installed??
Title: Re: G49 on Mach3 Mill
Post by: TPS on February 05, 2018, 08:19:24 AM
witch os are you running on?
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 05, 2018, 08:20:37 AM
Win7 & XP
Title: Re: G49 on Mach3 Mill
Post by: TPS on February 05, 2018, 08:40:24 AM
this Version should work on every OS:

Code: [Select]

'Gcode Selection Box
Sub GcodeSelect
    Dim MyList()
    Begin Dialog GcodeFileDlg 60, 60, 190, 220, "Gcode file selection", .DlgFunc
        ListBox 10, 10, 150, 180, MyList(), .List1, 2
        CancelButton 42, 198, 40, 12
        OKButton 90, 198, 40, 12   
       End Dialog
   
 Dim frame As GcodeFileDlg
 
    ' Show the GcodeFile dialog
    Dialog frame
End Sub
 
Function DlgFunc( controlID As String, action As Integer, suppValue As Integer)
 
    DlgFunc = 1  ' Keep dialog active
 
    Select Case action
    Case 1 ' Initialize
        temp = Dir( "c:\Mach3\Gcode\*.tap" )
        count = 0 
        While temp <> ""
            count = count + 1
            temp = Dir
        Wend
        Dim x() As String
        ReDim x(count)
        x(0) = Dir( "c:\Mach3\Gcode\*.tap" )
        For i = 1 To count
            x(i) = Dir
        Next i
        DlgListBoxArray "List1", x()
       
    Case 2 ' select
     
        Fname = (DlgText("List1"))
       
        Dim FileName As String
FileName = "c:\Mach3\Gcode\" &Fname
If FileName = "False" 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
     End Select

End Function





Title: Re: G49 on Mach3 Mill
Post by: TPS 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.

Title: Re: G49 on Mach3 Mill
Post by: Davek0974 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.
Title: Re: G49 on Mach3 Mill
Post by: TPS 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
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 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 :)

Title: Re: G49 on Mach3 Mill
Post by: TPS 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


Title: Re: G49 on Mach3 Mill
Post by: Davek0974 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. ;)
Title: Re: G49 on Mach3 Mill
Post by: TPS 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.
Title: Re: G49 on Mach3 Mill
Post by: TPS 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


Title: Re: G49 on Mach3 Mill
Post by: Davek0974 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 :)
Title: Re: G49 on Mach3 Mill
Post by: TPS 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

Title: Re: G49 on Mach3 Mill
Post by: Davek0974 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.
Title: Re: G49 on Mach3 Mill
Post by: TPS 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

Title: Re: G49 on Mach3 Mill
Post by: Davek0974 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.
Title: Re: G49 on Mach3 Mill
Post by: TPS 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


Title: Re: G49 on Mach3 Mill
Post by: Davek0974 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
Title: Re: G49 on Mach3 Mill
Post by: TPS 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



Title: Re: G49 on Mach3 Mill
Post by: Davek0974 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.
Title: Re: G49 on Mach3 Mill
Post by: rcaffin 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
Title: Re: G49 on Mach3 Mill
Post by: TPS 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.
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 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.
Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 06, 2018, 04:28:46 AM
Chuckle. I have forgotten more languages (assembly and high level) than I can remember. In my life I have written major database systems, created database cores, written robots systems with image analysis, debugged compilers and OSs, and generally had a fun time.
Forgive my humour.
Cheers
Roger
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 06, 2018, 04:37:52 AM
100%  :D ;D :D

Give that man an award, i'd buy you a pint TPS but I don't know where you are :)

Works perfectly now, I think cut-n-paste failed before so it was the same code as previous but new one works very slick.


My screen set has a label that shows the file name loaded so i duplicated a bit of code, the end now looks like....

Code: [Select]

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

'extract filename
outfilename = Mid(destfile,last+1,Len(destfile)-last)

SetUserLabel (2,outfilename)

Exit Sub
errhandler:
message "user cancel"

Many thanks for this mammoth effort.
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 06, 2018, 04:39:31 AM
Chuckle. I have forgotten more languages (assembly and high level) than I can remember. In my life I have written major database systems, created database cores, written robots systems with image analysis, debugged compilers and OSs, and generally had a fun time.
Forgive my humour.
Cheers
Roger


I never managed to stray outside office based stuff, invoicing, stock control, SQL databases etc it's been good fun but getting tiresome now when i get called to edit a program i wrote 10 years ago ;)
Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 06, 2018, 04:50:29 AM
Ah, this was in a Gov't research lab working for industry and a bit of moonlighting on the side, then working as an independent research consultant - the latter for double the money with better holidays. It was all fun.
Now I am retired - so I spend 10 hour days programming g-code for a CNC - but it is MY CNC!

Cheers
Roger
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 06, 2018, 04:56:14 AM
:) sounds good
Title: Re: G49 on Mach3 Mill
Post by: TPS on February 06, 2018, 05:53:09 AM
---
If it can take this many cycles to get a FileLoad screen right
---

i'm realy sorry, i needed so much tryes to get it working perfect.

Thomas
Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 06, 2018, 06:14:20 AM
Hi TPS

Don't worry - we can call it dynamic team programming - it is all the rage in DevOps these days (along with 20 other programing methods).
But it does remind me why I avoided getting too far into commercial and web programming. :) :) :)

Cheers
Roger
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 06, 2018, 06:15:44 AM
I hope that was sarcasm there Thomas  :)

You have nothing to apologise for, it is a damn fine bit of code and something that up until a couple of days ago, i would not have thought possible to do.

I think it will have other uses too in the future.,

Thanks again for your sterling efforts :)
Title: Re: G49 on Mach3 Mill
Post by: Tweakie.CNC on February 06, 2018, 07:15:18 AM
Quote
You have nothing to apologise for, it is a damn fine bit of code

I second that - excellent work Thomas.

Tweakie.
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 06, 2018, 03:12:58 PM
Small glitch on my end - it works fine on my test laptop in Win7 and XP but on the mill (XP) it fails as soon as it requests the MSCOMDLG library.

My guess is that as the mill pc is a cut-down or clean install, there is a file not installed or registered??

Any idea what the .dll i need would be called?

My guess is "Commdlg.dll"

Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 06, 2018, 03:52:52 PM
Yes, CommDlg.dll needs to be installed. It is a well-known omission and there should be any number of sources for it on the web.

Cheers
Roger
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 06, 2018, 03:57:17 PM
Thanks

i'll just copy one from my XP laptop.


:)
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 07, 2018, 06:01:34 AM
Just my luck - its not playing ball at all. :(

Commdlg.dll was already there, tried a quick regsvr32 commdlg.dll  and it says it not an .exe and has no helper program?????

Not too sure what to try next, can't risk upsetting the XP install on the mill but want to use the new code:(

Its XP SP3 on the mill, same as my laptop.

Any other ideas???
Title: Re: G49 on Mach3 Mill
Post by: TPS on February 07, 2018, 06:05:56 AM
have you tryed to run this code (sent this on page 4 of this thread):

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

once in vbscripter window to Register MSComDlg ?
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 07, 2018, 07:12:45 AM
Sadly no, just tried it using the code above and no change, the code above executed ok. :(
Title: Re: G49 on Mach3 Mill
Post by: TPS on February 07, 2018, 07:22:52 AM
have to leave my Office now, come back to you later.

btw, is any error message shown, if your run the code in vbscriper window?
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 07, 2018, 07:26:08 AM
just been googling and it seems the DLL needed is comdlg32.dll not commdlg.dll

I tried this one and got a different message saying the dll was loaded but no registry server entry point was found??

Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 07, 2018, 07:43:58 AM
small progress, i wrote a vb6 app that does nothing but load the common dialog control and installed it.

I now have a working load file screen but it errors on save file dialog ??
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 07, 2018, 08:36:50 AM
Sorted :) :)

After a heavy session on the net, it seems its a license thing with the comdlg32.dll.

Easy way to fix was to install a tiny Microsoft app called "HTML Help Workshop", you can uninstall afterwards if wanted but its so small i just left it.

Dialog works perfectly now.

Thanks
Title: Re: G49 on Mach3 Mill
Post by: TPS on February 07, 2018, 09:49:31 AM
glad to hear, that it's working now.

i never understood all this ddl and ocx confusion in window's,
but i know that is based on my unavalible knowledge about
this stuff.
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 12, 2018, 03:50:05 PM
Back again :)

Not related to G49 but to the code used here.

I'm looking to try drag engraving, so i need the spindle off.

Fusion can't post with a zero spindle speed, it faults and aborts.

So, my thought is to set a speed of 1rpm in Fusion - the mill cannot do this.

Then edit the file load script a little to search this time for "S1 M3" and comment that out.

Does that sound workable - there is no way a proper job can be loaded to run at 1rpm so that should be ok, I also cannot think of any other time that "S1 M3" would appear in code???

Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 12, 2018, 04:11:03 PM
Sounds good to me. Edit and delete would be fine too.
Bit poor about Fusion though.

Cheers
Title: Re: G49 on Mach3 Mill
Post by: Davek0974 on February 12, 2018, 04:14:54 PM
Yes, there are a lot asking for fusion to do static spindle posting, may come one day.

Are drag engravers any good?
Never used one :)
Title: Re: G49 on Mach3 Mill
Post by: rcaffin on February 12, 2018, 04:19:06 PM
I tried using an MYOG drag engraver once, but the tip snapped off. I was probably mis-using it.

Cheers
Roger