Hello Guest it is March 28, 2024, 05:51:41 PM

Author Topic: Button Script to search through active Gcode File for NEXT Tool change  (Read 19130 times)

0 Members and 1 Guest are viewing this topic.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Hi ALL, This is a button script to allow you to search through a loaded Gcode file. It advances to the next M6 it finds in the current file. If no file is loaded then it errors OUT and ends.

(;-)TP

'Macro for  GcodeFile string search
Dim sLine As String
Dim i As Long
Dim lFoundLine As Long

Fname = FileName

If Fname = "No FIle Loaded." Then
MsgBox" There is NO File Currently Loaded in Mach3"
End
Else

Open FIlename For Input As #1

Do Until EOF(1)
  lFoundLine = lFoundLine + 1
  Line Input #1, sLine
  If InStr(1, sLine, "M06") > 0 And lfoundline > GetDro(16) Then
    Exit Do
  End If
Loop
Close #1
Nline = (lfoundline -1)
MsgBox""&Nline
Setdro(16,Nline)
End If
End
Might want to add an alternative or "M6" search also.

You sure are working hard on your Florida winter retreat.
Have fun.

Offline Dan13

*
  •  1,208 1,208
    • View Profile
    • DY Engineering
Hey Terry,

Thanks for the code!

Doing for Turn, what if we OR gated the following in the If statement: "T0" OR "T1" OR "T2". True, not an elegant way, but it will do what's needed. And I don't have tools on the lathe past 29. If I had I could just add another one to the OR: "T3" and so on...

Dan

Offline BR549

*
  •  6,965 6,965
    • View Profile
Good Idea about teh M06 Most use M6 just change out the text to M6

For turn just change out the M6 to the "T" , or  "T?? yes it could pickup the letters in a (message) but just push the button again to advance to the next T??.

Not really a retreat only lived here for 59 years so far(;-)

(;-) TP
Sorry I thought you lived in the northeast

Now that is unless you have messages with a 'T' in the comment.   ;)

« Last Edit: March 10, 2013, 08:25:55 PM by Ya-Nvr-No »

Offline BR549

*
  •  6,965 6,965
    • View Profile
I am working on fixing the "T" deal but I don't have a clue yet as HOW to ignore strings inside the ( ) . Some things are obvious that one is not(;-).

At least to my little pea brain, (;-) TP
Use a flag that when you see a "(" you set the flag to 1 keep searching until you see a")" reset the flag to 0. Than your back to looking for a "T"

Offline BR549

*
  •  6,965 6,965
    • View Profile
(;-) IF you can fix it please DO.  It may take me DAYS to figure out HOW to make it work as I am not a programmer but a code assembler(;-).

There is also another error in the code I just saw.

 If InStr(1, sLine, "M06") > 0 And lfoundline > GetDro(16) Then

Should read as

 If InStr(1, sLine, "M06") > 0 And lfoundline > (GetDro(16)+1) Then

Other wise it will not search beyond the same line number. It just repeats the same line number.

(;-) TP
See... you can do it, you have been a machine at pumping out useful code. Just need to push your talents a little, always been fun for me to learn new things. I think your like that too.
'gives you the idea.


Do Until EOF(1)
  lFoundLine = lFoundLine + 1
  Line Input #1, sLine
  If InStr(1, sLine, "(") > 0 And lfoundline > GetDro(16)+1 Then
    flag=1
  End If
  If flag=0 Then
    If InStr(1, sLine, "T") > 0 And lfoundline > GetDro(16)+1 Then
      Exit Do
     End If
  End If
  flag=0
Loop