' ' 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 ' ' General Description ' ' - Posts the contents of the active setup. ' - Expects the current cnc file to be set to XXXXXiso.cnc or XXXXXdie.cnc. Both files ' must be present for posting to contine. ' - All active features are posted together using XXXXXdie.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. ' Public Sub PostToAgie Dim fm_doc As FMDocument Dim active_setup As FMSetup Dim num_active_feats As Integer Dim feat As FMFeature Dim active_features() As String Set fm_doc = Application.ActiveDocument Set active_setup = fm_doc.ActiveSetup If( active_setup.Type <> eST_Wire) Then MsgBox active_setup.Name + " is not a Wire setup" 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 MsgBox "No features found in setup " + active_setup.Name GoTo cleanup End If Dim iso_index As Integer Dim die_index As Integer Dim cnc_file As String, iso_name As String, die_name As String Dim have_both As Boolean Application.GetWirePostOptions(cnc_file) ' check to see if we have both cnc files have_both = False cnc_file = UCase( cnc_file) iso_index = InStrRev( cnc_file, "ISO.CNC") die_index = InStrRev( cnc_file, "DIE.CNC") If( iso_index <> 0) Then iso_name = cnc_file die_name = Left$( cnc_file, iso_index-1) + "DIE.CNC" If( Dir( die_name) <> "") Then have_both = True End If ElseIf( die_index <> 0) Then die_name = cnc_file iso_name = Left$( cnc_file, die_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 xxxDIE.CNC MsgBox " AGIE- post not selected. " + vbCrLf + _ "Select AGIE-ISO.CNC or AGIE-DIE.CNC and re-try." GoTo cleanup End If If( Not have_both) Then MsgBox "Unable to find matching cnc file for " + cnc_file GoTo cleanup End If ' output the .SBL file for all enabled features Dim nc_file_name As String Application.SetWirePostOptions ( die_name,,,,,False) fm_doc.SimToolpath fm_doc.Post( nc_file_name) If( Dir( nc_file_name) = "") Then MsgBox "Post output file not found! Error in program?" GoTo cleanup End If ' create the output directory Dim output_dir As String, setup_name As String, 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_name As String, sbr_name As String sbl_name = output_dir + "\" + setup_name + ".SBL" sbr_name = output_dir + "\" + setup_name + ".SBR" FileCopy( nc_file_name, sbl_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_name,InStrRev( sbr_name, "\")+1) + Chr(13) ' output the .ISO file for each feature Application.SetWirePostOptions ( iso_name,,,,,False) Dim sav_name As String Dim which As Integer which = 0 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 fm_doc.SimToolpath fm_doc.Post( nc_file_name) If( Dir( nc_file_name) = "") Then MsgBox "Post output file not found! Error in program?" GoTo cleanup End If sav_name = output_dir + "\" + feat.Name + ".ISO" FileCopy( nc_file_name, sav_name) Kill nc_file_name which = which + 1 Wend ' open the sbr output file Open sbr_name For Output As #1 ' reenable all the originally enabled features and add the iso filename to the sbr file Dim feat_iso_name As String which = 0 While( which < num_active_feats) Set feat = active_setup.Features( active_features( which+1)) ' disable all the features in the setup feat.Enabled = True ' add .iso file to user notification output_files = output_files + " " + feat.Name + ".ISO" + Chr(13) ' add .iso file to sbr file Print #1, "AGIE.USING_" + feat.Name + ".iso" + " IMPORT " + setup_name + "\" + feat.Name + ".iso" + ";" + Chr(13) which = which + 1 Wend Close #1 MsgBox( output_files) cleanup: End Sub