コード例 #1
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();
        }
コード例 #2
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();
        }