1
VB and the development of wizards / Re: scripted email notification
« on: June 11, 2015, 12:43:06 AM »
Sorry to dig up an old thread - but can someone explain how to do this a bit more thoroughly?
Thanks!
Thanks!
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.
OldTool = GetCurrentTool() 'Get tool # That is in the spindle
Tool = GetSelectedTool() 'Get Tool# of the New tool
If Tool <99 Then
If OldTool >99 Then
MsgBox ("Need to Dock and Retract") 'Add code to go to the aux z-axis dock and restract it.
End If
Code "G53 G0 X" & TCX & " Y" & TCY
While IsMoving()
Wend
MsgBox "CHANGE to TOOL #" & tool &" then press OK", 0, "Change Tool"
SetCurrentTool( tool )
Call End1()
Else
If OldTool <100 Then
MsgBox ("Need to Dock and lower") 'Add code to go to the aux z-axis dock and lower it.
End If
Select Case Tool
case 100
Message"Tool Changed to Black Marker" 'Will Run Code for Black Marker
Call End1() 'Calls old m6end macro - now a subroutine
case 101
Message"Tool Changed to Red Marker" 'Will Run Code for Red Marker
Call End1() 'Calls old m6end macro - now a subroutine
case 102
Message"Tool Changed to Blue Marker" 'Will Run Code for Blue Marker
Call End1() 'Calls old m6end macro - now a subroutine
End Select
End If
SetCurrentTool( tool )
Sub Main()
Dim XScale, YScale, ZScale
Dim ZClear, Zoffset, ZClearMach
Dim ClearAllow
Dim Response
If GetOEMLED(1866) Then Exit Sub
If GetOEMLED(801) Then ' On = English Measure INCH
ClearAllow = 0.125 ' Max Z Travel = .125in below Machine Z zero
Else ' Off = Metric Measure MM
ClearAllow = 2.0 ' Max Z Travel = 2mm below Machine Z zero
End If
Zclear = GetOEMDRO(1814) ' Get Z Clearance Plane from DRO
Zoffset = GetOEMDRO(49)
ZClearMach = Zoffset + Zclear
CurrentAbsInc = GetOemLED(48) ' Get the current G90/G91 state
'Get Axis Scale factors
XScale = GetOEMDRO(59)
YScale = GetOEMDRO(60)
ZScale = GetOEMDRO(61)
'Set All Axis' Scale to 1
Call SetOEMDRO(59,1)
Call SetOEMDRO(60,1)
Call SetOEMDRO(61,1)
Sleep(250)
tool = GetSelectedTool()
SetCurrentTool( tool )
SetVar(1, GetOEMDRO(800))
SetVar(2, GetOEMDRO(801))
SetVar(3, GetOEMDRO(802))
TCX=GetOEMDRO(1200)
TCY=GetOEMDRO(1201)
TCZ=GetOEMDRO(1202)
If TCZ>0 Then
MsgBox "Tool Change Z Position" & (Chr(13)) & "can NOT be above Z=0"& (Chr(13)) & "System going in to E-Stop",16,"Tool Change Z Position Error!!!!!"
'Reset Scale before E-Stop
Call SetOEMDRO(59,XScale)
Call SetOEMDRO(60,YScale)
Call SetOEMDRO(61,ZScale)
Sleep(250)
DoOEMButton(1021) ' Put Mach3 in Reset to end Tool Change
Exit Sub 'ERROR! exit the macro
End If
If ZClearMach>0 Then
Response = MsgBox ("Warning !!!" & (Chr(13)) & "Z Clearance Plane is Above Z Axis Home Switch." & (Chr(13)) & "Press OK To Retract Safely Below Switch" & (Chr(13)) & "Or Press Cancel for E-Stop",49,"Insufficient Z Clearance!!")
If Response = 1 Then ' If OK
ZClearMach = 0 - ClearAllow ' Retract to Z Machine zero - .125in or 2mm
ElseIf Response = 2 Then ' If Cancel
'Reset Scale before E-Stop
Call SetOEMDRO(59,XScale)
Call SetOEMDRO(60,YScale)
Call SetOEMDRO(61,ZScale)
Sleep(250)
DoOEMButton(1021) ' Put Mach3 in Reset to end Tool Change
Exit Sub
End If
End If
Code "G90"
If ZClearMach > TCZ Then
Code "G53 G0 Z" & ZClearMach
While IsMoving()
Wend
Else
Code "G53 G0 Z" & TCZ
While IsMoving()
Wend
End If
Code "G53 G0 X" & TCX & " Y" & TCY
While IsMoving()
Wend
If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
End If
Call SetOEMDRO(59,XScale)
Call SetOEMDRO(60,YScale)
Call SetOEMDRO(61,ZScale)
Sleep(250)
End Sub
Sub Main()
' Based on the macros written by Big-Tex November 29 2010
' and modified by Poppa Bear, with Greolt's and Arbo's changes 08Dec2010
If GetOEMLED(1866) Then Exit Sub
Dim XWork, YWork, ZWork, XMachine, YMachine, ZMachine
Dim XScale, YScale, ZScale
Dim ZNew, ZPlate, Zplatetomaterial
Dim TCZ
Dim XPlate, YPlate
Dim ZClear, ClearAllow, ZMaxRetract
Dim FirstProbeDist, FirstRetractDist, SecProbeDist
Dim CurrentFeed
Dim CurrentAbsInc
Dim Response, CurrUnit
TCZ=GetOEMDRO(1202)
XWork = GetOEMDRO(800) ' Get current X Work Coordinate
YWork = GetOEMDRO(801) ' Get current Y Work Coordinate
ZWork = GetOEMDRO(802) ' Get current Z Work Coordinate
XMachine = GetOemDRO(83) ' Get current X Machine Coordinate
YMachine = GetOemDRO(84) ' Get current Y Machine Coordinate
ZMachine = GetOemDRO(85) ' Get current Z Machine Coordinate
XPlate = GetUserDRO(1811) ' Get X Machine Coordinate of Fixed Plate
YPlate = GetUserDRO(1812) ' Get Y Machine Coordinate of Fixed Plate
CurrentFeed = GetOemDro(818) ' Get Current Feed Rate
Zplatetomaterial = GetUserDRO(1813) ' Get calculated material offset
ZClear = GetOEMDRO(1814) ' Get Z Clearance Plane
CurrentAbsInc = GetOemLED(48) ' Get the current G90/G91 state
'Get Axis Scale factors
XScale = GetOEMDRO(59)
YScale = GetOEMDRO(60)
ZScale = GetOEMDRO(61)
'Set All Axis' Scale to 1
Call SetOEMDRO(59,1)
Call SetOEMDRO(60,1)
Call SetOEMDRO(61,1)
Sleep(250)
'//////// the block below will set all your reusable vars depending on Inch or mm.
'//////// this sets the vars so you only need ONE large block of probing code.
If GetOEMLED(801) Then ' On = English Measure INCH
FirstProbeDist = 6.0 ' Probe Down 6 inches
FirstRetractDist = 0.05 ' Then Retract .05 inches
SecProbeDist = 0.25 ' Then Probe down .25 inches
FirstProbeFeed = 10 ' First Probe Feed @ 10 ipm
SecondProbeFeed = 1 'Second Probe Feed @ 1 ipm
ClearAllow = 0.125 ' Max Z Travel = .125in below Machine Z zero
CurrUnit = "inches"
Else ' Off = Metric Measure MM
FirstProbeDist = 150.0 ' Probe Down 150 mm's
FirstRetractDist = 1.0 ' Then Retract 1 mm
SecProbeDist = 6.0 ' Then Probe down 6 mm's
FirstProbeFeed = 250 ' First Probe Feed @ 250mm/min
SecondProbeFeed = 25 ' Second Probe Feed @ 25mm/min
ClearAllow = 2.0 ' Max Z Travel = 2mm below Machine Z zero
CurrUnit = "mm's"
End If
'//////// Error Condition checking code
If GetOemLED(16)<>0 Then 'Checks for machine coordinates
MsgBox "Must be in Working Coordinates - Putting System in Reset",16,"Machine Coordinates!!!!!"
'Reset Scale before E-Stop
Call SetOEMDRO(59,XScale)
Call SetOEMDRO(60,YScale)
Call SetOEMDRO(61,ZScale)
DoOEMButton(1021) ' Put Mach3 in Reset to end Tool Change
Exit Sub 'ERROR! exit the macro
End If
If GetOemLED(825)<>0 Then
MsgBox "Z Plate is Grounded - Putting System in Reset",16,"Plate Grounded Error!!!!!"
'Reset Scale before E-Stop
Call SetOEMDRO(59,XScale)
Call SetOEMDRO(60,YScale)
Call SetOEMDRO(61,ZScale)
DoOEMButton(1021) ' Put Mach3 in Reset to end Tool Change
Exit Sub 'ERROR! exit the macro
End If
If ZClear <=0 Then
'MsgBox "(Clearance Plane Must be > 0 - Putting System in Reset)",16,"Clearance Plane Error!!!!"
'Reset Scale before E-Stop
Call SetOEMDRO(59,XScale)
Call SetOEMDRO(60,YScale)
Call SetOEMDRO(61,ZScale)
'DoOEMButton(1021) ' Put Mach3 in Reset to end Tool Change
'Exit Sub 'ERROR! exit the macro
'End If
Response = MsgBox ("Warning !!!" & (Chr(13)) & "Z Clearance Plane <= 0 !!!" & (Chr(13)) & "Press OK To Set Retract Plane To " & Cstr(ClearAllow) & " " & CurrUnit & (Chr(13)) & "Or Press Cancel for E-Stop",49,"Clearance Plane Less Than Or Equal To Zero!!")
If Response = 1 Then ' If OK
ZClear = ClearAllow ' Retract to .125in or 2mm above fixed plate
ElseIf Response = 2 Then ' If Cancel
'Reset Scale before E-Stop
Call SetOEMDRO(59,XScale)
Call SetOEMDRO(60,YScale)
Call SetOEMDRO(61,ZScale)
Sleep(250)
DoOEMButton(1021) ' Put Mach3 in Reset to end Tool Change
Exit Sub
End If
End If
'//////// Start Probing Code, Probe In -Z direction.
'//////// The vars will be Inch or Metric from above if/else statment
Code "G90" ' Change to Absolute Distance Mode
Sleep(100)
Code "G53 G0 Z" & TCZ ' Move to Tool Change Z Position - Should already be there
While IsMoving()
Wend
Code "G53 G0 X" & XPlate & " Y" & YPlate ' Move to Fixed Plate Location
While IsMoving()
Wend
If GetOemLED(825)<>0 Then
MsgBox "Z Plate is Grounded - Putting System in Reset",16,"Plate Grounded Error!!!!!"
DoOEMButton(1021) ' Put Mach3 in Reset to end Tool Change
Exit Sub 'ERROR! exit the macro
End If
Code "F" & FirstProbeFeed ' Set Feedrate to 10 ipm, or 300 mm/m
Code "(Probing for Z Zero....)"
Zplate = (GetOEMDro(802) - FirstProbeDist) ' Probe move to Current Z - 6in, or 150mm
Code "G90 G31 Z" & Zplate
While IsMoving()
Wend
Zplate = GetVar(2002) ' Read the Touch Point
Code "G1 Z" & (Zplate + FirstRetractDist) ' Move up .05 in, or 1mm in case of overshoot
While IsMoving()
Wend
Code "F" & SecondProbeFeed ' Set Feedrate to 1 ipm, or 25mm/min
Zplate = (GetOEMDro(802)- SecProbeDist) ' Probe move to Current Z - .25in, or 6mm
Code "G90 G31 Z" & Zplate
While IsMoving()
Wend
Call SetOEMDRO(802,Zplatetomaterial) ' Set Z axis DRO to Calculated Offset, making tool tip @ Z=0
Sleep(500) ' Pause for Dro to update
'Make Sure Z Clearance Plane is below Home Switch. If not, Notify User and Proceed.
If GetOEMLED(85) <= Zplatetomaterial + ClearAllow Then
ZMaxRetract = Abs(GetOEMDRO(85) - Zplatetomaterial + ClearAllow)
Else
ZMaxRetract = Abs(GetOEMDRO(85)) + Zplatetomaterial - ClearAllow
End If
If ZClear > ZMaxRetract Then
Response = MsgBox ("Warning !!!" & (Chr(13)) & "Z Clearance Plane is Above Z Axis Home Switch." & (Chr(13)) & "Press OK To Retract Safely Below Switch" & (Chr(13)) & "Or Press Cancel for E-Stop",49,"Insufficient Z Clearance!!")
If Response = 1 Then ' If OK
ZClear = ZMaxRetract ' Retract to Z Machine zero - .125in or 2mm
ElseIf Response = 2 Then ' If Cancel
'Reset Scale before E-Stop
Call SetOEMDRO(59,XScale)
Call SetOEMDRO(60,YScale)
Call SetOEMDRO(61,ZScale)
Sleep(250)
DoOEMButton(1021) ' Put Mach3 in Reset to end Tool Change
Exit Sub
End If
End If
If ZClear <= Zplatetomaterial then 'Plunge into Fixed Plate !!!!
Response = MsgBox ("Warning !!!" & (Chr(13)) & "Z Clearance Plane is Below Fixed Plate!!!" & (Chr(13)) & "Press OK To Retract " & Cstr(ClearAllow) & " " & CurrUnit & (Chr(13)) & "Or Press Cancel for E-Stop",49,"Plunging Into Plate!!")
If Response = 1 Then ' If OK
ZClear = Zplatetomaterial + ClearAllow ' Retract to .125in or 2mm above fixed plate
ElseIf Response = 2 Then ' If Cancel
'Reset Scale before E-Stop
Call SetOEMDRO(59,XScale)
Call SetOEMDRO(60,YScale)
Call SetOEMDRO(61,ZScale)
Sleep(250)
DoOEMButton(1021) ' Put Mach3 in Reset to end Tool Change
Exit Sub
End If
End If
Code "G0 Z" & ZClear 'Retract to Z Clearance Plane
While IsMoving ()
Wend
Code "G0 X" & GetVar(1) & " Y" & GetVar(2) ' Move to Previous Position prior to M6 being called
While IsMoving()
Wend
Code "F" & CurrentFeed ' Reset Feedrate
If GetOEMLED(801) Then 'ON = English Measure INCH
Code "(Z Axis is now Zeroed in Inches)" ' Puts this message in the status bar
Else 'OFF = Metric Measure MM
Code "(Z Axis is now Zeroed in mm's)" ' Puts this message in the status bar
End If
If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
End If
Call SetOEMDRO(59,XScale)
Call SetOEMDRO(60,YScale)
Call SetOEMDRO(61,ZScale)
Sleep(250)
If Not FileName() = "No File Loaded." Then
If GetOEMLED(1865) Then
MsgBox "Start Spindle, then press OK to Continue",48,"Start Spindle"
' g-code should have an M3 after the M6, so the following commented code is not required
'Else
'DoSpinCW()
'While IsMoving()
'Wend
End If
End If
End Sub