/// <summary> /// Check, if current PowerMill project has a named workplane. /// </summary> /// <param name="wp">Workplane name to check.</param> /// <returns>true - workplane exists, false - no workplane.</returns> public static bool PowerMillHasWorkplane(string wp) { if (String.IsNullOrWhiteSpace(wp) || wp.ToUpper() == "GLOBAL") { return(true); } // Turn messages off, if necessary bool messages_displayed = PowerMILLAutomation.oPServices.RequestInformation("MessagesDisplayed") == "true"; if (messages_displayed) { PowerMILLAutomation.oPServices.DoCommand(PowerMILLAutomation.oToken, "DIALOGS MESSAGE OFF"); } // Check the workplane exists string response = PowerMILLAutomation.GetParameterValueTerse("entity_exists('workplane', '" + wp + "')"); // Turn messages back on, if they were on originally if (messages_displayed) { PowerMILLAutomation.oPServices.DoCommand(PowerMILLAutomation.oToken, "DIALOGS MESSAGE ON"); } return(response == "1"); }
/// <summary> /// Check if Checked NCProg has been modified or if the OutputFile has been delete /// </summary> /// <param name="NCProgramName"></param> /// <returns></returns> /// <remarks></remarks> public static string CheckNCProgram(string NCProgramName, out string sStatus) { string sCNFileName = null; // Get the NC prog Status //string sStatus = pmill.ExecuteEx("print par \"entity('ncprogram';'" + NCProgramName + "').Status\"").Replace("(ENUM)", "").Trim(); sStatus = PowerMILLAutomation.GetParameterValueTerse("entity('ncprogram';'" + NCProgramName + "').Status").Trim(); string sWorkPlane = PowerMILLAutomation.GetParameterValueTerse("entity('ncprogram';'" + NCProgramName + "').OutputWorkplane").Trim(); if (sStatus.ToLower() == "written") { // Get NC prog Infos PowerMILLAutomation.Execute("DIALOGS MESSAGE OFF"); string sProgCN = PowerMILLAutomation.ExecuteEx("EDIT NCPROGRAM '" + NCProgramName + "' LIST"); PowerMILLAutomation.Execute("DIALOGS MESSAGE ON"); string[] sTabCNInfos = sProgCN.Split((char)13); int iSlashIndex = sTabCNInfos[2].IndexOf('/'); if (iSlashIndex < 0) { iSlashIndex = 0; } int iSpaceIndex = sTabCNInfos[2].LastIndexOf((char)32, iSlashIndex); // Get the NCProg File Path sCNFileName = sTabCNInfos[2].Remove(0, iSpaceIndex).Trim(); return(sCNFileName); } else { return(null); } }
/// <summary> /// Get ToolNumbers and ToolName in NCProgram /// </summary> /// <param name="NCProgramName"></param> /// <remarks></remarks> public static void FillNCProgramTools(string NCProgramName, List <string> ToolpathesList, int NC_Index, out List <NCProgramTool> Tools, ref int InitToolNumber) { Tools = null; string Tool_Name; bool First_Tool = true; int Text_Blocks = 0; List <string> project_Tool_List = new List <string>(); for (int i = 0; i < ToolpathesList.Count; i++) { project_Tool_List = PowerMILLAutomation.GetListOf(PowerMILLAutomation.enumEntity.Tools); NCProgramTool NCProgTool = new NCProgramTool(); Tool_Name = PowerMILLAutomation.GetParameterValueTerse(String.Format("components(entity('ncprogram','{0}'))[{1}].Tool.Name", NCProgramName, i)).Trim(); //This section was added to match every nc program tool with a tool from the project. If no match is found, it means that the toolpath has no tool, so it is a text block. //The text block variable will be increased of one and used to compensate the list that matches toolpath with tools because text blocks do not appear into the ncprog toolpath list but do in the tool list. if (Tool_Name.ToUpper().Contains("ERROR")) { Text_Blocks = Text_Blocks + 1; continue; } NCProgTool.Name = Tool_Name; NCProgTool.Number = Convert.ToInt32(PowerMILLAutomation.GetParameterValueTerse(String.Format("entity('ncprogram','{0}').nctoolpath[{1}].ToolNumber.Value", NCProgramName, (i - Text_Blocks))).Trim()); if (First_Tool && NC_Index == 0) { InitToolNumber = NCProgTool.Number; } NCProgTool.Toolpath = ToolpathesList[(i - Text_Blocks)]; if (Tools == null) { Tools = new List <NCProgramTool>(); } Tools.Add(NCProgTool); First_Tool = false; } }
/// <summary> /// Export and translate the ToolHolder /// </summary> /// <param name="tool">Name of the tool</param> /// <param name="Type">Type to export (ToolHolder or ToolShank)</param> /// <returns>IGS file Path</returns> /// <remarks></remarks> public static string PMILLExportToolSegment(string tool, string Type, string outputDir) { // Change the name of export because of special characters string sExportToolName = tool; string sOutputPath = ""; string output_segment = ""; System.Text.RegularExpressions.Regex oRegex = new System.Text.RegularExpressions.Regex("\\W"); sExportToolName = oRegex.Replace(sExportToolName, ""); // Defines input and output path switch (Type) { case "TOOLHOLDER": outputDir = System.IO.Path.Combine(outputDir, "Holders"); output_segment = "HOLDER"; break; case "TOOLSHANK": outputDir = System.IO.Path.Combine(outputDir, "Shanks"); output_segment = "SHANK"; break; case "TOOL_PROFILE": outputDir = System.IO.Path.Combine(outputDir, "Tools"); output_segment = "TIP"; break; } if (!System.IO.Directory.Exists(outputDir)) { System.IO.Directory.CreateDirectory(outputDir); } sOutputPath = System.IO.Path.Combine(outputDir, sExportToolName + ".stl"); // Export the ToolHolder of Active Tool in DGK PowerMILLAutomation.ExecuteEx(String.Format("ACTIVATE TOOL '{0}'", tool)); PowerMILLAutomation.ExecuteEx(String.Format("EDIT TOOL ; EXPORT_STL {0} \"{1}\" YES", output_segment, sOutputPath)); // "YES" to overwrite if already exists if (System.IO.File.Exists(sOutputPath)) { // Return the IGS Path return(sOutputPath); } else { return(null); } }
/// <summary> /// Export the Selected stock model block /// </summary> /// <returns></returns> /// <remarks></remarks> public static void ExportStockModel(List <string> StockModelNames, string Tol, string DestDir, out List <string> BlockPaths, out bool bReturn) { string sOutputPath; EventLogger.WriteToEvengLog("Export block(s)"); BlockPaths = new List <string>(); bReturn = true; if (StockModelNames == null) { return; } if (StockModelNames.Count == 0) { return; } PowerMILLAutomation.ExecuteEx(String.Format("$Powermill.Export.TriangleTolerance = \"{0}\"", Tol)); BlockPaths = new List <string>(); foreach (string model in StockModelNames) { sOutputPath = ExportStockModel(model, DestDir); if (!String.IsNullOrEmpty(sOutputPath)) { BlockPaths.Add(sOutputPath); } } for (int i = 0; i < BlockPaths.Count; i++) { bReturn = System.IO.File.Exists(System.IO.Path.Combine(DestDir, BlockPaths[i])); if (!bReturn) { break; } } }
/// <summary> /// Get the NCProgToolpathes /// </summary> /// <returns></returns> /// <remarks></remarks> public static List <string> GetNCProgToolpathes(string NCProgName) { List <string> sToolpathesList = new List <string>(); // Get NC prog Infos PowerMILLAutomation.Execute("DIALOGS MESSAGE OFF"); string sProgCN = PowerMILLAutomation.ExecuteEx("EDIT NCPROGRAM '" + NCProgName + "' LIST"); PowerMILLAutomation.Execute("DIALOGS MESSAGE ON"); // Split the Line string[] sTabCNInfos = Regex.Split(sProgCN, Environment.NewLine);// sProgCN.Split(Convert.ToChar("\n\r")); // Add NC prog to the List for (int i = 4; i <= sTabCNInfos.Length - 2; i++) { if (!string.IsNullOrEmpty(sTabCNInfos[i].Trim())) { sToolpathesList.Add(sTabCNInfos[i]); } } return(sToolpathesList); }
/// <summary> /// Export Clamp List /// </summary> /// <remarks></remarks> public static void ExportClamps(List <string> ClampList, string Tol, string DestDir, out List <string> ClampListPaths, out bool bReturn) { string sOutputPath; EventLogger.WriteToEvengLog("Export clamps"); bReturn = true; ClampListPaths = new List <string>(); if (ClampList == null) { return; } if (ClampList.Count == 0) { return; } PowerMILLAutomation.ExecuteEx(String.Format("$Powermill.Export.TriangleTolerance = \"{0}\"", Tol)); ClampListPaths = new List <string>(); foreach (string model in ClampList) { sOutputPath = ExportModel(model, DestDir); if (!String.IsNullOrEmpty(sOutputPath)) { ClampListPaths.Add(sOutputPath); } } for (int i = 0; i < ClampListPaths.Count; i++) { bReturn = System.IO.File.Exists(ClampListPaths[i]); if (!bReturn) { break; } } }