public static void Cleanup() { doc = null; if (setups_info != null) { for (int i = 0; i < setups_info.Count; i++) { setups_info[i] = null; } setups_info.Clear(); } setups_info = null; num_enabled_setups = 0; if (all_solids != null) { all_solids.Clear(); all_solids = null; } if (all_ucss != null) { all_ucss.Clear(); all_ucss = null; } doc_options = null; }
public static void Cleanup() { doc = null; warning_msg = ""; if (setups_info != null) { for (int i = 0; i < setups_info.Count; i++) { setups_info[i] = null; } setups_info.Clear(); setups_info = null; } if (clamps != null) { for (int i = 0; i < clamps.Count; i++) { clamps[i] = null; } clamps.Clear(); clamps = null; } if (clamp_fpaths != null) { clamp_fpaths.Clear(); clamp_fpaths = null; } output_msg = ""; num_enabled_setups = 0; }
public static void Cleanup() { doc = null; warning_msg = ""; if (setups_info != null) { for (int i = 0; i < setups_info.Count; i++) { setups_info[i] = null; } setups_info.Clear(); } output_msg = ""; num_enabled_setups = 0; }
/* Save nc code for all setups (i.e., if part is non-indexed save 1 nc program is on). * In this case we save 1 nc program and set that program as nc code program for all setups. */ private static bool SaveOneNCProgForAllSetups(FeatureCAM.FMDocument doc, string fname_no_ext, string ext, string output_dirpath, List <SetupInfo> setups_info, ref bool is_op_error) { int nc_files_num, doc_files_num, macro_files_num; object doc_file_names, macro_file_names, nc_file_names; string err_msg; for (int i = 1; i <= doc.Setups.Count; i++) { if (doc.Setups.Item(i).Enabled) { doc.Setups.Item(i).Activate(); break; } } doc.SimToolpath(false); LogFile.Write("Run sim and save nc for the document (1 program for entire part)"); is_op_error = false; foreach (FeatureCAM.FMOperation op in doc.Operations) { if (op.Errors.Trim() != "") { is_op_error = true; } } if (is_op_error) { LogFile.Write("NC code will not be exported, because there are errors in the Operations list. Project file won't be exported as well."); return(false); } doc.SaveNC(fname_no_ext + ext, output_dirpath, false, FeatureCAM.tagFMSaveNCFileType.eNCFT_NCCode, false, out err_msg, out nc_files_num, out nc_file_names, out doc_files_num, out doc_file_names, out macro_files_num, out macro_file_names); if ((int)nc_files_num > 0) { for (int i = 0; i < setups_info.Count; i++) { foreach (string nc_fpath in (Array)nc_file_names) { if (setups_info[i].nc_fpaths == null) { setups_info[i].nc_fpaths = new List <string>(); } setups_info[i].nc_fpaths.Add((string)nc_fpath); } } LogFile.Write(String.Format("{0} file(s) created", nc_files_num)); return(true); } else { is_op_error = true; return(false); } }
public static bool SaveNCCode(FeatureCAM.Application app, FeatureCAM.FMDocument doc, string fname_no_ext, string ext, string output_dirpath, List <SetupInfo> setups_info, List <bool> save_nc_for_all_setups, bool is_single_program, int combine_setups) { int nc_files_num; object nc_file_names; string err_msg; bool is_op_error = false; int nc_file_id; /* Set output units, so they match document units */ app.PostOptionsMill.SetIsInchOutputUnits(!doc.Metric); app.PostOptionsTurn.SetIsInchOutputUnits(!doc.Metric); if (!is_single_program && combine_setups == 0) { for (int i = 0; i < setups_info.Count; i++) { if (save_nc_for_all_setups[i] && setups_info[i].enabled && setups_info[i].num_features > 0) { SaveNCForSetup(doc, doc.Setups.Item(i + 1), fname_no_ext, ext, output_dirpath, out nc_files_num, out nc_file_names, out err_msg, ref is_op_error); if ((int)nc_files_num > 0) { nc_file_id = 1; foreach (string nc_fpath in (Array)nc_file_names) { setups_info[i].nc_fpaths.Add((string)nc_fpath); } LogFile.Write(String.Format("List of created files: {0}", String.Join("\n", setups_info[i].nc_fpaths.ToArray()))); nc_file_id++; } } else { LogFile.Write(String.Format("Skip saving nc code for setup {0}. User selected not to export it, setup isn't enabled or there are no features in the setup", setups_info[i].name)); } } } else if (!is_single_program && combine_setups == 1) { for (int i = 0; i < doc.Setups.Count; i++) { if (doc.Setups.Item(i + 1).Enabled&& doc.Setups.Item(i + 1).Features.Count > 0) { SaveNCForSetup(doc, doc.Setups.Item(i + 1), fname_no_ext, ext, output_dirpath, out nc_files_num, out nc_file_names, out err_msg, ref is_op_error); if ((int)nc_files_num > 0) { nc_file_id = 1; if (setups_info[0].nc_fpaths == null) { setups_info[0].nc_fpaths = new List <string>(); } foreach (string nc_fpath in (Array)nc_file_names) { if (!setups_info[0].nc_fpaths.Contains((string)nc_fpath)) { setups_info[0].nc_fpaths.Add((string)nc_fpath); } } nc_file_id++; } } else { LogFile.Write(String.Format("Skip saving nc code for setup {0}. User selected not to export it, setup isn't enabled or there are no features in the setup", setups_info[i].name)); } } LogFile.Write(String.Format("List of created files: {0}", String.Join("\n", setups_info[0].nc_fpaths.ToArray()))); } else { bool save_nc = true; foreach (bool save_nc_for_setup in save_nc_for_all_setups) { save_nc &= save_nc_for_setup; } if (save_nc) { if (SaveOneNCProgForAllSetups(doc, fname_no_ext, ext, output_dirpath, setups_info, ref is_op_error)) { LogFile.Write(String.Format("List of created files: {0}", String.Join("\n", setups_info[0].nc_fpaths.ToArray()))); } } else { LogFile.Write("Skip saving nc code. User selected not to export it"); } } return(!is_op_error); }
private static void AllToolsToFile_Debug(FeatureCAM.FMDocument doc) { string all_tools = ""; List <FeatureCAM.FMBoringBar> bbars = new List <FeatureCAM.FMBoringBar>(); List <FeatureCAM.FMChamferMill> cmills = new List <FeatureCAM.FMChamferMill>(); List <FeatureCAM.FMCounterBore> cbores = new List <FeatureCAM.FMCounterBore>(); List <FeatureCAM.FMCounterSink> csinks = new List <FeatureCAM.FMCounterSink>(); List <FeatureCAM.FMEndMill> emills = new List <FeatureCAM.FMEndMill>(); List <FeatureCAM.FMFaceMill> fmills = new List <FeatureCAM.FMFaceMill>(); List <FeatureCAM.FMPlungeMill> pmills = new List <FeatureCAM.FMPlungeMill>(); List <FeatureCAM.FMRoundingMill> rmills = new List <FeatureCAM.FMRoundingMill>(); List <FeatureCAM.FMSideMill> smills = new List <FeatureCAM.FMSideMill>(); List <FeatureCAM.FMSpotDrill> sdrills = new List <FeatureCAM.FMSpotDrill>(); List <FeatureCAM.FMTap> taps = new List <FeatureCAM.FMTap>(); List <FeatureCAM.FMThreadMill> thmills = new List <FeatureCAM.FMThreadMill>(); List <FeatureCAM.FMTwistDrill> tdrills = new List <FeatureCAM.FMTwistDrill>(); foreach (FeatureCAM.FMToolCrib crib in doc.ToolCribs) { foreach (FeatureCAM.FMBoringBar tool in crib.BoringBars) { bbars.Add(tool); } foreach (FeatureCAM.FMChamferMill tool in crib.ChamferMills) { cmills.Add(tool); } foreach (FeatureCAM.FMCounterBore tool in crib.CounterBores) { cbores.Add(tool); } foreach (FeatureCAM.FMCounterSink tool in crib.CounterSinks) { csinks.Add(tool); } foreach (FeatureCAM.FMEndMill tool in crib.EndMills) { emills.Add(tool); } foreach (FeatureCAM.FMFaceMill tool in crib.FaceMills) { fmills.Add(tool); } foreach (FeatureCAM.FMPlungeMill tool in crib.PlungeRoughers) { pmills.Add(tool); } foreach (FeatureCAM.FMRoundingMill tool in crib.RoundingMills) { rmills.Add(tool); } foreach (FeatureCAM.FMSideMill tool in crib.SideMills) { smills.Add(tool); } foreach (FeatureCAM.FMSpotDrill tool in crib.SpotDrills) { sdrills.Add(tool); } foreach (FeatureCAM.FMTap tool in crib.Taps) { taps.Add(tool); } foreach (FeatureCAM.FMThreadMill tool in crib.ThreadMills) { thmills.Add(tool); } foreach (FeatureCAM.FMTwistDrill tool in crib.TwistDrills) { tdrills.Add(tool); } } all_tools += "/* Boring bars */"; foreach (FeatureCAM.FMBoringBar tool in bbars) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } all_tools += "/* Chamfer mills */"; foreach (FeatureCAM.FMChamferMill tool in cmills) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } all_tools += "/* Counter bores */"; foreach (FeatureCAM.FMCounterBore tool in cbores) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } all_tools += "/* Counter sinks */"; foreach (FeatureCAM.FMCounterSink tool in csinks) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } all_tools += "/* Endmills */"; foreach (FeatureCAM.FMEndMill tool in emills) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } all_tools += "/* Facemills */"; foreach (FeatureCAM.FMFaceMill tool in fmills) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } all_tools += "/* Plungemills */"; foreach (FeatureCAM.FMPlungeMill tool in pmills) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } all_tools += "/* Roundingmills */"; foreach (FeatureCAM.FMRoundingMill tool in rmills) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } all_tools += "/* Sidemills */"; foreach (FeatureCAM.FMSideMill tool in smills) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } all_tools += "/* Spotdrills */"; foreach (FeatureCAM.FMSpotDrill tool in sdrills) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } all_tools += "/* Taps */"; foreach (FeatureCAM.FMTap tool in taps) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } all_tools += "/* Threadmills */"; foreach (FeatureCAM.FMThreadMill tool in thmills) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } all_tools += "/* Twistdrills */"; foreach (FeatureCAM.FMTwistDrill tool in tdrills) { all_tools += Tool.AllToolsToString((FeatureCAM.FMTool)tool, null) + Environment.NewLine; } File.WriteAllText("C:\\all_tools1.txt", all_tools); }