Nice work SBC!
Code:
2005. Program Block 5 - Spiral Script
Dim comboArcSelection
Dim XCURR
Dim YCURR
Dim ZCURR
XCURR = MILL_GetXFeed()
YCURR = MILL_GetYFeed()
ZCURR = MILL_GetZFeed()
Call MILL_SetDoubleMemoryLoc(1,XCURR)
Call MILL_SetDoubleMemoryLoc(2,YCURR)
Call MILL_SetDoubleMemoryLoc(3,ZCURR)
comboArcSelection = MILL_GetUserSelectComboVariable(20) 'Read Spiral Arc combo box; 0 = No arcs, 1 = Arcs CW, 2 = Arcs CCW
Select Case comboArcSelection
Case 0
Call MILL_SetStringMemoryLoc(0,"SPIRALOFF") 'No Spiral arc selected
Case 1
Call MILL_SetStringMemoryLoc(0,"SPIRALON") 'Spiral arc selected,CW
Call MILL_SetStringMemoryLoc(1,"G02")
Case 2
Call MILL_SetStringMemoryLoc(0,"SPIRALON") 'Spiral arc selected,CCW
Call MILL_SetStringMemoryLoc(1,"G03")
Case Else
MsgBox("Unexpected Value for comboArcSelection")
End Select
' MILL_OutputText("(<---DEBUG: XCURR = "&XCURR&" )")
' MILL_OutputText("(<---DEBUG: YCURR = "&YCURR&" )")
' MILL_OutputText("(<---DEBUG: ZCURR = "&ZCURR&" )")
' MILL_OutputText("(<---DEBUG: OffsetAmount = "&setupGetOffsetAmount&" )")
' MILL_OutputText("(<---DEBUG: Arc Radius = "&setupGetArcRadius&" )")
Code:
2007. Program Block 7.
Dim spiralNumTurns
Dim spiralRadius
Dim spiralStartAngle
Dim spiralRampAngle
Dim spiralDirection
Dim ZCurrent
Dim ZPrevious
Dim ZChanged
Dim ZStart
Dim ZEnd
Dim ZStep
Dim XCurrent
Dim YCurrent
Dim Counter
Dim SPIRALONOFF
Dim PI
Dim DEG2RAD
PI = 3.14159265358979
DEG2RAD = PI/180 'Multiplier to convert degrees to Radians
'Read all the Advanced Posting Parameters from the 2D-POCKET feature
spiralNumTurns = MILL_GetUserEditIntegerVariable(14)
spiralRadius = MILL_GetUserEditRealVariable(16)
spiralStartAngle = MILL_GetUserEditIntegerVariable(17)
spiralRampAngle = MILL_GetUserEditRealVariable(18)
spiralDirection = MILL_GetStringMemoryLoc(1)
'The script runs after all the BobCAD generated code for the spiral is done, we need previous values
ZPrevious = MILL_GetPreviousZFeed()
ZCurrent = MILL_GetZFeed()
XPrevious = MILL_GetPreviousXFeed()
YPrevious = MILL_GetPreviousYFeed()
'This short code checks to see if the spiral is needed, eliminate spiral from the finish tool
ZStart = MILL_GetDoubleMemoryLoc(3)
If ZStart - ZCurrent = 0 Then 'If the second tool is posted, don't run the spiral
Call MILL_SetStringMemoryLoc(0,"SPIRALOFF")
End If
'Check to see if the user activated the spiral or if the finish tool is posting
SPIRALONOFF = MILL_GetStringMemoryLoc(0)
'If it is, run the spiral script
If SPIRALONOFF = "SPIRALON" Then
'If Z has changed, the BobCAD linear Spiral is still active - wait until all Z moves are executed
If ZCurrent < ZPrevious Then
' MILL_OutputText("(NC CODE SUPPRESSED BY SCRIPT - Z HAS CHANGED)")
Else 'BobCAD spiral is done. Let's do the Arc spiral - then post the regular Arc move
ZEnd = ZCurrent 'Find the current Z depth
ZChanged = ZStart - ZEnd 'Compare it to Z start point
ZStep = ZChanged / spiralNumTurns 'Get the ZStep for the spiral
Counter = 0 'Initialize counter
'Establish the arc move variables
XPrevious = MILL_MakeRealString(XPrevious)
YPrevious = MILL_MakeRealString(YPrevious)
ICenter = MILL_MakeRealString(spiralRadius*Cos(spiralStartAngle*DEG2RAD))*-1
JCenter = MILL_MakeRealString(spiralRadius*Sin(spiralStartAngle*DEG2RAD))*-1
Call MILL_ProcessPostLine("n,'(WARNING-CODE CHANGED BY SCRIPT)'")
Do While Counter < spiralNumTurns
Counter = Counter + 1 'Increment the counter
ZStart = ZStart - ZStep 'Increment Z
Call MILL_ProcessPostLine("n,'"&spiralDirection&" X"&XPrevious&" Y"&YPrevious&" Z"&MILL_MakeRealString(ZStart)&" I"&ICenter&" J"&JCenter&"'")
Loop
'All the arc moves should be done, turn off the script and reset the counter back to 0
Call MILL_SetStringMemoryLoc(0,"SPIRALOFF")
Counter = 0
Call MILL_ProcessPostLine("n,'(WARNING-END SCRIPT OUTPUT)'")
'Output the first move of the pocket
Call MILL_ProcessPostLine("n,'G01 'feed_move,x_f,y_f,z_f,feed_rate")
End If
Else
'Function is off, normal Block 55. post line
Call MILL_ProcessPostLine("n,feed_move,x_f,y_f,z_f,feed_rate")
End If
Code:
2008. Program Block 8.
Call MILL_SetStringMemoryLoc(0,"SPIRALOFF")
' MILL_OutputText(MILL_GetStringMemoryLoc(0))
Code:
2009. Program Block 9.
Dim spiralNumTurns
Dim spiralRadius
Dim spiralStartAngle
Dim spiralRampAngle
Dim spiralDirection
Dim ZCurrent
Dim ZPrevious
Dim ZChanged
Dim ZStart
Dim ZEnd
Dim ZStep
Dim XCurrent
Dim YCurrent
Dim Counter
Dim SPIRALONOFF
Dim PI
Dim DEG2RAD
PI = 3.14159265358979
DEG2RAD = PI/180 'Multiplier to convert degrees to Radians
'Read all the Advanced Posting Parameters from the 2D-POCKET feature
spiralNumTurns = MILL_GetUserEditIntegerVariable(14)
spiralRadius = MILL_GetUserEditRealVariable(16)
spiralStartAngle = MILL_GetUserEditIntegerVariable(17)
spiralRampAngle = MILL_GetUserEditRealVariable(18)
spiralDirection = MILL_GetStringMemoryLoc(1)
'The script runs after all the BobCAD generated code for the spiral is done, we need previous values
ZPrevious = MILL_GetPreviousZFeed()
ZCurrent = MILL_GetZFeed()
XPrevious = MILL_GetPreviousXFeed()
YPrevious = MILL_GetPreviousYFeed()
'This short code checks to see if the spiral is needed, eliminate spiral from the finish tool
ZStart = MILL_GetDoubleMemoryLoc(3)
If ZStart - ZCurrent = 0 Then 'If the second tool is posted, don't run the spiral
Call MILL_SetStringMemoryLoc(0,"SPIRALOFF")
End If
'Check to see if the user activated the spiral or if the finish tool is posting
SPIRALONOFF = MILL_GetStringMemoryLoc(0)
'If it is, run the spiral script
If SPIRALONOFF = "SPIRALON" Then
'If Z has changed, the BobCAD linear Spiral is still active - wait until all Z moves are executed
If ZCurrent < ZPrevious Then
' MILL_OutputText("(NC CODE SUPPRESSED BY SCRIPT - Z HAS CHANGED)")
Else 'BobCAD spiral is done. Let's do the Arc spiral - then post the regular Arc move
ZEnd = ZCurrent 'Find the current Z depth
ZChanged = ZStart - ZEnd 'Compare it to Z start point
ZStep = ZChanged / spiralNumTurns 'Get the ZStep for the spiral
Counter = 0 'Initialize counter
'Establish the arc move variables
XPrevious = MILL_MakeRealString(XPrevious)
YPrevious = MILL_MakeRealString(YPrevious)
ICenter = MILL_MakeRealString(spiralRadius*Cos(spiralStartAngle*DEG2RAD))*-1
JCenter = MILL_MakeRealString(spiralRadius*Sin(spiralStartAngle*DEG2RAD))*-1
Call MILL_ProcessPostLine("n,'(WARNING-CODE CHANGED BY SCRIPT)'")
Do While Counter < spiralNumTurns
Counter = Counter + 1 'Increment the counter
ZStart = ZStart - ZStep 'Increment Z
Call MILL_ProcessPostLine("n,'"&spiralDirection&" X"&XPrevious&" Y"&YPrevious&" Z"&MILL_MakeRealString(ZStart)&" I"&ICenter&" J"&JCenter&"'")
Loop
'All the arc moves should be done, turn off the script and reset the counter back to 0
Call MILL_SetStringMemoryLoc(0,"SPIRALOFF")
Counter = 0
Call MILL_ProcessPostLine("n,'(WARNING-END SCRIPT OUTPUT)'")
'Output the first move of the pocket
Call MILL_ProcessPostLine("n,g_arc_move,g_arc_plane,x_f,y_f,z_f,arc_center,feed_rate")
End If
Else
'Function is off, normal Block 64. post line
Call MILL_ProcessPostLine("n,g_arc_move,g_arc_plane,x_f,y_f,z_f,arc_center,feed_rate")
End If
Code:
COMBO_BOX,21,No (Standard Output),Yes CW (Experimental),Yes CCW (Experimental)
TEXT_LABEL,21,Use Spiral with Arcs?
DEFAULT_COMBO_INDEX,21,0
EDIT_BOX,15,INTEGER
TEXT_LABEL,15,NUMBER OF TURNS
DEFAULT_REAL,15,5
EDIT_BOX,17,REAL
TEXT_LABEL,17,ARC RADIUS
DEFAULT_REAL,17,0.2500
EDIT_BOX,18,INTEGER
TEXT_LABEL,18,START ANGLE
DEFAULT_INTEGER,18,0
EDIT_BOX,19,REAL
TEXT_LABEL,19,RAMP ANGLE*(Future use)
DEFAULT_REAL,19,0