'#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.xls. ' Dim doOverrides As Integer Dim unloading As Boolean Sub Main doOverrides = CInt( InputBox( "Please enter if you want overrides", "Overrides", "1" ) ) End Sub 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_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 = 1 And op_type = eFSOT_Drill Then ' fall through Else ' we will not compute new values, so tell FeatureCAM this and return use_new_values = eFSRVT_UseProgramFeedSpeed Exit Sub End If Debug.Print "PROGRAM STARTING1" Dim conADOConnection As New Connection Dim rstMan As New ADODB.Recordset Dim strSQL As String With conADOConnection Dim fsdatabase As String fsdatabase = "C:\fsdrilldata.xls" .Provider = "Microsoft.Jet.OLEDB.4.0" .ConnectionString = "Data Source=" & fsdatabase & ";Extended Properties=Excel 8.0;" ' the on error statement is essential... it causes the next statement to be ' executed on an error. otherwise i think it exits the procedure entirely. On Error Resume Next .Open If Err Then MsgBox "There was an error opening the F/S database " & fsdatabase & "." Exit Sub Else MsgBox "The F/S database was opened successfully." End If 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 If op_type = eFSOT_Drill Then ' get entry from database feed = CDbl( rstMan.Fields( "fd_drill" ) ) ' this is the calculation that makes the feed be relative to the tool diameter feed = feed * Min( tool_dia, 1.25 ) ' get entry from database speed = CDbl( rstMan.Fields( "sp_drill" ) ) ' this calculation turns "surface feet per minute" into RPM speed = speed * 12 / (tool_dia * pi) ' we have successfully computed new values, so tell FeatureCAM to use them use_new_values = eFSRVT_FeedSpeedIsDatabaseValue 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 Dim use_new As FeatureCAM.tagFMFeedSpeedReturnValueType Dim ot As Integer ot = op_type MillFeedSpeed use_new, feed, speed, stock_material, 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) 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