Hello Guest it is April 20, 2024, 12:25:40 PM

Author Topic: Mach3 script editor bug?  (Read 7581 times)

0 Members and 1 Guest are viewing this topic.

Re: Mach3 script editor bug?
« Reply #10 on: February 10, 2013, 10:37:50 PM »
I separated the code into subs. This was done because the profile and material is the only part of the project that changes. I plan to make buttons or List box in mach so the profile and material can be changed by the operator.
In the code when if falls out of the first loop CurrentX is set to the finish level. I put this in place to set the last roughing cut right above the finish cuts instead of taking lots of finish cuts. Would you consider this code safe from a infinite loop and less of a mess?


Code: [Select]
ProfileCut "Profile1", "Acrylic", .04, 0, .01, .001, 3, .4

Sub ProfileCut(ByVal ProFileName, ByVal Material, ByVal StartX, ByVal EndX, ByVal RoughingDepth, ByVal FinishDepth, ByVal NumFinishCuts, ByVal SafeX)
  Dim i
  Dim FeedRate
  Dim CurrentX
  CurrentX = StartX
 
  Code "G0 X" & SafeX 'Back away X
  Code "G0 Z.01" 'Back away Z .01
  Code "G0 X" & CurrentX + .01 'Get X close
  FeedRate = MaterialSort(Material) 'Set feedrate based on material

  While ((CurrentX) > (EndX + (FinishDepth * NumFinishCuts))) 'If above finish line
'Print "While " & CurrentX & " > " & (EndX + (FinishDepth * NumFinishCuts))
    ProfileSort ProFileName, CurrentX, FeedRate, SafeX 'Send cut to profile type
'Print "Cut" & CurrentX
    CurrentX = CurrentX - RoughingDepth 'Set next roughing X
  Wend

  CurrentX = EndX + (FinishDepth * NumFinishCuts ) 'Set CurrentX to top of finish cuts after drop
  For i = 1 To (NumFinishCuts + 1) 'Loop finish cuts
    ProfileSort ProFileName, CurrentX, FeedRate, SafeX 'Send cut to profile type
'Print "Cut" & CurrentX
    CurrentX = CurrentX - FinishDepth 'Set next finishing X
  Next I
End Sub

'//Gets Feed rate by material
Function MaterialSort( ByVal Material)
  If Material = "Acrylic" Then MaterialSort = 10
  'Add more materials
End Function

'//Gets Profile
Sub ProfileSort(ByVal ProFileName, CurrentX, FeedRate, ByVal SafeX)
  If ProfileName = "Profile1" Then Profile1 CurrentX, FeedRate, SafeX 'Sort profile
  'Add more sub profiles
End Sub

'//Profile
Sub Profile1(ByVal CurrentX, ByVal FeedRate, ByVal SafeX) 'A profile
  Code "G1 X" & CurrentX + 0.110 & " Z0.00 F" & FeedRate
  Code "G2 X" & CurrentX + 0.190 & " Z-0.075 R-0.066 F" & FeedRate
  Code "G1 X" & CurrentX + 0.130 & " Z-0.600 F" & FeedRate
  Code "G0 X" & SafeX     'Back away X
  Code "G0 Z0.01" 'Back away Y
  Code "G0 X" & CurrentX + .01 'Sets x to the base to save time
End Sub