Option Explicit ' PostCribSimAndConfigMatChooser.bas ' ' Author: Stuart Burbage ' Organisation: IndieCAM Ltd ' Date: 02/11/05 ' Revised: Kyle Kershaw ' Organization: Delcam USA ' Date: 05/04/2006 ' ' General Description ' ' This macro sets the Post Options, Tool Crib, Machine Sim file and location, Machining Configuration, and ' material for a particular machine of the user's choosing. ' ' skips setting material if material is specified as "" (blank). ' ' User must edit parameters in DoMilling and DoTurning sections to tailor to their own usage. ' 'Sub main Public Sub PostCribSimAndConfigMatChooser If Not TypeName( Application.ActiveDocument ) = "IFMDocument" Then 'don't do if mf or tsf document MsgBox "Post and crib chooser does not work for Multiple Fixture or " + vbCrLf + _ "Tombstone documents. Exiting macro",vbOkOnly,"Tilt" Exit Sub End If Dim app As Application, doc As FMDocument, Setup As FMSetup Set app = Application Set doc = app.ActiveDocument Set Setup = doc.ActiveSetup If (Setup.Type = eST_Milling) Then ' do if milling doc DoMillingStuff app, doc, Setup ElseIf (Setup.Type = eST_Turning) Then ' do if turning doc DoTurningStuff app, doc, Setup Else MsgBox "Post and crib chooser only works for Mill and Turn documents." + vbCrLf + _ "Exiting macro", vbOkOnly, "Tilt" End If End Sub Private Sub DoMillingStuff(ByVal app As Application, ByVal doc As FMDocument, ByVal Setup As FMSetup) Dim combos(3) As String ' these are the items that show up in the list box combos(0) = "Blank" combos(1) = "Blank" combos(2) = "Micron UCP 600" combos(3) = "Blank" Begin Dialog UserDialog 400,203,"Machining Centre Machine Chooser" ' %GRID:10,7,1,1 Text 20,14,360,56,"Depending upon your choice of machine, this macro establishes a post processor, an active tool crib, a tool change location, And a configuration. Please choose the machine you want to use.",.Text1 ListBox 20,77,230,77,combos(),.ComboBox1 OKButton 20,161,90,21 CancelButton 260,161,120,21 End Dialog Dim dlg As UserDialog, result As Long result = Dialog (dlg) If result = 0 Then Exit Sub Else Dim configName As String, postLocation As String, toolCrib As String, sim_file As String Dim block_s As Long, block_i As Long, tc_x As Double, tc_y As Double, tc_z As Double Dim min_arc As Double, sim_x As Double, sim_y As Double, sim_z As Double Dim mat As String If dlg.combobox1 = 0 Then configName = "mazak" ' set the configuration name postLocation = "C:\Documents and Settings\Stu\My Documents\Stu's Work\Customers Work\Walker & Tickle\GenericTURN_MILL_with_C.CNC" ' set the post and path toolCrib = "demo2.fm_Tools_from_last_save" ' set the tool crib block_s = 10 ' set block start block_i = 10 ' set block inc tc_x = 200 ' set tool change pos in x tc_z = 250 ' set tool change pos in z min_arc = .001 ' set min arc sim_file = "C:\Documents and Settings\Stu\My Documents\Stu's Work\Customers Work\Walker & Tickle\Nakamura Tome.md" ' set md model and path sim_x = 0 ' set sim position in x sim_y = 0 ' set sim position in y sim_z = -65 ' set sim position in z mat = "ALUMINUM" ' set material ElseIf dlg.combobox1 = 1 Then configName = "Gildemeister GMX 400" postLocation = "C:\Documents and Settings\Stu\My Documents\Stu's Work\Customers Work\DMG\Post Devel\GMX 400 Siemens 840D devel.CNC" toolCrib = "Gildemeister GMX 400" block_s = 10 block_i = 10 tc_x = 450 tc_z = 250 min_arc = .001 sim_file = "C:\Documents and Settings\Stu\My Documents\Stu's Work\Customers Work\DMG\Gildemeister GMX 400.md" sim_x = 0 sim_y = 0 sim_z = -200 mat = "" ElseIf dlg.combobox1 = 2 Then configName = "5_axis_demo_1" postLocation = "C:\Documents and Settings\Stu\My Documents\Stu's Work\Demo's\Mach 2006\5_axis\Mikron_UCP600.CNC" toolCrib = "basicmetric" block_s = 0 block_i = 1 tc_x = 300 tc_y = 200 tc_z = 400 min_arc = .001 sim_file = "C:\Documents and Settings\Stu\My Documents\Stu's Work\Demo's\Mach 2006\5_axis\Mikron_UCP600.md" sim_x = 0 sim_y = 0 sim_z = -90 mat = "" ElseIf dlg.combobox1 = 3 Then configName = "leadwell" postLocation = "C:\numac\leadwell.cnc" toolCrib = "numac" block_s = 5 block_i = 6 tc_x = 7 tc_z = 8 min_arc = .001 sim_file = "C:\somewhere\something.md" sim_x = 10 sim_y = 20 sim_z = 30 mat = "" End If app.SetMillPostOptions(postLocation,block_s, block_i, tc_x, tc_y, tc_z,,,min_arc) ' set the cnc file doc.ActiveToolCrib = toolCrib ' set the active tool crib Setup.SetMachineSimLocation(sim_x, sim_y, sim_z) ' set the location Setup.MachineSimFile = sim_file ' set the sim file Dim config As FMConfiguration Set config = Application.Configurations.Item( configName) ' copy over a new configuration If Not config Is Nothing Then ' test if valid configuration Application.Configurations.Item( doc.Name ).CopyConfiguration( config ) Else MsgBox "Configuration not set because no configuration exists for " & combos(dlg.combobox1) End If Dim stk As FMStock Set stk = doc.Stock If Not mat = "" Then stk.Material = mat ' sets material if not blank End If End If End Sub Private Sub DoTurningStuff(ByVal app As Application, ByVal doc As FMDocument, ByVal Setup As FMSetup) Dim combos(3) As String ' these are the items that show up in the list box combos(0) = "Demo 2 Spindle 2 Turret" combos(1) = "Gildemeister GMX 400 with B Axis" combos(2) = "Stu new machine" combos(3) = "leadwell" Begin Dialog UserDialog 400,203,"Lathe Machine Chooser" ' %GRID:10,7,1,1 Text 20,14,360,56,"Depending upon your choice of machine, this macro establishes a post processor, an active tool crib, a tool change location, And a configuration. Please choose the machine you want to use.",.Text1 ListBox 20,77,230,77,combos(),.ComboBox1 OKButton 20,161,90,21 CancelButton 260,161,120,21 End Dialog Dim dlg As UserDialog, result As Long result = Dialog (dlg) If result = 0 Then Exit Sub Else Dim configName As String, postLocation As String, toolCrib As String, sim_file As String Dim block_s As Long, block_i As Long, tc_x As Double, tc_z As Double, min_arc As Double Dim sim_x As Double, sim_y As Double, sim_z As Double Dim mat As String If dlg.combobox1 = 0 Then configName = "mazak" ' set the name postLocation = "C:\Documents and Settings\Stu\My Documents\Stu's Work\Customers Work\Walker & Tickle\GenericTURN_MILL_with_C.CNC" ' set the post and path toolCrib = "demo2.fm_Tools_from_last_save" ' set the tool crib block_s = 10 ' set block start block_i = 10 ' set block inc tc_x = 200 ' set tool change pos in x tc_z = 250 ' set tool change pos in z min_arc = .001 ' set min arc sim_file = "C:\Documents and Settings\Stu\My Documents\Stu's Work\Customers Work\Walker & Tickle\Nakamura Tome.md" ' set md model and path sim_x = 0 ' set sim position in x sim_y = 0 ' set sim position in y sim_z = -65 ' set sim position in z mat = "" ElseIf dlg.combobox1 = 1 Then configName = "Gildemeister GMX 400" postLocation = "C:\Documents and Settings\Stu\My Documents\Stu's Work\Customers Work\DMG\Post Devel\GMX 400 Siemens 840D devel.CNC" toolCrib = "Gildemeister GMX 400" block_s = 10 block_i = 10 tc_x = 450 tc_z = 250 min_arc = .001 sim_file = "C:\Documents and Settings\Stu\My Documents\Stu's Work\Customers Work\DMG\Gildemeister GMX 400.md" sim_x = 0 sim_y = 0 sim_z = -200 mat = "" ElseIf dlg.combobox1 = 2 Then configName = "mhp80" postLocation = "C:\numac\mhp80.cnc" toolCrib = "numac" block_s = 100 block_i = 200 tc_x = 300 tc_z = 400 min_arc = .001 sim_file = "C:\somewhere\something.md" sim_x = 10 sim_y = 20 sim_z = 30 mat = "" ElseIf dlg.combobox1 = 3 Then configName = "leadwell" postLocation = "C:\numac\leadwell.cnc" toolCrib = "numac" block_s = 5 block_i = 6 tc_x = 7 tc_z = 8 min_arc = .001 sim_file = "C:\somewhere\something.md" sim_x = 10 sim_y = 20 sim_z = 30 mat = "" End If app.SetTurnPostOptions(postLocation, block_s, block_i, tc_x, tc_z,,,min_arc) ' set the cnc file doc.ActiveToolCrib = toolCrib ' set the active tool crib Setup.SetMachineSimLocation(sim_x, sim_y, sim_z) ' set the location Setup.MachineSimFile = sim_file ' set the sim file Dim config As FMConfiguration Set config = Application.Configurations.Item( configName) ' copy over a new configuration If Not config Is Nothing Then ' test if valid configuration Application.Configurations.Item( doc.Name ).CopyConfiguration( config ) Else MsgBox "Configuration not set because no configuration exists for " & combos(dlg.combobox1) End If Dim stk As FMStock Set stk = doc.Stock If Not mat = "" Then stk.Material = mat ' sets material if not blank End If End If End Sub ' ' Add a toolbar and buttons upon loading of this addin into FeatureCAM. ' Private Sub AddIn_OnConnect(ByVal flags As FeatureCAM.tagFMAddInFlags) ' Bar name Button name Button face ID MakeButtonAndBar "Utility", "PostCribSimAndConfigMatChooser", 23 End Sub ' ' remove button or hide toolbar if add-in deselected ' Private Sub AddIn_OnDisConnect(ByVal flags As FeatureCAM.tagFMAddInFlags) HideDeleteBarButton "Utility", "PostCribSimAndConfigMatChooser" End Sub Private Sub MakeButtonAndBar(ByVal bar_name As String, ByVal button_name As String, _ ByVal button_id As Integer) Dim bars As FMCmdBars, bar As FMCmdBar, ctrl As FMCmdBarBtn Set bars = Application.CommandBars Set bar = bars(bar_name) If bar Is Nothing Then Set bar = bars.Add(bar_name) Else bar.Visible = True End If Set ctrl = bar.Controls(button_name) If ctrl Is Nothing Then Set ctrl = bar.Controls.Add( ,,button_name) ctrl.FaceId = button_id bar.Visible = True End If End Sub Private Sub HideDeleteBarButton(ByVal bar_name As String, ByVal button_name As String) Dim bars As FMCmdBars, bar As FMCmdBar, ctrl As FMCmdBarCtrl Set bars = Application.CommandBars Set bar = bars(bar_name) If Not bar Is Nothing Then Set ctrl = bar.Controls(button_name) If Not ctrl Is Nothing Then If bar.Controls.Count > 1 Then ctrl.Delete Else bar.Visible=False End If End If End If End Sub