' ' PostToAgie.bas - Button handler to create output files for posting to Agie Wire machines ' ' Author: Paul T. Shilton ' Organization: Engineering Geometry Systems ' Date: 7/15/02 ' Copyright (c) 2002, Engineering Geometry Systems ' ' Changed by Nina Tvorogova to support AGIE pocketing ' ' General Description ' ' - Posts the contents of the active setup. ' - Expects the current cnc file to be set to XXXXXiso.cnc or XXXXXsbl.cnc. Both files ' must be present for posting to continue. ' - All active features are posted together using XXXXXsbl.cnc to create the .SBL file ' - Each active feature is posted seperately using XXXXXiso.cnc to create a FEATURENAME.iso ' for each feature. ' - The .sbr file is created referencing each .iso file. ' - The output files are created in a subdirectory in the directory where the original .fm ' file was located. ' - Create a macro button that calls "PostToAgie". Use this button to create the final NC code ' instead of using the NC tab in FeatureCAM. ' Option Explicit Dim fm_doc As FMDocument Dim feat As FMFeature Dim nc_file_name As String Dim sbr_file_name As String Dim output_dir As String Dim setup_name As String Public Sub PostToAgie() PostToAgieHelper(True) End Sub Public Sub PostToAgieHelper(disp_msgbox As Boolean) Dim active_setup As FMSetup Dim num_active_feats As Integer Dim active_features() As String Set fm_doc = Application.ActiveDocument Set active_setup = fm_doc.ActiveSetup If ( active_setup.Type <> eST_Wire ) Then DisplayMsgBox active_setup.Name + " is not a Wire setup", disp_msgbox GoTo cleanup End If ReDim active_features( active_setup.Features.Count ) num_active_feats = 0 For Each feat In active_setup.Features If feat.Enabled Then num_active_feats = num_active_feats + 1 active_features( num_active_feats ) = feat.Name End If Next feat If( num_active_feats <= 0 ) Then DisplayMsgBox "No features found in setup " + active_setup.Name, disp_msgbox GoTo cleanup End If Dim iso_index As Integer Dim sbl_index As Integer Dim cnc_file As String, iso_name As String, sbl_name As String Dim have_both As Boolean cnc_file = Application.PostOptionsWire.CncFileName ' check to see if we have both cnc files have_both = False cnc_file = UCase( cnc_file) iso_index = InStrRev( cnc_file, "ISO.CNC" ) sbl_index = InStrRev( cnc_file, "SBL.CNC" ) If ( iso_index <> 0 ) Then iso_name = cnc_file sbl_name = Left$( cnc_file, iso_index-1 ) + "SBL.CNC" If ( Dir(sbl_name) <> "" ) Then have_both = True End If ElseIf ( sbl_index <> 0 ) Then sbl_name = cnc_file iso_name = Left$( cnc_file, sbl_index-1 ) + "ISO.CNC" If ( Dir(iso_name) <> "" ) Then have_both = True End If Else ' cnc file name does not match naming convention of xxxISO.CNC or xxxSBL.CNC DisplayMsgBox " AGIE- post not selected. " + vbCrLf + _ "Select AGIE-ISO.CNC or AGIE-SBL.CNC and re-try.", disp_msgbox GoTo cleanup End If If ( Not have_both ) Then DisplayMsgBox "Unable to find matching cnc file for " + cnc_file, disp_msgbox GoTo cleanup End If ' output the .SBL file for all enabled features Application.PostOptionsWire.SetCNCFileName(sbl_name) Application.PostOptionsWire.SetIsInchOutputUnits(False) fm_doc.SimToolpath fm_doc.Post( nc_file_name ) If ( Dir( nc_file_name ) = "" ) Then DisplayMsgBox "Post output file not found! Error in program?", disp_msgbox GoTo cleanup End If ' create the output directory Dim tmp As String, output_files As String Dim ext_index As Integer output_dir = fm_doc.path nc_file_name = UCase( nc_file_name ) ext_index = InStrRev( nc_file_name, ".TXT" ) tmp = Left$( nc_file_name, ext_index-1 ) setup_name = active_setup.Name If ( InStrRev( tmp, "\") <> 0) Then setup_name = Mid$(tmp,InStrRev( tmp, "\" ) + 1) End If output_dir = output_dir + "\" + setup_name Dim file As String, pattern As String file = Dir( output_dir, vbDirectory ) If ( file <> "" ) Then pattern = output_dir + "\*.*" file = Dir( pattern ) If ( file <> "" ) Then While file <> "" pattern = output_dir + "\" + file Kill pattern file = Dir$() Wend End If Else MkDir output_dir End If ' copy sbl file to output directory Dim sbl_file_name As String sbl_file_name = output_dir + "\" + setup_name + ".SBL" sbr_file_name = output_dir + "\" + setup_name + ".SBR" FileCopy(nc_file_name, sbl_file_name) Kill nc_file_name output_files = "NC output saved in: " + output_dir + Chr(13) + Chr(13) output_files = output_files + " " + setup_name + ".SBL" + Chr(13) output_files = output_files + " " + Mid$(sbr_file_name,InStrRev( sbr_file_name, "\" ) + 1) + Chr(13) ' output the .ISO file for each feature Application.PostOptionsWire.SetCNCFileName(iso_name) Application.PostOptionsWire.SetIsInchOutputUnits(False) Dim which As Integer Dim postfix As String which = 0 postfix = "" While( which < num_active_feats) Set feat = active_setup.Features( active_features( which+1 ) ) ' disable all the features in the setup active_setup.Enabled = False ' enable just this feature and post it feat.Enabled = True Dim op_type As Long ' tagFMWireEDMOperType Dim cutter_comp As Byte ' eAID_WireCutterComp - cutter comp or offset ' save the strategy of the feature and set contour strategy to the feature Select Case feat.Type Case eWEDM_Die op_type = feat.Attribute(eAID_WireDieOpers) If (op_type = eWEDM_OperPocket) Then ' do nothing, keep pocketing operation postfix = "a" ElseIf (op_type = eWEDM_OperPocket + eWEDM_OperContour) Then ' do pocketing with "a" postfix feat.SetAttribute(eAID_WireDieOpers, , eWEDM_OperPocket) postfix = "a" If Not PostSaveISOandSBR(postfix, output_files, disp_msgbox) Then GoTo cleanup ' then do contour with "b" postfix feat.SetAttribute(eAID_WireDieOpers, , eWEDM_OperContour) postfix = "b" Else feat.SetAttribute(eAID_WireDieOpers, , eWEDM_OperContour) End If Case eWEDM_Punch, eWEDM_Side op_type = feat.Attribute(eAID_WireNonDieOpers) feat.SetAttribute(eAID_WireNonDieOpers, , eWEDM_OperContour) Case eWEDM_4Die op_type = feat.Attribute(eAID_Wire4DieOpers) feat.SetAttribute(eAID_Wire4DieOpers, , eWEDM_Oper4Contour) Case eWEDM_4Punch, eWEDM_4Side op_type = feat.Attribute(eAID_WireNon4DieOpers) feat.SetAttribute(eAID_WireNon4DieOpers, , eWEDM_Oper4Contour) End Select cutter_comp = feat.Attribute(eAID_WireCutterComp) feat.SetAttribute(eAID_WireCutterComp, , 1) If Not PostSaveISOandSBR(postfix, output_files, disp_msgbox) Then GoTo cleanup ' restore the strategy of the feature Select Case feat.Type Case eWEDM_Die feat.SetAttribute(eAID_WireDieOpers, , op_type) Case eWEDM_Punch, eWEDM_Side feat.SetAttribute(eAID_WireNonDieOpers, , op_type) Case eWEDM_4Die feat.SetAttribute(eAID_Wire4DieOpers, , op_type) Case eWEDM_4Punch, eWEDM_4Side feat.SetAttribute(eAID_WireNon4DieOpers, , op_type) End Select feat.SetAttribute(eAID_WireCutterComp, , cutter_comp) which = which + 1 postfix = "" Wend ' reenable all the originally enabled features and add the iso filename to the sbr file which = 0 While( which < num_active_feats) Set feat = active_setup.Features( active_features( which+1 ) ) ' reenable all the features in the setup feat.Enabled = True which = which + 1 Wend DisplayMsgBox output_files, disp_msgbox cleanup: End Sub Private Function PostSaveISOandSBR( _ ByVal a_postfix As String, _ ByRef a_output_files As String, _ ByVal a_disp_msgbox As Boolean _ ) As Boolean Dim b_result As Boolean Dim iso_file_name As String Dim fn As Integer b_result = True fm_doc.SimToolpath fm_doc.Post( nc_file_name ) If ( Dir(nc_file_name) = "" ) Then DisplayMsgBox "Post output file not found! Error in program?", a_disp_msgbox b_result = False End If iso_file_name = UCase(feat.Name) + a_postfix + ".ISO" FileCopy( nc_file_name, output_dir + "\" + iso_file_name ) Kill nc_file_name a_output_files = a_output_files + " " + iso_file_name + Chr(13) ' open the sbr output file fn = FreeFile Open sbr_file_name For Append As #fn Print #fn, "AGIE.USING_" + iso_file_name + " IMPORT " + iso_file_name + ";" + Chr(13) Close #fn PostSaveISOandSBR = b_result End Function Private Sub DisplayMsgBox( ByVal message As String, ByVal disp_msgbox As Boolean) If disp_msgbox Then MsgBox message End If End Sub