'#Reference {EF53050B-882E-4776-B643-EDA472E8E3F2}#2.7#0#C:\Program Files\Common Files\System\ado\msado15.dll#Microsoft ActiveX Data Objects 2.7 Library Option Explicit ' ' FS.bas - Illustrate the use of the MillFeedSpeed hook in conjunction with an Access ' database. ' ' Author: Tom McCollough ' Organization: Engineering Geometry Systems ' Date: 7/31/02 ' Copyright (c) 2002, Engineering Geometry Systems ' ' General Description ' ' A sample written to illustrate the MillFeedSpeed hook in conjunction with an Access ' database. ' ' You need to reference the Microsoft ActiveX Data Objects 2.7 Library. ' You must load the fs.bas as an addin. ' You must place the database in C:\fsdrilldata.mdb. ' Dim doOverrides As Integer Dim unloading As Boolean Const pi As Double = 3.14159265358979 Private Function Min( a, b ) If a < b Then Min = a Else Min = b End If End Function Public Sub MillFeedSpeed(use_new_values As FeatureCAM.tagFMFeedSpeedReturnValueType, _ feed As Double, speed As Double, stock_material As String, Tool As FeatureCAM.FMTool, _ tool_material As String, tool_coating As String, _ tool_dia As Double, tool_len As Double, op_type As Integer, _ is_finish As Boolean, is_metric As Boolean, thread As Double) doOverrides = 1 If doOverrides = 0 Then ' we will not compute new values, so tell FeatureCAM this and return use_new_values = eFSRVT_UseProgramFeedSpeed Exit Sub End If Dim conADOConnection As New Connection Dim rstMan As New ADODB.Recordset Dim strSQL As String With conADOConnection .Provider = "Microsoft.Jet.OLEDB.4.0" .Properties("Data Source") = "C:\fsdrilldata.mdb" .Open End With strSQL = "SELECT * FROM fsdata WHERE stock_material = '" & _ stock_material & _ "' AND tool_material = '" & _ tool_material & _ "' AND tool_coating = '" & _ tool_coating & _ "'" Set rstMan.ActiveConnection = conADOConnection rstMan.Open strSQL, , adOpenForwardOnly, adLockOptimistic, adCmdText If rstMan.BOF And rstMan.EOF Then MsgBox "No records for " & stock_material & " " & tool_material & " " & tool_coating rstMan.Close Else MsgBox "Records exist for " & stock_material & " " & tool_material & " " & tool_coating Dim sfm As Double ' surface feet per minute Dim ipt As Double ' inches per tooth If op_type = eFSOT_Drill Then ' get entry from database sfm = CDbl( rstMan.Fields( "sp_drill" ) ) ' this calculation turns "surface feet per minute" into RPM speed = sfm * 12 / (tool_dia * pi) ' get entry from database ipt = CDbl( rstMan.Fields( "fd_drill" ) ) ' scale the ipt by the size of the tool, just like FeatureCAM does. ' but do the scale without imposing any limits (i.e. 1.25) ipt = ipt * tool_dia ' this calculation turns "inches per tooth" into IPR (inches per revolution) feed = ipt * Tool.Flutes ' we have successfully computed new values, so tell FeatureCAM to use them use_new_values = eFSRVT_FeedSpeedIsDatabaseValue ElseIf op_type = eFSOT_Profile Then ' get entry from database sfm = CDbl( rstMan.Fields( "sp_profile" ) ) ' this calculation turns "surface feet per minute" into RPM speed = sfm * 12 / (tool_dia * pi) ' get entry from database ipt = CDbl( rstMan.Fields( "fd_profile" ) ) ' scale the ipt by the size of the tool, just like FeatureCAM does ' but do the scale without imposing any limits (i.e. 1.25) ipt = ipt * tool_dia ' this calculation turns "inches per tooth" into IPR (inches per revolution) feed = ipt * Tool.Flutes ' we have successfully computed new values, so tell FeatureCAM to use them use_new_values = eFSRVT_FeedSpeedIsDatabaseValue Else use_new_values = eFSRVT_UseProgramFeedSpeed End If End If End Sub ' Triggered when a feed/speed is computed by FeatureCAM. ' The default feed/speed values computed from the standard ' FeatureCAM database are calculated first And passed To ' this handler. If you supply this handler, Then you ' should Set feed And speed To the values you desire, And ' change use_new_values To True. If the document Is metric, ' Then the parameter is_metric Is True, And All units are ' sent To the handler In metric. Public Sub Application_MillFeedSpeed(handler_installed As Variant, feed_speed_return_value_type As FeatureCAM.tagFMFeedSpeedReturnValueType, feed As Double, speed As Double, ByVal op_type As FeatureCAM.tagFMFeedSpeedOperType, ByVal stock_material As String, Tool As FeatureCAM.FMTool, ByVal tool_material As String, ByVal tool_coating As String, ByVal tool_dia As Double, ByVal tool_len As Double, ByVal is_finish_oper As Boolean, ByVal is_metric_doc As Boolean, ByVal thread As Double, ByVal thread_is_pitch As Boolean, ByVal thread_mill_is_internal As Boolean) If Not unloading Then handler_installed = True Dim use_new As FeatureCAM.tagFMFeedSpeedReturnValueType Dim ot As Integer ot = op_type MillFeedSpeed use_new, feed, speed, stock_material, Tool, tool_material, tool_coating, tool_dia, tool_len, ot, is_finish_oper, is_metric_doc, thread feed_speed_return_value_type = use_new End If End Sub Private Sub AddIn_OnConnect(ByVal flags As FeatureCAM.tagFMAddInFlags) doOverrides = CInt( InputBox( "Please enter if you want overrides (1=yes, 0=no)", "Overrides", "1", 0, 0 ) ) If flags = eAIF_ConnectUserLoad Then Dim Doc As FMDocument For Each Doc In Application.Documents Doc.InvalidateToolpaths Next Doc End If unloading = False End Sub Private Sub AddIn_OnDisConnect(ByVal flags As FeatureCAM.tagFMAddInFlags) unloading = True If flags = eAIF_DisConnectUserUnLoad Then Dim Doc As FMDocument For Each Doc In Application.Documents Doc.InvalidateToolpaths Next Doc End If End Sub