Пример #1
0
        /// <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>
        /// 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;
                }
            }
        }