private static void LoadStockInfo(string stock_fpath, string workpieceID) { double stock_x, stock_y, stock_z; double stock_thickness; double stock_bbox_xmin, stock_bbox_xmax, stock_bbox_ymin, stock_bbox_ymax, stock_bbox_zmin, stock_bbox_zmax; if (!(Variables.stock.Type == tagFMStockType.eST_Block && Variables.stock.IndexType == tagFMIndexType.eIT_None)) { Variables.stock.BoundingBox(out stock_bbox_xmin, out stock_bbox_ymin, out stock_bbox_zmin, out stock_bbox_xmax, out stock_bbox_ymax, out stock_bbox_zmax, tagFMCoordinateSpace.eCS_World, null); stock_thickness = stock_bbox_zmax - stock_bbox_zmin; Variables.stock.GetLocation(out stock_x, out stock_y, out stock_z); if (Variables.stock.Type == tagFMStockType.eST_Block) { stock_z = stock_z - stock_thickness; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisX) { stock_y = stock_z = 0; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisY) { stock_x = stock_z = 0; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisZ) { stock_y = stock_z = 0; } Variables.eureka_proj.AddFileShape("stock", workpieceID, stock_fpath, Variables.offset_x, Variables.offset_y, Variables.offset_z, 0, 0, 0, ""); Variables.eureka_proj.SetShapeAsStock(workpieceID + ".stock"); } else { FMSetup setup = Variables.doc.Setups.Item(Variables.selected_setup_id + 1); FMUcs ucs = setup.ucs; double i, j, k; double x, y, z, xx, xy, xz, yx, yy, yz, zx, zy, zz; ucs.GetLocation(out x, out y, out z); ucs.GetVectors(out xx, out xy, out xz, out yx, out yy, out yz, out zx, out zy, out zz); ComputeEulerAngles(ucs, out i, out j, out k); Variables.eureka_proj.AddFileShape("stock", workpieceID, stock_fpath, Variables.offset_x, Variables.offset_y, -1 * Variables.offset_z, i, j, k, ""); Variables.eureka_proj.SetShapeAsStock(workpieceID + ".stock"); } }
private static void SaveNCForSetup(FMDocument doc, FMSetup setup, string fname_no_ext, string ext, string output_dirpath, out int nc_files_num, out object nc_file_names, out string err_msg, ref bool is_op_error) { int doc_files_num, macro_files_num; object doc_file_names, macro_file_names; nc_files_num = 0; err_msg = ""; nc_file_names = null; LogFile.Write(String.Format("Run sim and save nc for setup {0}", setup.Name)); setup.Activate(); doc.SimToolpath(false); is_op_error = false; foreach (FeatureCAM.FMFeature feat in setup.Features) { for (int i = 1; i <= feat.Operations.Count; i++) { if (feat.Operations.Item(i).Errors.Trim() != "") { is_op_error = true; } } } if (is_op_error) { LogFile.Write("There are errors in the setup's operations list. NC code will not be exported. Project file won't be exported as well."); return; } doc.SaveNC(fname_no_ext + ext, output_dirpath, true, 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); LogFile.Write(String.Format("{0} file(s) created", nc_files_num)); }
private static string GetToolsInSetups(FMSetup setup) { string setup_tool_list = ""; FMFeatures feats; FMFeature feat; FMOperations ops; FMOperation op; FMTool tool; if (setup == null) { return(""); } feats = setup.Features; if (feats == null) { return(""); } for (int fi = 1; fi <= feats.Count; fi++) { feats.Item(1); feat = (FMFeature)feats.Item(fi); string featname = feat.Name; ops = feat.Operations; for (int oi = 1; oi <= ops.Count; oi++) { op = (FMOperation)ops.Item(oi); string opname = (string)op.OperationName; tool = (FMTool)op.Tool; if (tool != null) { setup_tool_list += (string)tool.Name + ';'; } } } return(setup_tool_list); }
private static string GetNCCodeInfo() { string fcontent = ""; double xx, xy, xz, yx, yy, yz, zx, zy, zz; double x = 0, y = 0, z = 0; double stock_x, stock_y, stock_z; double stock_thickness; double stock_bbox_xmin, stock_bbox_xmax, stock_bbox_ymin, stock_bbox_ymax, stock_bbox_zmin, stock_bbox_zmax; Variables.stock.GetLocation(out stock_x, out stock_y, out stock_z); Variables.stock.BoundingBox(out stock_bbox_xmin, out stock_bbox_ymin, out stock_bbox_zmin, out stock_bbox_xmax, out stock_bbox_ymax, out stock_bbox_zmax, tagFMCoordinateSpace.eCS_World, null); stock_thickness = stock_bbox_zmax - stock_bbox_zmin; fcontent += "BEGIN_NCFRAME" + Environment.NewLine; if (Variables.stock.IndexType == tagFMIndexType.eIT_None) { Variables.doc.ActiveSetup.ucs.GetVectors(out xx, out xy, out xz, out yx, out yy, out yz, out zx, out zy, out zz); double tempx, tempy, tempz; tempx = tempy = tempz = 0; if (xx == 1 && xy == 0 && xz == 0 && yx == 0 && yy == 1 && yz == 0) { tempz = z + stock_bbox_zmin; } (Variables.doc.Setups.Item(Variables.selected_setup_id + 1)).MapWorldToSetup(ref tempx, ref tempy, ref tempz); fcontent += Lib.tab + "|FRAME|G" + Variables.doc.ActiveSetup.FixtureID + "|" + Math.Round(Lib.FromUnitsToUnits(Variables.offset_x, Variables.doc.Metric, true), 4) + "," + Math.Round(Lib.FromUnitsToUnits(Variables.offset_y, Variables.doc.Metric, true), 4) + "," + Math.Round(Lib.FromUnitsToUnits(-1 * Variables.offset_z, Variables.doc.Metric, true), 4) + "," + Math.Round(1.0, 4) + "," + Math.Round(0.0, 4) + "," + Math.Round(0.0, 4) + "," + Math.Round(0.0, 4) + "," + Math.Round(1.0, 4) + "," + Math.Round(0.0, 4) + "|" + Environment.NewLine; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisX || Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisY || Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisZ) { foreach (FMSetup setup in Variables.doc.Setups) { if (Variables.stock.Type == tagFMStockType.eST_Block) { x = stock_x + x; y = stock_y + y; z = stock_z + stock_thickness + z; } setup.MapSetupToWorld(ref x, ref y, ref z); setup.ucs.GetVectors(out xx, out xy, out xz, out yx, out yy, out yz, out zx, out zy, out zz); fcontent += Lib.tab + "|FRAME|G" + setup.FixtureID + "|" + Math.Round(Lib.Inch2MM(x), 4) + "," + Math.Round(Lib.Inch2MM(y), 4) + "," + Math.Round(Lib.Inch2MM(z), 4) + "," + Math.Round(xx, 4) + "," + Math.Round(xy, 4) + "," + Math.Round(xz, 4) + "," + Math.Round(yx, 4) + "," + Math.Round(yy, 4) + "," + Math.Round(yz, 4) + "|" + Environment.NewLine; } } else if (Variables.stock.IndexType == tagFMIndexType.eIT_5thAxis) { if (Settings.is_use_DATUM) { string touch_off_setup_name; touch_off_setup_name = Variables.stock.TouchOffSetup; FMSetup setup = Variables.doc.Setups.Item(touch_off_setup_name); setup.ucs.GetLocation(out x, out y, out z); x += Variables.offset_x; y += Variables.offset_y; z += Variables.offset_z; fcontent += Lib.tab + "|FRAME|P0|" + Math.Round(Lib.FromUnitsToUnits(x, Variables.doc.Metric, true), 4) + "," + Math.Round(Lib.FromUnitsToUnits(y, Variables.doc.Metric, true), 4) + "," + Math.Round(Lib.FromUnitsToUnits(-z, Variables.doc.Metric, true), 4) + "," + "1.0,0.0,0.0" + "," + "0.0,1.0,0.0|" + Environment.NewLine; } else { foreach (FMSetup setup in Variables.doc.Setups) { if (Variables.stock.Type == tagFMStockType.eST_Block) { x = stock_x + x; y = stock_y + y; z = stock_z + stock_thickness + z; } setup.MapSetupToWorld(ref x, ref y, ref z); setup.ucs.GetVectors(out xx, out xy, out xz, out yx, out yy, out yz, out zx, out zy, out zz); fcontent += Lib.tab + "|FRAME|G" + setup.FixtureID + "|" + Math.Round(Lib.Inch2MM(x), 4) + "," + Math.Round(Lib.Inch2MM(y), 4) + "," + Math.Round(Lib.Inch2MM(z), 4) + "," + Math.Round(xx, 4) + "," + Math.Round(xy, 4) + "," + Math.Round(xz, 4) + "," + Math.Round(yx, 4) + "," + Math.Round(yy, 4) + "," + Math.Round(yz, 4) + "|" + Environment.NewLine; } } } fcontent += "END" + Environment.NewLine + Environment.NewLine; return(fcontent); }
private static string GetStockInfo() { string fcontent = ""; double stock_x, stock_y, stock_z; double stock_thickness; double stock_bbox_xmin, stock_bbox_xmax, stock_bbox_ymin, stock_bbox_ymax, stock_bbox_zmin, stock_bbox_zmax; if (!(Variables.stock.Type == tagFMStockType.eST_Block && Variables.stock.IndexType == tagFMIndexType.eIT_None)) { Variables.stock.BoundingBox(out stock_bbox_xmin, out stock_bbox_ymin, out stock_bbox_zmin, out stock_bbox_xmax, out stock_bbox_ymax, out stock_bbox_zmax, tagFMCoordinateSpace.eCS_World, null); stock_thickness = stock_bbox_zmax - stock_bbox_zmin; Variables.stock.GetLocation(out stock_x, out stock_y, out stock_z); if (Variables.stock.Type == tagFMStockType.eST_Block) { stock_z = stock_z - stock_thickness; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisX) { stock_y = stock_z = 0; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisY) { stock_x = stock_z = 0; } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisZ) { stock_y = stock_z = 0; } fcontent += "BEGIN_MODEL" + Environment.NewLine + Lib.tab + "|UNITS|" + (Variables.doc.Metric ? "MM" : "INCH") + "|" + Environment.NewLine + Lib.tab + "|VECTOR|" + Math.Round(Lib.FromUnitsToUnits(Variables.offset_x, Variables.doc.Metric, true), 4) + "," + Math.Round(Lib.FromUnitsToUnits(Variables.offset_y, Variables.doc.Metric, true), 4) + "," + Math.Round(Lib.FromUnitsToUnits(Variables.offset_z, Variables.doc.Metric, true), 4) + "|0.0,0.0,0.0|" + Environment.NewLine + Lib.tab + "|MATRICE_OXY|" + Math.Round(stock_x, 4) + "," + Math.Round(stock_y, 4) + "," + Math.Round(stock_z, 4) + "," + "1.0,0.0,0.0,0.0,1.0,0.0|" + Environment.NewLine + Lib.tab + "|STOCK|STL|stock.stl|0.1|" + Environment.NewLine + "END" + Environment.NewLine + Environment.NewLine; } else { FMSetup setup = Variables.doc.Setups.Item(Variables.selected_setup_id + 1); FMUcs ucs = setup.ucs; double x, y, z, xx, xy, xz, yx, yy, yz, zx, zy, zz; ucs.GetLocation(out x, out y, out z); ucs.GetVectors(out xx, out xy, out xz, out yx, out yy, out yz, out zx, out zy, out zz); Variables.stock.BoundingBox(out stock_bbox_xmin, out stock_bbox_ymin, out stock_bbox_zmin, out stock_bbox_xmax, out stock_bbox_ymax, out stock_bbox_zmax, tagFMCoordinateSpace.eCS_World, null); double tempx, tempy, tempz; tempx = tempy = tempz = 0; if (xx == 1 && xy == 0 && xz == 0 && yx == 0 && yy == 1 && yz == 0) { tempz = (stock_bbox_zmax - stock_bbox_zmin) + z; } setup.MapWorldToSetup(ref tempx, ref tempy, ref tempz); fcontent += "BEGIN_MODEL" + Environment.NewLine + Lib.tab + "|UNITS|" + (Variables.doc.Metric ? "MM" : "INCH") + "|" + Environment.NewLine + Lib.tab + "|VECTOR|" + Math.Round(Lib.FromUnitsToUnits(Variables.offset_x, Variables.doc.Metric, true), 4) + "," + Math.Round(Lib.FromUnitsToUnits(Variables.offset_y, Variables.doc.Metric, true), 4) + "," + Math.Round(Lib.FromUnitsToUnits(Variables.offset_z, Variables.doc.Metric, true), 4) + "|0.0,0.0,0.0|" + Environment.NewLine + Lib.tab + "|MATRICE_OXY|" + Math.Round(x, 4) + "," + Math.Round(y, 4) + "," + Math.Round(z, 4) + "," + xx + "," + xy + "," + xz + "," + yx + "," + yy + "," + yz + "|" + Environment.NewLine + Lib.tab + "|STOCK|STL|stock.stl|0.1|" + Environment.NewLine + "END" + Environment.NewLine + Environment.NewLine; } return(fcontent); }
private static void SetCoordSystemInfo(SetupInfo setup_info, ref string mod_setup_info) { int pos_s, pos_e, insert_at; string coord_sys_desc, new_component_str; try { if (setup_info.ucss == null) { return; } FindXMLBlock(mod_setup_info, "CSystems", out pos_s, out pos_e); if (pos_s < 0 || pos_e < 0) //there is no Setups info in the template { new_component_str = " <CSystems Simulation=\"off\">" + Environment.NewLine + " <Machine></Machine>" + Environment.NewLine + " </CSystems>" + Environment.NewLine; } else { new_component_str = mod_setup_info.Substring(pos_s, pos_e - pos_s); } coord_sys_desc = ""; FMUcs attach_ucs = Variables.doc.UCSs.Item(setup_info.attach_ucs); FMSetup temp_setup = Variables.doc.AddSetup(setup_info.attach_ucs + "_temp_setup", tagFMSetupType.eST_Milling, null, attach_ucs.Name, Type.Missing); temp_setup.Enabled = false; foreach (UCS ucs in Variables.all_ucss) { double x, y, z, i, j, k; ucs.ComputeCoordinatesInRelationToSetup(temp_setup, out x, out y, out z, out i, out j, out k); coord_sys_desc += String.Format(" <CSystem Name=\"{0}\" Type=\"component\" Visible=\"none\" Color=\"-1\" Transition=\"{1}\">\r\n", (!setup_info.sub_spindle ? "" : "(Main) ") + ucs.name, (ucs.name.Equals(Variables.doc_options.trans_ucs) ? "on" : "off")) + String.Format(" <Attach>{0}</Attach>\r\n", (!ucs.name.Equals(Variables.doc_options.trans_ucs) ? setup_info.attach_ucss_to : setup_info.attach_stock_to)) + String.Format(" <Position X=\"{0}\" Y=\"{1}\" Z=\"{2}\"/>\r\n", Math.Round(x, 4), Math.Round(y, 4), Math.Round(z, 4)) + String.Format(" <Rotation I=\"{0}\" J=\"{1}\" K=\"{2}\"/>\r\n", i, j, k) + String.Format(" </CSystem>\r\n"); } FMUcs temp_setup_ucs = temp_setup.ucs; temp_setup.Delete(); temp_setup_ucs.Delete(); if (!String.IsNullOrEmpty(setup_info.attach_ucs_subspindle)) { attach_ucs = Variables.doc.UCSs.Item(setup_info.attach_ucs_subspindle); temp_setup = Variables.doc.AddSetup(setup_info.attach_ucs_subspindle + "_temp_setup", tagFMSetupType.eST_Milling, null, attach_ucs.Name, Type.Missing); temp_setup.Enabled = false; if (setup_info.attach_ucss_to_subspindle != "") { foreach (UCS ucs in Variables.all_ucss) { double x, y, z, i, j, k; ucs.ComputeCoordinatesInRelationToSetup(temp_setup, out x, out y, out z, out i, out j, out k); coord_sys_desc += String.Format(" <CSystem Name=\"{0}\" Type=\"component\" Visible=\"none\" Color=\"-1\" Transition=\"{1}\">\r\n", "(Sub) " + ucs.name, (ucs.name.Equals(Variables.doc_options.trans_ucs) ? "on" : "off")) + String.Format(" <Attach>{0}</Attach>\r\n", (!ucs.name.Equals(Variables.doc_options.trans_ucs) ? setup_info.attach_ucss_to_subspindle : setup_info.attach_stock_to_subspindle)) + String.Format(" <Position X=\"{0}\" Y=\"{1}\" Z=\"{2}\"/>\r\n", Math.Round(x, 4), Math.Round(y, 4), Math.Round(z, 4)) + String.Format(" <Rotation I=\"{0}\" J=\"{1}\" K=\"{2}\"/>\r\n", i, j, k) + String.Format(" </CSystem>\r\n"); } } temp_setup_ucs = temp_setup.ucs; temp_setup.Delete(); temp_setup_ucs.Delete(); } insert_at = new_component_str.IndexOf("</CSystems>"); insert_at = new_component_str.LastIndexOf(Environment.NewLine, insert_at) + Environment.NewLine.Length; new_component_str = new_component_str.Insert(insert_at, coord_sys_desc); if (pos_s < 0 || pos_e < 0) //there is no Setups info in the template { insert_at = mod_setup_info.IndexOf("</Setup>"); insert_at = mod_setup_info.LastIndexOf(Environment.NewLine, insert_at) + Environment.NewLine.Length; mod_setup_info = mod_setup_info.Insert(insert_at, new_component_str); } else { mod_setup_info = mod_setup_info.Substring(0, pos_s) + new_component_str + mod_setup_info.Substring(pos_e); } } catch (Exception Ex) { LogFile.WriteException(Ex, "SetCoordSystemInfo"); } }
private static void GetNCCodeInfo(Eureka.Controller controller) { double xx, xy, xz, yx, yy, yz, zx, zy, zz; double x = 0, y = 0, z = 0; double stock_x, stock_y, stock_z; double stock_thickness; double stock_bbox_xmin, stock_bbox_xmax, stock_bbox_ymin, stock_bbox_ymax, stock_bbox_zmin, stock_bbox_zmax; int work_ref_index; Variables.stock.GetLocation(out stock_x, out stock_y, out stock_z); Variables.stock.BoundingBox(out stock_bbox_xmin, out stock_bbox_ymin, out stock_bbox_zmin, out stock_bbox_xmax, out stock_bbox_ymax, out stock_bbox_zmax, tagFMCoordinateSpace.eCS_World, null); stock_thickness = stock_bbox_zmax - stock_bbox_zmin; if (Variables.stock.IndexType == tagFMIndexType.eIT_None) { Variables.doc.ActiveSetup.ucs.GetVectors(out xx, out xy, out xz, out yx, out yy, out yz, out zx, out zy, out zz); double tempx, tempy, tempz; tempx = tempy = tempz = 0; if (xx == 1 && xy == 0 && xz == 0 && yx == 0 && yy == 1 && yz == 0) { tempz = z + stock_bbox_zmin; } controller.RemoveAllDefaultWorkReferences(); work_ref_index = controller.GetWorkReferenceIndex("G" + Variables.doc.ActiveSetup.FixtureID); if (work_ref_index > 0) { controller.SetDefaultWorkReference(work_ref_index, Math.Round(Lib.FromUnitsToUnits(Variables.offset_x, Variables.doc.Metric, true), 4), Math.Round(Lib.FromUnitsToUnits(Variables.offset_y, Variables.doc.Metric, true), 4), Math.Round(Lib.FromUnitsToUnits(-1 * Variables.offset_z, Variables.doc.Metric, true), 4)); } } else if (Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisX || Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisY || Variables.stock.IndexType == tagFMIndexType.eIT_4thAxisZ) { foreach (FMSetup setup in Variables.doc.Setups) { if (Variables.stock.Type == tagFMStockType.eST_Block) { x = stock_x + x; y = stock_y + y; z = stock_z + stock_thickness + z; } controller.RemoveAllDefaultWorkReferences(); work_ref_index = controller.GetWorkReferenceIndex("G" + Variables.doc.ActiveSetup.FixtureID); if (work_ref_index > 0) { controller.SetDefaultWorkReference(work_ref_index, Math.Round(Lib.Inch2MM(x), 4), Math.Round(Lib.Inch2MM(y), 4), Math.Round(Lib.Inch2MM(z), 4)); } } } else if (Variables.stock.IndexType == tagFMIndexType.eIT_5thAxis) { if (Variables.use_DATUM) { string touch_off_setup_name; touch_off_setup_name = Variables.stock.TouchOffSetup; FMSetup setup = Variables.doc.Setups.Item(touch_off_setup_name); setup.ucs.GetLocation(out x, out y, out z); x += Variables.offset_x; y += Variables.offset_y; z += Variables.offset_z; controller.RemoveAllDefaultWorkReferences(); work_ref_index = controller.GetWorkReferenceIndex(Variables.doc.ActiveSetup.FixtureID); if (work_ref_index > 0) { controller.SetDefaultWorkReference(work_ref_index, Math.Round(Lib.Inch2MM(x), 4), Math.Round(Lib.Inch2MM(y), 4), Math.Round(Lib.Inch2MM(z), 4)); } } else { foreach (FMSetup setup in Variables.doc.Setups) { if (Variables.stock.Type == tagFMStockType.eST_Block) { x = stock_x + x; y = stock_y + y; z = stock_z + stock_thickness + z; } setup.MapSetupToWorld(ref x, ref y, ref z); setup.ucs.GetVectors(out xx, out xy, out xz, out yx, out yy, out yz, out zx, out zy, out zz); } } } }