コード例 #1
0
        internal BAPlot(ref Mtb.Application pApp)
        {
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            InitializeComponent();
            AddIn.gMtbApp = pApp;


            //var myModel = new PlotModel { Title = "Example 1" };
            //myModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
            //this.plot1.Model = myModel;
        }
コード例 #2
0
        private void buttonTest_Click(object sender, EventArgs e)
        {
            Mtb.Application MtbApp       = new Mtb.Application();
            Mtb.Project     MtbProject   = MtbApp.ActiveProject;
            Mtb.Worksheet   MtbWorksheet = MtbProject.ActiveWorksheet;

            MtbApp.UserInterface.Visible       = false;
            MtbApp.UserInterface.DisplayAlerts = false;
            try
            {
                //need to exe like %'c:\...\...\xx.mac' "99000R99" "1"
                string macro     = "c:\\vm\\test.mac";
                string robotname = "24010R01";
                string appl      = "Hand";
                string subgroup  = "Clamp";

                MtbProject.ExecuteCommand("%'" + macro + "' \"" + robotname + "%\" \"" + appl + "%\" \"" + subgroup + "%\"");
                //MtbProject.ExecuteCommand("%'" + textBoxMacro.Text + "' \"" + textBoxRobot.Text + "\"");
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            textBoxOutput.Text = "Commands count: " + MtbProject.Commands.Count + Environment.NewLine;
            for (int i = 1; i <= MtbProject.Commands.Count; i++)
            {
                textBoxOutput.Text += "*******************************************************************************" + Environment.NewLine;
                textBoxOutput.Text += "*******************************************************************************" + Environment.NewLine;
                textBoxOutput.Text += "Command " + i + Environment.NewLine;
                textBoxOutput.Text += "Command name: " + MtbProject.Commands.Item(i).Name + Environment.NewLine;
                textBoxOutput.Text += "Outputs count: " + MtbProject.Commands.Item(i).Outputs.Count + Environment.NewLine;
                for (int j = 1; j <= MtbProject.Commands.Item(i).Outputs.Count; j++)
                {
                    textBoxOutput.Text += "-------------------------------------------------------------------------------" + Environment.NewLine;
                    textBoxOutput.Text += "Output " + j + Environment.NewLine;
                    textBoxOutput.Text += "Output type: " + MtbProject.Commands.Item(i).Outputs.Item(j).OutputType + Environment.NewLine;
                    textBoxOutput.Text += "Output text: " + MtbProject.Commands.Item(i).Outputs.Item(j).Text + Environment.NewLine;
                    if (MtbProject.Commands.Item(i).Outputs.Item(j).OutputType == Mtb.MtbOutputTypes.OTGraph)
                    {
                        MtbProject.Commands.Item(i).Outputs.Item(j).Graph.CopyToClipboard();
                        pictureBoxChart.Image = Clipboard.GetImage();
                    }
                }
            }
            while (MtbProject.Commands.Count > 0)
            {
                MtbProject.Commands.Remove(1);
            }
        }
コード例 #3
0
 public void OnDisconnect()
 {
     // This method is called as Minitab is closing your add-in.
     GC.Collect();
     GC.WaitForPendingFinalizers();
     try
     {
         Marshal.FinalReleaseComObject(AddIn.gMtbApp);
         AddIn.gMtbApp = null;
     }
     catch
     {
     }
     return;
 }
コード例 #4
0
 public void OnConnect(Int32 iHwnd, Object pApp, ref Int32 iFlags)
 {
     // This method is called as Minitab is initializing your add-in.
     // The “iHwnd” parameter is the handle to the main Minitab window.
     // The “pApp” parameter is a reference to the “Minitab Automation object.”
     // You can hold onto either of these for use in your add-in.
     // “iFlags” is used to tell Minitab if your add-in has dynamic menus (i.e. should be reloaded each time
     // Minitab starts up).  Set Flags to 1 for dynamic menus and 0 for static.
     AddIn.gMtbApp = pApp as Mtb.Application;
     // This forces Minitab to retain all commands (even those run by the interactive user):
     AddIn.gMtbApp.Options.SaveCommands = true;
     // Static menus:
     iFlags = 0;
     return;
 }
コード例 #5
0
        static void Main(string[] args)
        {
            Mtb.Application mtbApp = new Mtb.Application();
            Mtb.Project     proj   = mtbApp.ActiveProject;
            Mtb.Worksheet   ws     = proj.ActiveWorksheet;
            mtbApp.UserInterface.Visible       = true;
            mtbApp.UserInterface.DisplayAlerts = false;

            proj.ExecuteCommand("rand 10 c1");
            for (int i = 0; i < 1100; i++)
            {
                Console.WriteLine(i + 1);
                proj.ExecuteCommand(string.Format("Note line {0}", i + 1));
                proj.Commands.Delete();
            }

            Console.WriteLine("Done");
            Console.ReadKey();
        }
コード例 #6
0
        public void GeneratePictures(Models.RowData modelRowData, System.Windows.Forms.TextBox textBox)
        {
            try
            {
                foreach (Process proc in Process.GetProcessesByName("Mtb"))
                {
                    proc.Kill();
                }
            }
            catch (Exception ex)
            {
            }

            Mtb.Application MtbApp = new Mtb.Application();
            MtbApp.UserInterface.Visible = true;
            //创建图片文件夹
            textBox.AppendText("Creating picture folder:" + modelRowData.filePath + "\r\n");
            if (!Directory.Exists(modelRowData.filePath))         //判断文件夹是否已经存在
            {
                Directory.CreateDirectory(modelRowData.filePath); //创建文件夹
            }
            textBox.AppendText("Generating pictures...\r\n");
            foreach (Models.Instance modelInstance in modelRowData.instances)
            {
                try
                {
                    textBox.AppendText("    " + modelInstance.title + "    ");
                    GeneratePicturesInstance(MtbApp, modelInstance, modelRowData);
                    textBox.AppendText("Succeed\r\n");
                }
                catch
                {
                    Mtb.Project MtbProj = MtbApp.ActiveProject;
                    MtbProj.Delete();
                    MtbApp.New();
                    textBox.AppendText("Failed\r\n");
                }
            }
            textBox.AppendText("Generate pictures succeed\r\n");
            MtbApp.Quit();
        }
コード例 #7
0
        /// <summary>
        /// 啟動 Minitab
        /// </summary>
        public static void Initialize()
        {
            List <int> procIDs = new List <int>();

            try
            {
                //建立一開始系統內包含 Minitab 的程序
                System.Diagnostics.Process[] initProc = System.Diagnostics.Process.GetProcessesByName("Mtb");

                if (initProc.Length > 0)
                {
                    procIDs = initProc.Select(x => x.MainWindowHandle.ToInt32()).ToList();
                }

                bool isNew = false;
                while (!isNew) //判斷現在是否有以視窗模式開啟的 Minitab
                {
                    App = new Mtb.Application();
                    if (procIDs.Count > 0 && procIDs.Contains(App.Handle))
                    {
                        isNew = false;
                    }
                    else
                    {
                        isNew = true;
                    }
                }
                App.UserInterface.DisplayAlerts = false;
                App.UserInterface.Visible       = false;
                System.Diagnostics.Process[] finalProc = System.Diagnostics.Process.GetProcessesByName("Mtb");  //取得目前所有 Minitab 的程序
                int[] ids = finalProc.Where(x => !initProc.Any(y => y.Id == x.Id)).Select(x => x.Id).ToArray(); //只取得剛剛建立的程序,ID 會固定
                appID = ids[0];
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + "\r\n無法啟動 Minitab,請確認是否有安裝 Minitab 或有足夠的授權數");
            }
        }
コード例 #8
0
 /// <summary>
 /// 關閉 Minitab 程式
 /// </summary>
 public static void Quit()
 {
     try
     {
         App.Quit();
         System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName("Mtb");
         for (int i = proc.Length; i-- > 0;)
         {
             if (proc[i].Id == appID)
             {
                 proc[i].Kill();                      //只將目前使用的 Minitab 關掉
             }
         }
     }
     catch
     {
     }
     finally
     {
         App = null;
         GC.Collect();
     }
 }
コード例 #9
0
        public void GeneratePicturesInstance(Mtb.Application MtbApp, Models.Instance modelInstance, Models.RowData modelRowData)
        {
            Mtb.Project MtbProj = MtbApp.ActiveProject;

            parseColumn(modelInstance, modelRowData);
            //计算标准差
            CalculateSTDVE(column3, modelInstance);

            Mtb.Columns MtbColumns = MtbProj.ActiveWorksheet.Columns;
            Mtb.Column  MtbColumn1 = MtbColumns.Add(null, null, 1);
            MtbColumn1.SetData(column1.ToArray());

            Mtb.Column MtbColumn2 = MtbColumns.Add(null, null, 1);
            MtbColumn2.SetData(column2.ToArray());

            Mtb.Column MtbColumn3 = MtbColumns.Add(null, null, 1);
            MtbColumn3.SetData(column3.ToArray());

            try
            {
                string imgPath = Path.Combine(modelRowData.filePath, parseFileName(modelInstance.title) + " Process Capability");
                string lspec   = Double.IsNaN(modelInstance.LCL) ? "" : "Lspec " + modelInstance.LCL.ToString("f3") + ";";
                string uspec   = Double.IsNaN(modelInstance.UCL) ? "" : "Uspec " + modelInstance.UCL.ToString("f3") + ";";
                MtbProj.ExecuteCommand(" Capa C3 " + column1.Count + ";  " + lspec + uspec + "   Pooled;   AMR;   UnBiased;   OBiased;   Toler 6;   Within;   Percent;   Title \"" + getPictureTitle(0, modelInstance) + "\";   CStat.");
                Mtb.Graph MtbGraph = MtbProj.Commands.Item(MtbProj.Commands.Count).Outputs.Item(1).Graph;
                MtbGraph.SaveAs(imgPath, true, Mtb.MtbGraphFileTypes.GFPNGHighColor, 768, 531);
                modelInstance.pictures.Add(imgPath + ".png");
            }
            catch
            {
                modelInstance.pictures.Add(null);
            }

            try
            {
                string imgPath = Path.Combine(modelRowData.filePath, parseFileName(modelInstance.title) + " Individual Polt");
                MtbProj.ExecuteCommand("  Indplot ( C3 ) * C1;   Title \"" + getPictureTitle(1, modelInstance) + "\";   Individual.");
                Mtb.Graph MtbGraph2 = MtbProj.Commands.Item(MtbProj.Commands.Count).Outputs.Item(1).Graph;
                MtbGraph2.SaveAs(imgPath, true, Mtb.MtbGraphFileTypes.GFPNGHighColor, 768, 531);
                modelInstance.pictures.Add(imgPath + ".png");
            }
            catch
            {
                modelInstance.pictures.Add(null);
            }
            try
            {
                string imgPath = Path.Combine(modelRowData.filePath, parseFileName(modelInstance.title) + " Scatter Plot");
                MtbProj.ExecuteCommand("  Plot C3*C2;   Symbol C1;   Title \"" + getPictureTitle(2, modelInstance) + "\";   JITTER.");
                Mtb.Graph MtbGraph3 = MtbProj.Commands.Item(MtbProj.Commands.Count).Outputs.Item(1).Graph;
                MtbGraph3.SaveAs(imgPath, true, Mtb.MtbGraphFileTypes.GFPNGHighColor, 768, 531);
                modelInstance.pictures.Add(imgPath + ".png");
            }
            catch
            {
                modelInstance.pictures.Add(null);
            }
            try
            {
                string imgPath = Path.Combine(modelRowData.filePath, parseFileName(modelInstance.title) + " Probability Plot");
                MtbProj.ExecuteCommand(" PPlot C3;   Normal;   Symbol;   FitD;     NoCI;   Grid 2;   Grid 1;   MGrid 1;   Title \"" + getPictureTitle(3, modelInstance) + "\".");
                Mtb.Graph MtbGraph4 = MtbProj.Commands.Item(MtbProj.Commands.Count).Outputs.Item(1).Graph;
                MtbGraph4.SaveAs(imgPath, true, Mtb.MtbGraphFileTypes.GFPNGHighColor, 768, 531);
                modelInstance.pictures.Add(imgPath + ".png");
            }
            catch
            {
                modelInstance.pictures.Add(null);
            }
            MtbProj.Delete();
            MtbApp.New();
        }
コード例 #10
0
 internal FormGeoMean(ref Mtb.Application pApp)
 {
     InitializeComponent();
     AddIn.gMtbApp = pApp;
 }
コード例 #11
0
        public Dictionary <string, object> MtbAnalysis(string chartType, Dictionary <string, string> rules)
        {
            try
            {
                foreach (Process proc in Process.GetProcessesByName("Mtb"))
                {
                    proc.Kill();
                }
            }
            catch (Exception ex)
            {}
            System.IO.FileInfo imgFile = new System.IO.FileInfo(imgDir + this.controlId + "_" + chartType + ".PNG");
            if (imgFile.Exists)
            {
                imgFile.Delete();
            }

            Mtb.Application             MtbApp       = new Mtb.Application();
            Dictionary <string, object> resultObject = new Dictionary <string, object>();

            try
            {
                MtbApp.UserInterface.Visible = false;
                Mtb.Project MtbProj = MtbApp.ActiveProject;

                Mtb.Columns MtbColumns = MtbProj.ActiveWorksheet.Columns;
                //加载dt所有数据到mtb
                for (int i = 0; i < endColumn; i++)
                {
                    Mtb.Column MtbColumn1 = MtbColumns.Add(null, null, 1);
                    ArrayList  columnData = new ArrayList();
                    for (int j = 0; j < dt.Rows.Count; j++)
                    {
                        if (dt.Rows[j][i].ToString().Length < 1)
                        {
                            columnData.Add(DBNull.Value);
                        }
                        else
                        {
                            columnData.Add(dt.Rows[j][i]);
                        }
                    }
                    MtbColumn1.SetData(columnData.ToArray());
                }

                int rawColumnCount = MtbColumns.Count;

                //Minitab 控制图 or 能力分析命令。
                //命令先生成,先调用checkRule()方法检查规则数量,以及对应生成的检验结果列数
                string execAnalysis = this.GetExcuteCommands(chartType, rules);

                //Minitab 分析结果存储列命令
                string varCommand = this.GetVarCommands(chartType);

                if (!string.IsNullOrEmpty(varCommand))
                {
                    MtbProj.ExecuteCommand(varCommand);
                }
                if (!string.IsNullOrEmpty(execAnalysis))
                {
                    MtbProj.ExecuteCommandAsync(execAnalysis);
                }

                Mtb.Output MtbOut = null;
                try {
                    MtbOut = MtbProj.Commands.Item(MtbProj.Commands.Count).Outputs.Item(1);
                    Console.WriteLine("Normal output!Normal output!Normal output!");
                }
                catch (Exception ex)
                {
                    MtbOut = MtbProj.Commands.Item(MtbProj.Commands.Count).Outputs.Item(1);
                    Console.WriteLine("Unormal output!Unormal output!Unormal output!");
                }

                //Minitab 图形保存
                Mtb.Graph MtbGraph = MtbOut.Graph;
                MtbGraph.SaveAs(imgDir + this.controlId + "_" + chartType, true, Mtb.MtbGraphFileTypes.GFPNGHighColor, 790, 500);

                //Minitab 工作区表保存
                Mtb.Worksheet MtbSheet = MtbProj.ActiveWorksheet;
                MtbSheet.SaveAs(imgDir + this.controlId + "_" + chartType, true);

                for (int i = 1; i <= MtbSheet.Columns.Count; i++)
                {
                    resultObject.Add(MtbSheet.Columns.Item(i).Name, MtbSheet.Columns.Item(i).GetData());
                }
                if (chartType.Contains("Chart"))
                {
                    resultObject.Add("RuleOut", MtbProj.Commands.OutputDocument.Text);
                }
                MtbProj.Delete();
                MtbApp.Quit();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally { MtbApp.Quit(); }
            return(resultObject);
        }
コード例 #12
0
 internal FormDescribe(ref Mtb.Application pApp)
 {
     InitializeComponent();
     AddIn.gMtbApp = pApp;
 }
コード例 #13
0
ファイル: Program.cs プロジェクト: Yalibuda/Mtblib
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Mtb.Application mtbApp = new Mtb.Application();
            mtbApp.UserInterface.DisplayAlerts = false;
            mtbApp.UserInterface.Visible       = true;
            Mtb.Project   proj = mtbApp.ActiveProject;
            Mtb.Worksheet ws;
            try
            {
                proj.Worksheets.Open(@"C:\Users\Yalibuda\Desktop\data_16.mtw");
                ws = proj.ActiveWorksheet;
            }
            catch
            {
                mtbApp.Quit();
                return;
            }



            Mtb.Column rawDataCol = ws.Columns.Item("VALUE");
            double     mean       = Mtblib.Tools.MtbTools.MISSINGVALUE;
            double     stdev      = Mtblib.Tools.MtbTools.MISSINGVALUE;
            double     maximum    = Mtblib.Tools.MtbTools.MISSINGVALUE;
            double     minimum    = Mtblib.Tools.MtbTools.MISSINGVALUE;

            try
            {
                mean    = ((double[])rawDataCol.GetData()).Where(x => x < Mtblib.Tools.MtbTools.MISSINGVALUE).Average();
                stdev   = ((double[])rawDataCol.GetData()).Where(x => x < Mtblib.Tools.MtbTools.MISSINGVALUE).StdDev();
                maximum = ((double[])rawDataCol.GetData()).Where(x => x < Mtblib.Tools.MtbTools.MISSINGVALUE).Max();
                minimum = ((double[])rawDataCol.GetData()).Where(x => x < Mtblib.Tools.MtbTools.MISSINGVALUE).Min();
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }


            Console.WriteLine("Stdev:{0}", stdev);

            //double sstdev = ((double[])ws.Columns.Item("C10").GetData()).StdDev();
            //Console.Write(sstdev);
            //Chart barchart = new Chart(proj,ws);
            //barchart.Variables = "C10 C11";
            //barchart.BarsRepresent = Chart.ChartRepresent.TWO_WAY_TABLE;
            //barchart.GroupingVariables = "C2 C3";
            //barchart.Bar.GroupingBy = "C2 C3";
            //barchart.NoMissing = true;
            //barchart.NoEmpty = true;
            //string path2 = MtbTools.BuildTemporaryMacro("mycode.mtb", barchart.GetCommand());
            //proj.ExecuteCommand(string.Format("% \"{0}\" 1", path2));



            //proj.Worksheets.Open(@"D:\Dropbox\Workspace\Test\test20160611.mtw");
            //proj.Worksheets.Open(@"D:\Dropbox\Workspace\03.PFG\06.Dataset\熔爐資料\FurnWall.mtw");
            //proj.Worksheets.Open(@"D:\Dropbox\Workspace\Test\test20160810.mtw");
            //ws = proj.ActiveWorksheet;
            //Mtb.Column[] cols = new Mtb.Column[] {
            //    ws.Columns.Item("C1"),
            //    ws.Columns.Item("C2"),
            //    ws.Columns.Item("C3"),
            //    ws.Columns.Item("C4"),
            //    ws.Columns.Item("C5"),
            //    ws.Columns.Item("C6")
            //};

            //ws.Columns.Add().Name="xxx";
            //ws.Columns.Item("xxx").SetData("a", 1, 10);
            //System.Data.DataTable dt = Mtblib.Tools.MtbTools.GetDataTableFromMtbCols(cols);
            //System.Data.DataTable result = Mtblib.Tools.MtbTools.Apply(
            //    "C3", Mtblib.Tools.Arithmetic.NMiss, new string[] { "C1", "C2" }, dt);



            //proj.Worksheets.Open(@"D:\Dropbox\Workspace\03.PFG\06.Dataset\熔爐資料\FurnWall.mtw");
            //ws = proj.ActiveWorksheet;
            //double[] data = ws.Columns.Item("C5").GetData();
            //string[] name = ws.Columns.Item("C3").GetData();
            //DateTime[] timeorder = ws.Columns.Item("C4").GetData();
            //var data1 = data.Zip(name, (x, y) => new { Value = x, Name = y });
            //var datas = data1.Zip(timeorder, (x, y) => new { Value = x.Value, Name = x.Name, Time = y }).ToArray();
            //string num = "17";
            //var subdata = datas.Where(x => x.Name == num).Select(x => x.Value).ToArray();


            //Mtblib.Stat.ChangePoints.ChangePointInfo[] changePts = Mtblib.Stat.ChangePoints.Run(subdata);
            //System.Text.StringBuilder cmnd = new System.Text.StringBuilder();
            //cmnd.AppendLine("plot c5*c4;");
            //cmnd.AppendLine("symb;");
            //cmnd.AppendLine("conn;");
            //cmnd.AppendLine("Include;");
            //cmnd.AppendFormat("where \"c3=\"\"{0}\"\" \";\r\n",num);
            //dynamic xvalue = datas.Where(x => x.Name == num).Select(x => x.Time).ToArray();
            //double[] dxvalue;
            //if (xvalue is DateTime[])
            //{
            //    dxvalue = ((DateTime[])xvalue).Select(x => x.ToOADate()).ToArray();
            //}
            //else
            //{
            //    dxvalue = xvalue;
            //}
            //if (changePts != null)
            //{
            //    cmnd.AppendLine("refe 1 &");
            //    foreach (var item in changePts)
            //    {
            //        Console.WriteLine("Change Points={0}, Confidence level={1}", item.Index, item.ConfidenceLevel);
            //        cmnd.AppendFormat("{0} &\r\n", dxvalue[item.Index + 1].ToString());
            //    }
            //    cmnd.AppendLine(";");
            //}

            //cmnd.AppendFormat("title \"爐區={0}\";\r\n", num);
            //cmnd.AppendLine(".");
            //proj.ExecuteCommand(cmnd.ToString());



            //List<double[]> d = new List<double[]>();
            //d.Add(ws.Columns.Item("C3").GetData());
            //d.Add(ws.Columns.Item("C4").GetData());
            //d.Add(ws.Columns.Item("C5").GetData());
            //Mtblib.Tools.GScale[] gg = Mtblib.Tools.MtbTools.GetMinitabGScaleInfo(d, proj, ws);

            // Test
            //Mtb.Application mtbApp = new Mtb.Application();
            //mtbApp.UserInterface.Visible = true;
            //mtbApp.UserInterface.DisplayAlerts = false;
            //Mtb.Project proj = mtbApp.ActiveProject;
            // summary data
            //proj.Worksheets.Open(@"D:\Dropbox\Workspace\01.chipMOS\06.Dataset\Top 3 Cust.mtw");
            // stacked data
            //proj.Worksheets.Open(@"D:\Dropbox\Workspace\Test\test20160611.mtw");
            //Mtb.Worksheet ws = proj.ActiveWorksheet;
            // count data
            //proj.Worksheets.Open(@"D:\Dropbox\Workspace\Test\test20160628.mtw");
            //Mtb.Worksheet ws = proj.ActiveWorksheet;

            ////Scatter plot
            //Plot p = new Plot(proj, ws);
            //p.YVariables = "C4 C5";
            //p.XVariables = "C3";
            //p.GraphType = Plot.MultipleGraphType.Overlay;
            //p.YScale.SecScale.Variable = "C5";
            //p.YScale.SecScale.Label.Text= "HEHEHE";
            //p.YScale.Label.Text = "AAAAA";
            //p.XScale.Ticks.SetLabels(new string[] { "\"A\"","\"B\"" });
            //p.Connectline.Visible = true;
            //Console.WriteLine(p.GetCommand());
            //proj.ExecuteCommand(p.GetCommand());



            //HighlevelBarLinePlot hchart = new HighlevelBarLinePlot(proj,ws);
            //hchart.chart.Variables = "C3";
            //hchart.chart.GroupingVariables = "C1 C2";
            //hchart.chart.Bar.GroupingBy = "C2";
            //hchart.chart.FuncType = Chart.ChartFunctionType.MEAN;
            //hchart.chart.Title.Text = "AAA";
            //hchart.chart.XScale.Ticks.TShow = 1;
            //hchart.Run();


            // Chart
            //using (Chart barchart = new Chart(proj, ws))
            //{
            //    // Chart 的基本設定 (Two-way table)
            //    //barchart.BarsRepresent = Chart.ChartRepresent.TWO_WAY_TABLE;
            //    //barchart.Variables = "C4-C7";
            //    //barchart.GroupingVariables = "C1";

            //    //Chart 的基本設定 (stacked data)
            //    //barchart.FuncType = Chart.ChartFunctionType.MEAN;
            //    //barchart.BarsRepresent = Chart.ChartRepresent.A_FUNCTION_OF_A_VARIABLE;
            //    //barchart.Variables = "C3";
            //    //barchart.GroupingVariables = "C1-C2";

            //    //Chart 的基本設定 (count data)
            //    barchart.BarsRepresent = Chart.ChartRepresent.COUNT_OF_UNIQUE_VALUES;
            //    barchart.Variables = "C1";
            //    barchart.GroupingVariables = "C2";

            //    barchart.AdjDatlabAtStackBar = true;
            //    barchart.DataLabel.Visible = true;
            //    barchart.DataLabel.DatlabType = Datlab.DisplayType.Column;
            //    barchart.StackType = Chart.ChartStackType.Stack;
            //    barchart.XScale.Label.Text = "AAAAA";
            //    barchart.XScale.Ticks.TShow = 1;
            //    barchart.YScale.Label.Text = "BBBB";
            //    barchart.Bar.AssignAttributeByVariables = true;
            //    //barchart.Panel.PaneledBy = "C1";
            //    //barchart.Panel.RowColumn = new int[] { 3, 1 };
            //    barchart.FootnoteLst.Add(new Footnote() { Text = "CCCCC" });
            //    //barchart.FigureRegion.SetCoordinate(0, 1, 0, 0.6);
            //    barchart.Title.Visible = false;
            //    barchart.Title.Text = "xxxx";
            //    barchart.ShowSeparateSubTitle = false;
            //    barchart.ShowPersonalSubTitle = false;
            //    barchart.XScale.Refes.Values = 1.5;
            //    barchart.XScale.Refes.Labels = "\"AAAA\"";
            //    barchart.YScale.Refes.Values = new double[]{100,120};
            //    barchart.YScale.Refes.Color = new int[] { 3, 4 };

            //    string path1 = MtbTools.BuildTemporaryMacro("testchart.mac", barchart.GetCommand());

            //    System.Text.StringBuilder cmnd = new System.Text.StringBuilder();
            //    cmnd.AppendFormat("%\"{0}\" {1};\r\n", path1,
            //        string.Join(" &\r\n", ((Mtb.Column[])barchart.Variables).Select(x => x.SynthesizedName).ToArray())
            //        );
            //    if (barchart.GroupingVariables != null)
            //    {
            //        cmnd.AppendFormat("group {0};\r\n",
            //        string.Join(" &\r\n", ((Mtb.Column[])barchart.GroupingVariables).Select(x => x.SynthesizedName).ToArray())
            //        );
            //    }
            //    if (barchart.Panel.PaneledBy != null)
            //    {
            //        cmnd.AppendFormat("pane {0};\r\n",
            //        string.Join(" &\r\n", (string[])barchart.Panel.PaneledBy)
            //        );
            //    }
            //    if (barchart.DataLabel.LabelColumn != null)
            //    {
            //        cmnd.AppendFormat("datlab {0};\r\n", barchart.DataLabel.LabelColumn);
            //    }
            //    cmnd.Append(".");
            //    string path2 = MtbTools.BuildTemporaryMacro("mycode.mtb", cmnd.ToString());
            //    proj.ExecuteCommand(string.Format("exec \"{0}\" 1", path2));
            //}



            ////Boxplot
            //BoxPlot boxplot = new BoxPlot(proj, ws);
            //boxplot.Mean.Visible = true;
            //boxplot.Mean.Type = 6;
            //boxplot.Mean.Color = MtbColor.DarkSkyBlue;
            //boxplot.CMean.Visible = true;
            //boxplot.Individual.Visible = true;
            //boxplot.IQRBox.Visible = false;
            //boxplot.Whisker.Visible = false;
            //boxplot.Outlier.Visible = false;
            //boxplot.Variables = "C3";
            //boxplot.GroupingVariables = "C1 C2";
            //boxplot.XScale.Label.Visible = false;
            //boxplot.XScale.Ticks.TShow = new int[] { 1, 2 };
            //boxplot.XScale.Ticks.HideAllTick = true;
            //boxplot.FootnoteLst.Add(
            //    new Footnote()
            //    {
            //        Text = "AAAAAA"
            //    });
            //boxplot.MeanDatlab.Visible = true;
            //LabelPosition lpos = new LabelPosition(1, "");
            //boxplot.MeanDatlab.PosititionList.Add(lpos);
            ////boxplot.GraphPath = @"D:\test.jpg";
            //boxplot.GraphRegion.SetCoordinate(10, 4);
            //boxplot.Title.Text = "BoxxxxxPlot";
            //boxplot.FigureRegion.SetCoordinate(0, 1, 0.6, 1);

            //System.Text.StringBuilder cmnd = new System.Text.StringBuilder();
            //cmnd.AppendLine("layout.");
            //cmnd.Append(barchart.GetCommand());
            //cmnd.Append(boxplot.GetCommand());
            //cmnd.AppendLine("endl");
            //proj.ExecuteCommand(cmnd.ToString());

            //proj.ExecuteCommand(boxplot.GetCommand() + ".");
            //Datlab dd = new Datlab();



            //string text = "C1-C5";
            //Regex regex = new Regex(@"('.*?'|C[\d]+)-('.*?'|C[\d]+)");
            //if (regex.IsMatch(text))
            //{
            //    MatchCollection mm = regex.Matches(text);

            //    foreach (Match m in mm)
            //    {
            //        for (int i = 0; i < m.Groups.Count; i++)
            //        {
            //            Console.WriteLine(m.Groups[i].Value);
            //        }
            //    }
            //}



            Application.Run(new Form1());
        }