Exemplo n.º 1
0
    //------------------------------------------------------------------------------
    //  Explicit Activation
    //      This entry point is used to activate the application explicitly
    //------------------------------------------------------------------------------
    public static int Main(string[] args)
    {
        int retValue = 0;

        try
        {
            theProgram = new Program();

            Session theSession  = Session.GetSession();
            Part    workPart    = theSession.Parts.Work;
            Part    displayPart = theSession.Parts.Display;

            int module_id;
            theUfSession.UF.AskApplicationModule(out module_id);
            if (module_id != UFConstants.UF_APP_DRAFTING)
            {
                MessageBox.Show("請先轉換為製圖模組後再執行!");
                return(retValue);
            }

            bool status, Is_Keep;

            //抓取目前圖紙數量和Tag
            //取得全部尺寸資料,並整理出尺寸落在的圖紙&尺寸設定的自定義泡泡再填入Panel中(當使用者點自定義時使用)
            int          SheetCount  = 0;
            NXOpen.Tag[] SheetTagAry = null;
            theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry);
            Dictionary <NXObject, Sheet_DefineNum> DicUserDefine = new Dictionary <NXObject, Sheet_DefineNum>();
            for (int i = 0; i < SheetCount; i++)
            {
                NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                CurrentSheet.Open();
                CurrentSheet.View.UpdateDisplay();
                NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray();
                GetUserDefineData(SheetObj, CurrentSheet.Name, ref DicUserDefine);
            }

            NXOpen.Drawings.DrawingSheet DefaultSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0]);
            DefaultSheet.Open();

            Application.EnableVisualStyles();
            CreateBallonDlg cCreateBallonDlg = new CreateBallonDlg(DicUserDefine);
            FormUtilities.ReparentForm(cCreateBallonDlg);
            System.Windows.Forms.Application.Run(cCreateBallonDlg);
            if (cCreateBallonDlg.DialogResult == DialogResult.Yes)
            {
                Is_Keep = cCreateBallonDlg.Is_Keep;
                cCreateBallonDlg.Dispose();
            }
            else
            {
                ((NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0])).Open();
                cCreateBallonDlg.Dispose();
                theProgram.Dispose();
                return(retValue);
            }


            #region 前置處理
            string         Is_Local        = Environment.GetEnvironmentVariable("UGII_ENV_FILE");
            CoordinateData cCoordinateData = new CoordinateData();
            if (Is_Local != null)
            {
                //取得圖紙範圍資料Data
                status = CaxGetDatData.GetDraftingCoordinateData(out cCoordinateData);
                if (!status)
                {
                    return(retValue);
                }
            }
            else
            {
                string DraftingCoordinate_dat  = "DraftingCoordinate.dat";
                string DraftingCoordinate_Path = string.Format(@"{0}\{1}", "D:", DraftingCoordinate_dat);
                CaxPublic.ReadCoordinateData(DraftingCoordinate_Path, out cCoordinateData);
            }

            //圖紙長、高
            double SheetLength = 0;
            double SheetHeight = 0;


            //取得最後一顆泡泡的數字
            int MaxBallonNum;
            try
            {
                MaxBallonNum = Convert.ToInt32(workPart.GetStringAttribute(CaxME.DimenAttr.BallonNum));
            }
            catch (System.Exception ex)
            {
                MaxBallonNum = 0;
            }
            #endregion

            //重新產生泡泡
            if (Is_Keep == false)
            {
                #region 刪除全部泡泡
                IdSymbolCollection BallonCollection = workPart.Annotations.IdSymbols;
                IdSymbol[]         BallonAry        = BallonCollection.ToArray();
                foreach (IdSymbol i in BallonAry)
                {
                    try
                    {
                        i.GetStringAttribute("BalloonAtt");
                    }
                    catch (System.Exception ex)
                    {
                        continue;
                    }
                    CaxPublic.DelectObject(i);
                }
                workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "BALLONNUM");
                #endregion


                #region 存DicDimenData(string=檢具名稱,DimenData=尺寸物件、泡泡座標)
                DefineParam.DicDimenData = new Dictionary <string, List <DimenData> >();
                for (int i = 0; i < SheetCount; i++)
                {
                    //打開Sheet並記錄所有OBJ
                    NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                    //string SheetName = "S" + (i + 1).ToString();
                    //CaxME.SheetRename(CurrentSheet, SheetName);
                    CurrentSheet.Open();

                    if (i == 0)
                    {
                        DefineParam.FirstDrawingSheet = CurrentSheet;
                    }

                    //取得圖紙長、高
                    SheetLength = CurrentSheet.Length;
                    SheetHeight = CurrentSheet.Height;

                    //DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects();
                    NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray();
                    foreach (NXObject singleObj in SheetObj)
                    {
                        #region 刪除尺寸數量產生的文字(ex:a-c)
                        string dicount = "", chekcLevel = "";
                        try
                        {
                            dicount = singleObj.GetStringAttribute(CaxME.DimenAttr.DiCount);
                        }
                        catch (System.Exception ex)
                        {
                            dicount = "";
                        }
                        try
                        {
                            chekcLevel = singleObj.GetStringAttribute(CaxME.DimenAttr.CheckLevel);
                        }
                        catch (System.Exception ex)
                        {
                            chekcLevel = "";
                        }
                        if (dicount != "" && chekcLevel == "")
                        {
                            CaxPublic.DelectObject(singleObj);
                        }
                        #endregion

                        string Gauge = "", AssignExcelType = "";
                        #region 判斷是否有屬性,沒有屬性就跳下一個
                        try{ AssignExcelType = singleObj.GetStringAttribute(CaxME.DimenAttr.AssignExcelType); }
                        catch (System.Exception ex) { continue; }
                        try{ Gauge = singleObj.GetStringAttribute(CaxME.DimenAttr.Gauge); }
                        catch (System.Exception ex) { }
                        #endregion

                        //事先塞入該尺寸所在Sheet
                        singleObj.SetAttribute("SheetName", CurrentSheet.Name);

                        //string DimeType = singleObj.GetType().ToString();
                        CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate();
                        //GetTextBoxCoordinate(DimeType, singleObj, out cBoxCoordinate);

                        //可以將NXOpen直接轉型成Annotation
                        CaxME.GetTextBoxCoordinate(((NXOpen.Annotations.Annotation)singleObj).Tag, out cBoxCoordinate);

                        #region 計算泡泡座標
                        DimenData sDimenData = new DimenData();
                        sDimenData.Obj          = singleObj;
                        sDimenData.CurrentSheet = CurrentSheet;
                        Functions.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData);
                        #endregion

                        if (Gauge != "")
                        {
                            List <DimenData> ListDimenData = new List <DimenData>();
                            status = DefineParam.DicDimenData.TryGetValue(Gauge, out ListDimenData);
                            if (!status)
                            {
                                ListDimenData = new List <DimenData>();
                            }
                            ListDimenData.Add(sDimenData);
                            DefineParam.DicDimenData[Gauge] = ListDimenData;
                        }
                    }
                }
                #endregion

                //插入泡泡
                int BallonNum = 0;
                InsertBallon(ref BallonNum, cCoordinateData, SheetHeight, SheetLength, "BalloonAtt");

                //將最後一顆泡泡的數字插入零件中
                workPart.SetAttribute(CaxME.DimenAttr.BallonNum, BallonNum.ToString());
            }
            //保留泡泡
            else
            {
                #region 存DicDimenData(string=檢具名稱,DimenData=尺寸物件、泡泡座標)
                DefineParam.DicDimenData = new Dictionary <string, List <DimenData> >();
                for (int i = 0; i < SheetCount; i++)
                {
                    //打開Sheet並記錄所有OBJ
                    NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                    CurrentSheet.Open();

                    if (i == 0)
                    {
                        DefineParam.FirstDrawingSheet = CurrentSheet;
                    }

                    //取得圖紙長、高
                    SheetLength = CurrentSheet.Length;
                    SheetHeight = CurrentSheet.Height;

                    //DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects();
                    NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray();
                    foreach (NXObject singleObj in SheetObj)
                    {
                        //判斷是否取到舊的尺寸,如果是就跳下一個
                        string OldBallonNum = "";
                        try
                        {
                            OldBallonNum = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonNum);
                            continue;
                        }
                        catch (System.Exception ex) {  }

                        //判斷是否有屬性,沒有屬性就跳下一個
                        string Gauge = "", AssignExcelType = "";
                        try { AssignExcelType = singleObj.GetStringAttribute(CaxME.DimenAttr.AssignExcelType); }
                        catch (System.Exception ex) { continue; }

                        try { Gauge = singleObj.GetStringAttribute(CaxME.DimenAttr.Gauge); }
                        catch (System.Exception ex) { }

                        //事先塞入該尺寸所在Sheet
                        singleObj.SetAttribute("SheetName", CurrentSheet.Name);

                        //string DimeType = "";
                        //DimeType = singleObj.GetType().ToString();
                        CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate();

                        //GetTextBoxCoordinate(DimeType, singleObj, out cBoxCoordinate);
                        //CaxLog.ShowListingWindow(cBoxCoordinate.lower_left[0].ToString());
                        CaxME.GetTextBoxCoordinate(((NXOpen.Annotations.Annotation)singleObj).Tag, out cBoxCoordinate);
                        //CaxLog.ShowListingWindow(cBoxCoordinate.lower_left[0].ToString());
                        #region 計算泡泡座標
                        DimenData sDimenData = new DimenData();
                        sDimenData.Obj          = singleObj;
                        sDimenData.CurrentSheet = CurrentSheet;
                        Functions.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData);
                        #endregion

                        if (Gauge != "")
                        {
                            List <DimenData> ListDimenData = new List <DimenData>();
                            status = DefineParam.DicDimenData.TryGetValue(Gauge, out ListDimenData);
                            if (!status)
                            {
                                ListDimenData = new List <DimenData>();
                            }
                            ListDimenData.Add(sDimenData);
                            DefineParam.DicDimenData[Gauge] = ListDimenData;
                        }
                    }
                }
                #endregion

                if (DefineParam.DicDimenData.Count != 0)
                {
                    //插入泡泡
                    InsertBallon(ref MaxBallonNum, cCoordinateData, SheetHeight, SheetLength, "BalloonAtt");

                    //將最後一顆泡泡的數字插入零件中
                    workPart.SetAttribute(CaxME.DimenAttr.BallonNum, MaxBallonNum.ToString());
                }
            }

            //切回第一張Sheet
            DefineParam.FirstDrawingSheet.Open();

            MessageBox.Show("完成");
            theProgram.Dispose();
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----
            CaxLog.ShowListingWindow(ex.ToString());
        }
        return(retValue);
    }
Exemplo n.º 2
0
        private void AssignGaugeDlg_Load(object sender, EventArgs e)
        {
            try
            {
                int module_id;
                theUfSession.UF.AskApplicationModule(out module_id);
                if (module_id != UFConstants.UF_APP_DRAFTING)
                {
                    MessageBox.Show("請先轉換為製圖模組後再執行!");
                    this.Close();
                }

                Is_Local = Environment.GetEnvironmentVariable("UGII_ENV_FILE");
                if (Is_Local != null)
                {
                    //取得AssignGaugeData
                    status = CaxGetDatData.GetAssignGaugeData(out AGData);
                    if (!status)
                    {
                        CaxLog.ShowListingWindow("GetAssignGaugeData失敗,請檢查MEConfig是否有檔案");
                        return;
                    }

                    //取得圖紙範圍資料Data
                    status = CaxGetDatData.GetDraftingCoordinateData(out cCoordinateData);

                    //取得PRODUCT資料(未完成,資料庫還沒建立)
                    ISession            session    = MyHibernateHelper.SessionFactory.OpenSession();
                    IList <Sys_Product> sysProduct = session.QueryOver <Sys_Product>().List <Sys_Product>();
                    foreach (Sys_Product i in sysProduct)
                    {
                        listProduct.Add(i.productName);
                    }
                }
                else
                {
                    //取得AssignGaugeData
                    string AssignGaugeData_dat  = "AssignGaugeData.dat";
                    string AssignGaugeData_Path = string.Format(@"{0}\{1}", "D:", AssignGaugeData_dat);
                    AGData = System.IO.File.ReadAllLines(AssignGaugeData_Path);

                    //取得圖紙範圍資料Data
                    string DraftingCoordinate_dat  = "DraftingCoordinate.dat";
                    string DraftingCoordinate_Path = string.Format(@"{0}\{1}", "D:", DraftingCoordinate_dat);
                    if (!System.IO.File.Exists(DraftingCoordinate_Path))
                    {
                        MessageBox.Show("路徑:" + DraftingCoordinate_Path + "不存在");
                        return;
                    }

                    CaxPublic.ReadCoordinateData(DraftingCoordinate_Path, out cCoordinateData);
                }
                //預設關閉選擇物件
                //SelectDimen.Enabled = false;

                #region 存AGData到DicGaugeData中
                foreach (string Row in AGData)
                {
                    string[] splitRow = Row.Split(',');
                    if (splitRow.Length == 0)
                    {
                        continue;
                    }

                    GaugeData cGaugeData = new GaugeData();
                    status = DicGaugeData.TryGetValue(splitRow[1], out cGaugeData);
                    if (status)
                    {
                        continue;
                    }

                    cGaugeData       = new GaugeData();
                    cGaugeData.Color = splitRow[0];
                    try
                    {
                        cGaugeData.EngName = splitRow[2];
                    }
                    catch (System.Exception ex)
                    {
                        cGaugeData.EngName = "";
                    }
                    DicGaugeData.Add(splitRow[1], cGaugeData);
                }
                #endregion

                //填檢具到下拉選單中
                //Gauge.Items.Add("");
                //Gauge.Items.AddRange(DicGaugeData.Keys.ToArray());
                //填檢具到SelfCheck下拉選單中
                //SelfCheckGauge.Items.Add("");
                //foreach (KeyValuePair<string,GaugeData> kvp in DicGaugeData)
                //{
                //    if (kvp.Key.Contains("T"))
                //    {
                //        continue;
                //    }
                //    SelfCheckGauge.Items.Add(kvp.Key);
                //}

                //取得sheet並填入下拉選單中
                int          SheetCount  = 0;
                NXOpen.Tag[] SheetTagAry = null;
                theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry);
                for (int i = 0; i < SheetCount; i++)
                {
                    NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                    ListSheet.Items.Add(CurrentSheet.Name);
                }

                //預設開啟sheet1圖紙
                NXOpen.Drawings.DrawingSheet DefaultSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0]);
                ListSheet.Text = DefaultSheet.Name;

                //取得圖紙長寬
                SheetLength = DefaultSheet.Length;
                SheetHeight = DefaultSheet.Height;

                //填入IQC、IPQC與SelfCheck的單位
                //string[] CheckUnits = new string[] { "HRS", "PCS", "100%" };
                //Freq_Units.Items.AddRange(CheckUnits.ToArray());
                //SelfCheck_Units.Items.AddRange(CheckUnits.ToArray());
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 3
0
        private void AssignGaugeDlg_Load(object sender, EventArgs e)
        {
            /*
             * //取回目前泡泡最大值
             * try
             * {
             *  BallonNum = Convert.ToInt32(workPart.GetStringAttribute(CaxME.DimenAttr.BallonNum));
             * }
             * catch (System.Exception ex)
             * {
             *  BallonNum = 0;
             * }
             */

            //預設關閉選擇物件
            SelectObject.Enabled = false;

            //取得AssignGaugeData
            string[] AGData = new string[] { };
            status = CaxGetDatData.GetAssignGaugeData(out AGData);
            if (!status)
            {
                CaxLog.ShowListingWindow("GetAssignGaugeData失敗,請檢查MEConfig是否有檔案");
                return;
            }

            #region 存AGData到DicGaugeData中
            foreach (string Row in AGData)
            {
                string[] splitRow = Row.Split(',');
                if (splitRow.Length == 0)
                {
                    continue;
                }

                GaugeData cGaugeData = new GaugeData();
                status = DicGaugeData.TryGetValue(splitRow[1], out cGaugeData);
                if (status)
                {
                    continue;
                }

                cGaugeData       = new GaugeData();
                cGaugeData.Color = splitRow[0];
                try
                {
                    cGaugeData.EngName = splitRow[2];
                }
                catch (System.Exception ex)
                {
                    cGaugeData.EngName = "";
                }
                DicGaugeData.Add(splitRow[1], cGaugeData);
            }
            #endregion

            //填檢具到IQC、IPQC下拉選單中
            Gauge.Items.Add("");
            Gauge.Items.AddRange(DicGaugeData.Keys.ToArray());
            //填檢具到SelfCheck下拉選單中
            SelfCheckGauge.Items.Add("");
            foreach (KeyValuePair <string, GaugeData> kvp in DicGaugeData)
            {
                if (kvp.Key.Contains("T"))
                {
                    continue;
                }
                SelfCheckGauge.Items.Add(kvp.Key);
            }

            //取得sheet並填入下拉選單中
            int          SheetCount  = 0;
            NXOpen.Tag[] SheetTagAry = null;
            theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry);
            for (int i = 0; i < SheetCount; i++)
            {
                NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                ListSheet.Items.Add(CurrentSheet.Name);
            }

            //預設開啟sheet1圖紙
            NXOpen.Drawings.DrawingSheet DefaultSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0]);
            ListSheet.Text = DefaultSheet.Name;

            //取得圖紙長寬
            SheetLength = DefaultSheet.Length;
            SheetHeight = DefaultSheet.Height;

            //填入IQC、IPQC與SelfCheck的單位
            string[] CheckUnits = new string[] { "HRS", "PCS", "100%Check" };
            Freq_Units.Items.AddRange(CheckUnits.ToArray());
            SelfCheck_Units.Items.AddRange(CheckUnits.ToArray());

            //取得圖紙範圍資料Data
            CaxGetDatData.GetDraftingCoordinateData(out cCoordinateData);
        }
Exemplo n.º 4
0
        private void OK_Click(object sender, EventArgs e)
        {
            if (chb_keepOrigination.Checked == false && chb_Regeneration.Checked == false && chb_UserDefine.Checked == false)
            {
                this.Hide();
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Information, "請先選擇一個選項");
                this.Show();
                return;
            }
            if (chb_keepOrigination.Checked == true)
            {
                Is_Keep           = true;
                this.DialogResult = DialogResult.Yes;
                this.Close();
            }
            if (chb_Regeneration.Checked == true)
            {
                Is_Keep           = false;
                this.DialogResult = DialogResult.Yes;
                this.Close();
            }
            if (chb_UserDefine.Checked == true)
            {
                //判斷所有的泡泡是否有重複
                List <string> ListIsRepeat = new List <string>();
                foreach (GridRow i in SGC.PrimaryGrid.Rows)
                {
                    if (i.Cells["自定泡泡號"].Value.ToString() == "")
                    {
                        continue;
                    }
                    if (ListIsRepeat.Contains(i.Cells["自定泡泡號"].Value.ToString()))
                    {
                        MessageBox.Show("泡泡號【" + i.Cells["自定泡泡號"].Value.ToString() + "】重複,請重新檢查");
                        return;
                    }
                    else
                    {
                        ListIsRepeat.Add(i.Cells["自定泡泡號"].Value.ToString());
                    }
                }
                CoordinateData cCoordinateData = new CoordinateData();
                CaxGetDatData.GetDraftingCoordinateData(out cCoordinateData);

                //開始插入自定義泡泡
                foreach (GridRow i in SGC.PrimaryGrid.Rows)
                {
                    //判斷是否有舊的泡泡,如果舊泡泡與自定的相同,則跳下一個
                    //判斷是否有舊的泡泡,如果舊泡泡與自定的不相同,則先刪除泡泡再重新產生
                    //如有Dicount也要加入一起生成


                    //如果沒有自定泡泡就跳下一個row
                    if (i.Cells["自定泡泡號"].Value.ToString() == "")
                    {
                        //判斷是否需刪除已存在的泡泡
                        NXOpen.Drawings.DrawingSheet drawingSheet1 = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(i.Cells["尺寸位置"].Value.ToString());
                        string oldBalloon = "";
                        try
                        {
                            oldBalloon = ((NXObject)i.Cells["Dimension"].Value).GetStringAttribute(CaxME.DimenAttr.BallonNum);
                        }
                        catch (System.Exception ex)
                        {
                            continue;
                        }
                        NXObject[] SheetObj = CaxME.FindObjectsInView(drawingSheet1.View.Tag).ToArray();
                        CaxME.DeleteBallon(oldBalloon, SheetObj);
                        workPart.Views.Refresh();
                        //刪除屬性
                        ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.BallonNum);
                        ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.BallonLocation);
                        ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.SheetName);
                        continue;
                    }
                    //如果回傳False,表示舊泡泡=自定泡泡;如果回傳True,表示舊泡泡=\=自定泡泡
                    if (!JudgmentBalloon(i))
                    {
                        continue;
                    }
                    InsertBalloon(i, cCoordinateData);
                }
                if (exOnj != null)
                {
                    exOnj.Unhighlight();
                    workPart.Views.Refresh();
                }

                //(NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(ListSheet.Text)
                //((NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject("S1")).Open();
                this.Close();
            }
        }
        private void OK_Click(object sender, EventArgs e)
        {
            //抓取目前圖紙數量和Tag
            int SheetCount = 0;

            NXOpen.Tag[] SheetTagAry = null;
            theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry);
            //取得最後一顆泡泡的數字
            int MaxBallonNum;

            try
            {
                MaxBallonNum = Convert.ToInt32(workPart.GetStringAttribute(CaxME.DimenAttr.BallonNum));
            }
            catch (System.Exception ex)
            {
                MaxBallonNum = 0;
            }

            if (chb_Regeneration.Checked == true)
            {
                #region 刪除全部泡泡
                IdSymbolCollection BallonCollection = workPart.Annotations.IdSymbols;
                IdSymbol[]         BallonAry        = BallonCollection.ToArray();
                foreach (IdSymbol i in BallonAry)
                {
                    try
                    {
                        i.GetStringAttribute("BalloonAtt");
                    }
                    catch (System.Exception ex)
                    {
                        continue;
                    }
                    CaxPublic.DelectObject(i);
                }
                workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "BALLONNUM");
                #endregion

                for (int i = 0; i < SheetCount; i++)
                {
                    //打開Sheet並記錄所有OBJ
                    DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                    CurrentSheet.Open();
                    if (i == 0)
                    {
                        Variables.FirstDrawingSheet = CurrentSheet;
                    }

                    int        BallonNum = 0;
                    NXObject[] SheetObj  = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray();
                    foreach (NXObject singleObj in SheetObj)
                    {
                        string diCount = "", fixDiemnsion = "";
                        #region 刪除尺寸數量產生的文字(ex:a-c)
                        try
                        {
                            diCount = singleObj.GetStringAttribute(CaxME.DimenAttr.DiCount);
                        }
                        catch (System.Exception ex)
                        {
                            diCount = "";
                        }
                        try
                        {
                            fixDiemnsion = singleObj.GetStringAttribute(CaxME.DimenAttr.FixDimension);
                        }
                        catch (System.Exception ex)
                        {
                            fixDiemnsion = "";
                        }
                        if (diCount != "" && fixDiemnsion == "")
                        {
                            CaxPublic.DelectObject(singleObj);
                        }
                        #endregion

                        string AssignExcelType = "";
                        #region 判斷是否有屬性,沒有屬性就跳下一個
                        try { AssignExcelType = singleObj.GetStringAttribute(CaxME.DimenAttr.FixDimension); }
                        catch (System.Exception ex) { continue; }
                        #endregion


                        //事先塞入該尺寸所在Sheet
                        singleObj.SetAttribute("SheetName", CurrentSheet.Name);

                        CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate();
                        CaxME.GetTextBoxCoordinate(singleObj.Tag, out cBoxCoordinate);

                        #region 計算泡泡座標
                        CaxME.DimenData sDimenData = new CaxME.DimenData();
                        sDimenData.Obj          = singleObj;
                        sDimenData.CurrentSheet = CurrentSheet;
                        CaxME.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData);
                        #endregion

                        sDimenData.CurrentSheet.Open();

                        Point3d BallonLocation = new Point3d();
                        BallonLocation.X = sDimenData.LocationX;
                        BallonLocation.Y = sDimenData.LocationY;

                        BallonNum++;
                        InsertBalloon(BallonNum, diCount, BallonLocation);
                        singleObj.SetAttribute(CaxME.DimenAttr.BallonNum, BallonNum.ToString());
                    }


                    //將最後一顆泡泡的數字插入零件中
                    workPart.SetAttribute(CaxME.DimenAttr.BallonNum, BallonNum.ToString());
                }
            }
            else if (chb_keepOrigination.Checked == true)
            {
                for (int i = 0; i < SheetCount; i++)
                {
                    //打開Sheet並記錄所有OBJ
                    DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                    CurrentSheet.Open();
                    if (i == 0)
                    {
                        Variables.FirstDrawingSheet = CurrentSheet;
                    }

                    NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray();
                    foreach (NXObject singleObj in SheetObj)
                    {
                        //判斷是否取到舊的尺寸,如果是就跳下一個
                        string OldBallonNum = "";
                        try
                        {
                            OldBallonNum = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonNum);
                            continue;
                        }
                        catch (System.Exception ex) { }

                        string AssignExcelType = "";
                        #region 判斷是否有屬性,沒有屬性就跳下一個
                        try { AssignExcelType = singleObj.GetStringAttribute(CaxME.DimenAttr.FixDimension); }
                        catch (System.Exception ex) { continue; }
                        #endregion

                        //事先塞入該尺寸所在Sheet
                        singleObj.SetAttribute("SheetName", CurrentSheet.Name);

                        CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate();
                        CaxME.GetTextBoxCoordinate(singleObj.Tag, out cBoxCoordinate);

                        #region 計算泡泡座標
                        CaxME.DimenData sDimenData = new CaxME.DimenData();
                        sDimenData.Obj          = singleObj;
                        sDimenData.CurrentSheet = CurrentSheet;
                        CaxME.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData);
                        #endregion

                        sDimenData.CurrentSheet.Open();

                        Point3d BallonLocation = new Point3d();
                        BallonLocation.X = sDimenData.LocationX;
                        BallonLocation.Y = sDimenData.LocationY;

                        MaxBallonNum++;
                        string diCount = "";
                        try
                        {
                            diCount = singleObj.GetStringAttribute(CaxME.DimenAttr.DiCount);
                        }
                        catch (System.Exception ex)
                        {
                            diCount = "1";
                        }

                        InsertBalloon(MaxBallonNum, diCount, BallonLocation);
                        singleObj.SetAttribute(CaxME.DimenAttr.BallonNum, MaxBallonNum.ToString());
                    }
                    //將最後一顆泡泡的數字插入零件中
                    workPart.SetAttribute(CaxME.DimenAttr.BallonNum, MaxBallonNum.ToString());
                }
            }
            else if (chb_UserDefine.Checked == true)
            {
                //判斷所有的泡泡是否有重複
                List <string> ListIsRepeat = new List <string>();
                foreach (GridRow i in SGC.PrimaryGrid.Rows)
                {
                    if (i.Cells["自定泡泡號"].Value.ToString() == "")
                    {
                        continue;
                    }
                    if (ListIsRepeat.Contains(i.Cells["自定泡泡號"].Value.ToString()))
                    {
                        MessageBox.Show("泡泡號【" + i.Cells["自定泡泡號"].Value.ToString() + "】重複,請重新檢查");
                        return;
                    }
                    else
                    {
                        ListIsRepeat.Add(i.Cells["自定泡泡號"].Value.ToString());
                    }
                }
                CoordinateData cCoordinateData = new CoordinateData();
                CaxGetDatData.GetDraftingCoordinateData(out cCoordinateData);

                //開始插入自定義泡泡
                foreach (GridRow i in SGC.PrimaryGrid.Rows)
                {
                    //判斷是否有舊的泡泡,如果舊泡泡與自定的相同,則跳下一個
                    //判斷是否有舊的泡泡,如果舊泡泡與自定的不相同,則先刪除泡泡再重新產生
                    //如有Dicount也要加入一起生成


                    //如果沒有自定泡泡就跳下一個row
                    if (i.Cells["自定泡泡號"].Value.ToString() == "")
                    {
                        //判斷是否需刪除已存在的泡泡
                        NXOpen.Drawings.DrawingSheet drawingSheet1 = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(i.Cells["尺寸位置"].Value.ToString());
                        string oldBalloon = "";
                        try
                        {
                            oldBalloon = ((NXObject)i.Cells["Dimension"].Value).GetStringAttribute(CaxME.DimenAttr.BallonNum);
                        }
                        catch (System.Exception ex)
                        {
                            continue;
                        }
                        NXObject[] SheetObj = CaxME.FindObjectsInView(drawingSheet1.View.Tag).ToArray();
                        CaxME.DeleteBallon(oldBalloon, SheetObj);
                        workPart.Views.Refresh();
                        //刪除屬性
                        ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.BallonNum);
                        ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.BallonLocation);
                        ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.SheetName);
                        continue;
                    }
                    //如果回傳False,表示舊泡泡=自定泡泡;如果回傳True,表示舊泡泡=\=自定泡泡
                    if (!JudgmentBalloon(i))
                    {
                        continue;
                    }
                    InsertBalloon(i, cCoordinateData);
                }
                if (exOnj != null)
                {
                    exOnj.Unhighlight();
                    workPart.Views.Refresh();
                }
            }

            MessageBox.Show("完成!");
        }