private void OK_Click(object sender, EventArgs e) { try { if (Variables.SelDimensionAry.Length != 0) { int value; if (DiCount.Text == "" || !int.TryParse(DiCount.Text, out value)) { MessageBox.Show("尺寸數量不正確,請指定正整數"); return; } foreach (KeyValuePair <NXObject, string> kvp in Variables.DicSelDimension) { //改變標註尺寸顏色 CaxME.SetDimensionColor(kvp.Key, 186); //塞屬性 kvp.Key.SetAttribute(CaxME.DimenAttr.FixDimension, "1"); kvp.Key.SetAttribute(CaxME.DimenAttr.DiCount, DiCount.Text); } DiCount.Text = "1"; } if (Variables.CleanDimensionAry.Length != 0) { NXObject[] SheetObj = CaxME.FindObjectsInView(Variables.drawingSheet1.View.Tag).ToArray(); foreach (NXObject i in Variables.CleanDimensionAry) { //恢復原始顏色 CaxME.SetDimensionColor(i, 125); //取得泡泡資訊 string BallonNum = ""; try { BallonNum = i.GetStringAttribute(CaxME.DimenAttr.BallonNum); } catch (System.Exception ex) { BallonNum = ""; } if (BallonNum != "") { CaxME.DeleteFixBallon(BallonNum, SheetObj); } i.DeleteAllAttributesByType(NXObject.AttributeType.String); } } MessageBox.Show("設定完成!"); } catch (System.Exception ex) { MessageBox.Show("執行失敗,請聯繫開發工程師"); this.Close(); return; } }
private void FixCreateBalloonDlg_Load(object sender, EventArgs e) { #region 系統環境 Variables.Is_Local = Environment.GetEnvironmentVariable("UGII_ENV_FILE"); if (Variables.Is_Local == null) { MessageBox.Show("請先使用系統後再執行!"); this.Close(); return; } #endregion //抓取目前圖紙數量和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(); int count = 0; GridRow row = new GridRow(); foreach (KeyValuePair <NXObject, Sheet_DefineNum> kvp in DicUserDefine) { row = new GridRow(new object[SGC.PrimaryGrid.Columns.Count]); SGC.PrimaryGrid.Rows.Add(row); count = count + 1; row.Cells["序號"].Value = count; row.Cells["尺寸位置"].Value = kvp.Value.sheet; row.Cells["自定泡泡號"].Value = kvp.Value.defineNum; row.Cells["Dimension"].Value = kvp.Key; } }
private void OK_Click(object sender, EventArgs e) { if (IsAbsCheck) { foreach (NXObject i in SelDimensionAry) { i.SetAttribute("KC", "KeyChara."); } AbsCheDimen.Text = "Key Chara.(0)"; } else if (IsRemove) { foreach (KeyValuePair <NXObject, string> kvp in DicSelDimension) { //恢復原始顏色 string oldColor = "125"; CaxME.SetDimensionColor(kvp.Key, Convert.ToInt32(oldColor)); //取得泡泡資訊 string BallonNum = ""; try { BallonNum = kvp.Key.GetStringAttribute(CaxME.DimenAttr.BallonNum); } catch (System.Exception ex) { BallonNum = ""; } if (BallonNum != "") { //CaxME.DeleteBallon(BallonNum); } kvp.Key.DeleteAllAttributesByType(NXObject.AttributeType.String); } RepairDimen.Text = "Remove(0)"; } MessageBox.Show("設定成功"); }
private bool JudgmentBalloon(GridRow row) { string oldBalloon = ""; try { oldBalloon = ((NXObject)row.Cells["Dimension"].Value).GetStringAttribute(CaxME.DimenAttr.BallonNum); if (oldBalloon == row.Cells["自定泡泡號"].Value.ToString()) { return(false); } NXOpen.Drawings.DrawingSheet drawingSheet1 = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(row.Cells["尺寸位置"].Value.ToString()); NXObject[] SheetObj = CaxME.FindObjectsInView(drawingSheet1.View.Tag).ToArray(); CaxME.DeleteBallon(oldBalloon, SheetObj); workPart.Views.Refresh(); } catch (System.Exception ex) { oldBalloon = ""; } return(true); }
private bool InsertBalloon(int balloonNum, string diCount, Point3d BallonLocation) { try { double BallonNumSize = 0; //決定數字的大小 if (balloonNum <= 9) { BallonNumSize = 2.5; } else if (balloonNum > 9 && balloonNum <= 99) { BallonNumSize = 1.5; } else { BallonNumSize = 1; } NXObject balloonObj = null; CaxME.CreateBallonOnSheet(balloonNum.ToString(), BallonLocation, BallonNumSize, "BalloonAtt", out balloonObj); //如果大於1表示要插入a.b.c..... if (diCount != "1") { //文字座標 CaxME.BoxCoordinate sBoxCoordinate = new CaxME.BoxCoordinate(); CaxME.GetTextBoxCoordinate(balloonObj.Tag, out sBoxCoordinate); Point3d textCoord = new Point3d(sBoxCoordinate.lower_left[0] + 1.5, sBoxCoordinate.lower_left[1] - 1.5, 0); string countText = Convert.ToChar(65 + 0).ToString().ToLower() + "-" + Convert.ToChar(65 + Convert.ToInt32(diCount) - 1).ToString().ToLower(); CaxME.InsertDicountNote(balloonNum.ToString(), CaxME.DimenAttr.DiCount, countText, "1.8", textCoord); } } catch (System.Exception ex) { return(false); } return(true); }
private void Ins_OK_Click(object sender, EventArgs e) { try { status = DataChecked(); if (!status) { MessageBox.Show("Data檢查失敗"); return; } string AssignExcelType = ""; if (FAIcheckBox.Checked == true) { AssignExcelType = FAIcheckBox.Text; } if (IQCcheckBox.Checked == true) { AssignExcelType = IQCcheckBox.Text; } if (IPQCcheckBox.Checked == true) { AssignExcelType = IPQCcheckBox.Text; } if (FQCcheckBox.Checked == true) { AssignExcelType = FQCcheckBox.Text; } foreach (KeyValuePair <NXObject, string> kvp in DicSelDimension) { //取得原始顏色 int oldColor = CaxME.GetDimensionColor(kvp.Key); if (oldColor == -1) { oldColor = 125; } //取得檢具顏色 AssignGaugeDlg.GaugeData cGaugeData = new AssignGaugeDlg.GaugeData(); if (SelfCheckGauge.Text != "") { status = DicGaugeData.TryGetValue(SelfCheckGauge.Text, out cGaugeData); if (!status) { CaxLog.ShowListingWindow("此檢具資料可能有誤"); return; } } if (Gauge.Text != "") { status = DicGaugeData.TryGetValue(Gauge.Text, out cGaugeData); if (!status) { CaxLog.ShowListingWindow("此檢具資料可能有誤"); return; } } //改變標註尺寸顏色 CaxME.SetDimensionColor(kvp.Key, Convert.ToInt32(cGaugeData.Color)); //塞屬性 kvp.Key.SetAttribute(CaxME.DimenAttr.OldColor, oldColor.ToString());//舊顏色 kvp.Key.SetAttribute(CaxME.DimenAttr.AssignExcelType, AssignExcelType); if (Gauge.Text != "") { kvp.Key.SetAttribute(CaxME.DimenAttr.Gauge, Gauge.Text);//檢具名稱 } if (Freq_0.Text != "" & Freq_1.Text != "" & Freq_Units.Text != "") { kvp.Key.SetAttribute(CaxME.DimenAttr.Frequency, Freq_0.Text + "PC/" + Freq_1.Text + Freq_Units.Text);//頻率 } if (SelfCheckGauge.Text != "") { kvp.Key.SetAttribute("SelfCheckExcel", "SelfCheck"); kvp.Key.SetAttribute(CaxME.DimenAttr.SelfCheck_Gauge, SelfCheckGauge.Text); //檢具名稱 kvp.Key.SetAttribute(CaxME.DimenAttr.SelfCheck_Freq, SelfCheck_0.Text + "PC/" + SelfCheck_1.Text + SelfCheck_Units.Text); //SelfCheck } } //對零件塞上excelType屬性,說明此次尺寸是出哪一張excel(此屬性是給MEUpload時插入資料庫所使用) string excelType = ""; if (FAIcheckBox.Checked == true) { try { excelType = workPart.GetStringAttribute("ExcelType"); } catch (System.Exception ex) { excelType = ""; } if (excelType != "" && !excelType.Contains("FAI")) { excelType = excelType + "," + "FAI"; workPart.SetAttribute("ExcelType", excelType); } if (excelType == "") { workPart.SetAttribute("ExcelType", "FAI"); } } if (IQCcheckBox.Checked == true) { try { excelType = workPart.GetStringAttribute("ExcelType"); } catch (System.Exception ex) { excelType = ""; } if (excelType != "" && !excelType.Contains("IQC")) { excelType = excelType + "," + "IQC"; workPart.SetAttribute("ExcelType", excelType); } if (excelType == "") { workPart.SetAttribute("ExcelType", "IQC"); } } if (IPQCcheckBox.Checked == true) { try { excelType = workPart.GetStringAttribute("ExcelType"); } catch (System.Exception ex) { excelType = ""; } if (excelType != "" && !excelType.Contains("IPQC")) { excelType = excelType + "," + "IPQC"; workPart.SetAttribute("ExcelType", excelType); } if (excelType == "") { workPart.SetAttribute("ExcelType", "IPQC"); } } if (FQCcheckBox.Checked == true) { try { excelType = workPart.GetStringAttribute("ExcelType"); } catch (System.Exception ex) { excelType = ""; } if (excelType != "" && !excelType.Contains("FQC")) { excelType = excelType + "," + "FQC"; workPart.SetAttribute("ExcelType", excelType); } if (excelType == "") { workPart.SetAttribute("ExcelType", "FQC"); } } if (SelfCheckGauge.Text != "") { try { excelType = workPart.GetStringAttribute("ExcelType"); } catch (System.Exception ex) { excelType = ""; } if (excelType != "" && !excelType.Contains("SelfCheck")) { excelType = excelType + "," + "SelfCheck"; workPart.SetAttribute("ExcelType", excelType); } if (excelType == "") { workPart.SetAttribute("ExcelType", "SelfCheck"); } } } catch (System.Exception ex) { return; } MessageBox.Show("Assign成功"); SelDimen.Text = "選擇物件(0)"; }
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()); } } MessageBox.Show("完成!"); }
private static void GetTextBoxCoordinate(string DimeType, NXObject singleObj, out CaxME.BoxCoordinate cBoxCoordinate) { cBoxCoordinate = new CaxME.BoxCoordinate(); if (DimeType == "NXOpen.Annotations.VerticalDimension") { #region VerticalDimension取Location NXOpen.Annotations.VerticalDimension temp = (NXOpen.Annotations.VerticalDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.PerpendicularDimension") { #region PerpendicularDimension取Location NXOpen.Annotations.PerpendicularDimension temp = (NXOpen.Annotations.PerpendicularDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.MinorAngularDimension") { #region MinorAngularDimension取Location NXOpen.Annotations.MinorAngularDimension temp = (NXOpen.Annotations.MinorAngularDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.MajorAngularDimension") { #region MajorAngularDimension取Location NXOpen.Annotations.MajorAngularDimension temp = (NXOpen.Annotations.MajorAngularDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.RadiusDimension") { #region MinorAngularDimension取Location NXOpen.Annotations.RadiusDimension temp = (NXOpen.Annotations.RadiusDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.HorizontalDimension") { #region HorizontalDimension取Location NXOpen.Annotations.HorizontalDimension temp = (NXOpen.Annotations.HorizontalDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.IdSymbol") { #region IdSymbol取Location NXOpen.Annotations.IdSymbol temp = (NXOpen.Annotations.IdSymbol)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.Note") { #region Note取Location NXOpen.Annotations.Note temp = (NXOpen.Annotations.Note)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.DraftingFcf") { #region DraftingFcf取Location NXOpen.Annotations.DraftingFcf temp = (NXOpen.Annotations.DraftingFcf)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.Label") { #region Label取Location NXOpen.Annotations.Label temp = (NXOpen.Annotations.Label)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.DraftingDatum") { #region DraftingDatum取Location NXOpen.Annotations.DraftingDatum temp = (NXOpen.Annotations.DraftingDatum)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.DiameterDimension") { #region DiameterDimension取Location NXOpen.Annotations.DiameterDimension temp = (NXOpen.Annotations.DiameterDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.AngularDimension") { #region AngularDimension取Location NXOpen.Annotations.AngularDimension temp = (NXOpen.Annotations.AngularDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.CylindricalDimension") { #region CylindricalDimension取Location NXOpen.Annotations.CylindricalDimension temp = (NXOpen.Annotations.CylindricalDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.ChamferDimension") { #region ChamferDimension取Location NXOpen.Annotations.ChamferDimension temp = (NXOpen.Annotations.ChamferDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.HoleDimension") { #region HoleDimension取Location NXOpen.Annotations.HoleDimension temp = (NXOpen.Annotations.HoleDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); //CaxLog.ShowListingWindow(cBoxCoordinate.lower_left[0].ToString()); //CaxLog.ShowListingWindow(cBoxCoordinate.lower_left[1].ToString()); //CaxLog.ShowListingWindow(cBoxCoordinate.lower_right[0].ToString()); //CaxLog.ShowListingWindow(cBoxCoordinate.lower_right[1].ToString()); //CaxLog.ShowListingWindow(cBoxCoordinate.upper_right[0].ToString()); //CaxLog.ShowListingWindow(cBoxCoordinate.upper_right[1].ToString()); //CaxLog.ShowListingWindow(cBoxCoordinate.upper_left[0].ToString()); //CaxLog.ShowListingWindow(cBoxCoordinate.upper_left[1].ToString()); //CaxLog.ShowListingWindow("----"); //CaxME.DrawTextBox(temp.Tag); #endregion } else if (DimeType == "NXOpen.Annotations.ParallelDimension") { #region ParallelDimension取Location NXOpen.Annotations.ParallelDimension temp = (NXOpen.Annotations.ParallelDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.FoldedRadiusDimension") { #region FoldedRadiusDimension取Location NXOpen.Annotations.FoldedRadiusDimension temp = (NXOpen.Annotations.FoldedRadiusDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.ArcLengthDimension") { #region ArcLengthDimension取Location NXOpen.Annotations.ArcLengthDimension temp = (NXOpen.Annotations.ArcLengthDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.DraftingSurfaceFinish") { #region SurfaceFinish取Location NXOpen.Annotations.DraftingSurfaceFinish temp = (NXOpen.Annotations.DraftingSurfaceFinish)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.ConcentricCircleDimension") { #region ConcentricCircle取Location NXOpen.Annotations.ConcentricCircleDimension temp = (NXOpen.Annotations.ConcentricCircleDimension)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } else if (DimeType == "NXOpen.Annotations.Gdt") { #region GDT Symbol取Location NXOpen.Annotations.Gdt temp = (NXOpen.Annotations.Gdt)singleObj; CaxME.GetTextBoxCoordinate(temp.Tag, out cBoxCoordinate); #endregion } }
//------------------------------------------------------------------------------ // 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); }
private static void InsertBallon(ref int MaxBallonNum, CoordinateData cCoordinateData, double SheetHeight, double SheetLength, string BalloonAtt) { double BallonNumSize = 0; foreach (KeyValuePair <string, List <DimenData> > kvp in DefineParam.DicDimenData) { List <DimenData> tempListDimenData = new List <DimenData>(); DefineParam.DicDimenData.TryGetValue(kvp.Key, out tempListDimenData); for (int i = 0; i < tempListDimenData.Count; i++) { tempListDimenData[i].CurrentSheet.Open(); MaxBallonNum++; Point3d BallonLocation = new Point3d(); BallonLocation.X = tempListDimenData[i].LocationX; BallonLocation.Y = tempListDimenData[i].LocationY; //決定數字的大小 if (MaxBallonNum <= 9) { BallonNumSize = 2.5; } else if (MaxBallonNum > 9 && MaxBallonNum <= 99) { BallonNumSize = 1.5; } else { BallonNumSize = 1; } NXObject balloonObj = null; CaxME.CreateBallonOnSheet(MaxBallonNum.ToString(), BallonLocation, BallonNumSize, BalloonAtt, out balloonObj); //取得該尺寸數量 string diCount = ""; try { diCount = tempListDimenData[i].Obj.GetStringAttribute(CaxME.DimenAttr.DiCount); } catch (System.Exception ex) { //當遇到舊料號沒有Dicount的屬性時,在這邊補上 tempListDimenData[i].Obj.SetAttribute(CaxME.DimenAttr.DiCount, "1"); diCount = "1"; } //如果大於1表示要插入a.b.c..... if (diCount != "1") { //文字座標 CaxME.BoxCoordinate sBoxCoordinate = new CaxME.BoxCoordinate(); CaxME.GetTextBoxCoordinate(balloonObj.Tag, out sBoxCoordinate); Point3d textCoord = new Point3d(sBoxCoordinate.lower_left[0] + 1.5, sBoxCoordinate.lower_left[1] - 1.5, 0); string countText = Convert.ToChar(65 + 0).ToString().ToLower() + "-" + Convert.ToChar(65 + Convert.ToInt32(diCount) - 1).ToString().ToLower(); CaxME.InsertDicountNote(MaxBallonNum.ToString(), CaxME.DimenAttr.DiCount, countText, "1.8", textCoord); } //取得該尺寸所在圖紙 string SheetNum = tempListDimenData[i].Obj.GetStringAttribute("SheetName"); #region 計算泡泡相對位置 //計算泡泡相對位置 string RegionX = "", RegionY = ""; for (int ii = 0; ii < cCoordinateData.DraftingCoordinate.Count; ii++) { string SheetSize = cCoordinateData.DraftingCoordinate[ii].SheetSize; if (Math.Ceiling(SheetHeight) != Convert.ToDouble(SheetSize.Split(',')[0]) || Math.Ceiling(SheetLength) != Convert.ToDouble(SheetSize.Split(',')[1])) { continue; } //比對X for (int j = 0; j < cCoordinateData.DraftingCoordinate[ii].RegionX.Count; j++) { string X0 = cCoordinateData.DraftingCoordinate[ii].RegionX[j].X0; string X1 = cCoordinateData.DraftingCoordinate[ii].RegionX[j].X1; if (BallonLocation.X >= Convert.ToDouble(X0) && BallonLocation.X <= Convert.ToDouble(X1)) { RegionX = cCoordinateData.DraftingCoordinate[ii].RegionX[j].Zone; } } //比對Y for (int j = 0; j < cCoordinateData.DraftingCoordinate[ii].RegionY.Count; j++) { string Y0 = cCoordinateData.DraftingCoordinate[ii].RegionY[j].Y0; string Y1 = cCoordinateData.DraftingCoordinate[ii].RegionY[j].Y1; if (BallonLocation.Y >= Convert.ToDouble(Y0) && BallonLocation.Y <= Convert.ToDouble(Y1)) { RegionY = cCoordinateData.DraftingCoordinate[ii].RegionY[j].Zone; } } } #endregion tempListDimenData[i].Obj.SetAttribute(CaxME.DimenAttr.BallonNum, MaxBallonNum.ToString()); tempListDimenData[i].Obj.SetAttribute(CaxME.DimenAttr.BallonLocation, SheetNum + "-" + RegionY + RegionX); } } }
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 InsertBalloon(GridRow row, CoordinateData cCoordinateData) { //取得圖紙長、高 NXOpen.Drawings.DrawingSheet drawingSheet1 = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(row.Cells["尺寸位置"].Value.ToString()); drawingSheet1.Open(); double SheetLength = drawingSheet1.Length; double SheetHeight = drawingSheet1.Height; //事先塞入該尺寸所在Sheet ((NXObject)row.Cells["Dimension"].Value).SetAttribute(CaxME.DimenAttr.SheetName, row.Cells["尺寸位置"].Value.ToString()); //計算泡泡座標 CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate(); CaxME.GetTextBoxCoordinate(((NXOpen.Annotations.Annotation)row.Cells["Dimension"].Value).Tag, out cBoxCoordinate); DimenData sDimenData = new DimenData(); Functions.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData); Point3d BallonLocation = new Point3d(); BallonLocation.X = sDimenData.LocationX; BallonLocation.Y = sDimenData.LocationY; //決定數字的大小 double BallonNumSize = 0; if (Convert.ToInt32(row.Cells["自定泡泡號"].Value) <= 9) { BallonNumSize = 2.5; } else if (Convert.ToInt32(row.Cells["自定泡泡號"].Value) > 9 && Convert.ToInt32(row.Cells["自定泡泡號"].Value) <= 99) { BallonNumSize = 1.5; } else { BallonNumSize = 1; } NXObject balloonObj = null; CaxME.CreateBallonOnSheet(row.Cells["自定泡泡號"].Value.ToString(), BallonLocation, BallonNumSize, "BalloonAtt", out balloonObj); //取得該尺寸數量 string diCount = ""; try { diCount = ((NXObject)row.Cells["Dimension"].Value).GetStringAttribute(CaxME.DimenAttr.DiCount); } catch (System.Exception ex) { //當遇到舊料號沒有Dicount的屬性時,在這邊補上 ((NXObject)row.Cells["Dimension"].Value).SetAttribute(CaxME.DimenAttr.DiCount, "1"); diCount = "1"; } //如果大於1表示要插入a.b.c..... if (diCount != "1") { //文字座標 CaxME.BoxCoordinate sBoxCoordinate = new CaxME.BoxCoordinate(); CaxME.GetTextBoxCoordinate(balloonObj.Tag, out sBoxCoordinate); Point3d textCoord = new Point3d(sBoxCoordinate.lower_left[0] + 1.5, sBoxCoordinate.lower_left[1] - 1.5, 0); string countText = Convert.ToChar(65 + 0).ToString().ToLower() + "-" + Convert.ToChar(65 + Convert.ToInt32(diCount) - 1).ToString().ToLower(); CaxME.InsertDicountNote(row.Cells["自定泡泡號"].Value.ToString(), CaxME.DimenAttr.DiCount, countText, "1.8", textCoord); } #region 計算泡泡相對位置 string RegionX = "", RegionY = ""; for (int ii = 0; ii < cCoordinateData.DraftingCoordinate.Count; ii++) { string SheetSize = cCoordinateData.DraftingCoordinate[ii].SheetSize; if (Math.Ceiling(SheetHeight) != Convert.ToDouble(SheetSize.Split(',')[0]) || Math.Ceiling(SheetLength) != Convert.ToDouble(SheetSize.Split(',')[1])) { continue; } //比對X for (int j = 0; j < cCoordinateData.DraftingCoordinate[ii].RegionX.Count; j++) { string X0 = cCoordinateData.DraftingCoordinate[ii].RegionX[j].X0; string X1 = cCoordinateData.DraftingCoordinate[ii].RegionX[j].X1; if (BallonLocation.X >= Convert.ToDouble(X0) && BallonLocation.X <= Convert.ToDouble(X1)) { RegionX = cCoordinateData.DraftingCoordinate[ii].RegionX[j].Zone; } } //比對Y for (int j = 0; j < cCoordinateData.DraftingCoordinate[ii].RegionY.Count; j++) { string Y0 = cCoordinateData.DraftingCoordinate[ii].RegionY[j].Y0; string Y1 = cCoordinateData.DraftingCoordinate[ii].RegionY[j].Y1; if (BallonLocation.Y >= Convert.ToDouble(Y0) && BallonLocation.Y <= Convert.ToDouble(Y1)) { RegionY = cCoordinateData.DraftingCoordinate[ii].RegionY[j].Zone; } } } #endregion ((NXObject)row.Cells["Dimension"].Value).SetAttribute(CaxME.DimenAttr.BallonNum, row.Cells["自定泡泡號"].Value.ToString()); ((NXObject)row.Cells["Dimension"].Value).SetAttribute(CaxME.DimenAttr.BallonLocation, row.Cells["尺寸位置"].Value.ToString() + "-" + RegionY + RegionX); workPart.Views.Refresh(); }
private void Upload_Click(object sender, EventArgs e) { try { int SheetCount = 0; NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); //判斷是否需要出PDF List <DrawingSheet> drawingSheets = new List <DrawingSheet>(); for (int j = 0; j < SheetCount; j++) { drawingSheets.Add((DrawingSheet)NXObjectManager.Get(SheetTagAry[j])); } if (this.ExportPDF.Checked) { if (!Directory.Exists(this.L_Folder)) { Directory.CreateDirectory(this.L_Folder); } string str1 = string.Format(@"{0}\{1}.pdf", this.L_Folder, Path.GetFileNameWithoutExtension(FixInsUploadDlg.displayPart.FullPath)); CaxME.CreateOISPDF(drawingSheets, str1); //傳OIS圖到SERVER if (!Directory.Exists(S_Folder)) { System.IO.Directory.CreateDirectory(S_Folder); } CaxPublic.DirectoryCopy(this.L_Folder, S_Folder, true); } //取得WorkPart資訊並檢查資料是否完整 DadDimension.WorkPartAttribute sWorkPartAttribute = new DadDimension.WorkPartAttribute(); status = DadDimension.GetWorkPartAttribute(workPart, out sWorkPartAttribute); if (!status) { if (this.ExportPDF.Checked) { MessageBox.Show("量測資訊不足,僅上傳PDF檔案,上傳完成!"); } else { MessageBox.Show("量測資訊不足,無法上傳資料!"); } this.Close(); return; } //if (sWorkPartAttribute.draftingVer == "" || sWorkPartAttribute.draftingDate == "" || // sWorkPartAttribute.partDescription == "" || sWorkPartAttribute.material == "") //{ // MessageBox.Show("量測資訊不足"); // this.Close(); // return; //} //取得所有量測尺寸資料 List <DadDimension> listDimensionData = new List <DadDimension>(); for (int i = 0; i < SheetCount; i++) { //打開Sheet並記錄所有OBJ NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); CurrentSheet.Open(); CurrentSheet.View.UpdateDisplay(); DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects(); status = Com_FixDimension.RecordFixDimension(SheetObj, sWorkPartAttribute, ref listDimensionData); if (!status) { this.Close(); return; } } //將圖片存到本機Globaltek內 for (int i = 0; i < PicNameStr.Length; i++) { string destFileName = string.Format(@"{0}\{1}", this.L_Folder, PicNameStr[i]); File.Copy(PicPathStr[i], destFileName, true); } //由料號查Com_PEMain Com_PEMain cCom_PEMain = new Com_PEMain(); status = CaxSQL.GetCom_PEMain(cCaxUpLoad.CusName, cCaxUpLoad.PartName, cCaxUpLoad.CusRev, cCaxUpLoad.OpRev, out cCom_PEMain); if (!status) { return; } //由Com_PEMain和Op查Com_PartOperation Com_PartOperation cCom_PartOperation = new Com_PartOperation(); status = CaxSQL.GetCom_PartOperation(cCom_PEMain, cCaxUpLoad.OpNum, out cCom_PartOperation); if (!status) { return; } #region 比對資料庫FixInspection是否有同筆數據 bool Is_Exit = true; Com_FixInspection cCom_FixInspection = new Com_FixInspection(); CaxSQL.GetCom_FixInspection(cCom_PartOperation, Path.GetFileNameWithoutExtension(workPart.FullPath), out cCom_FixInspection); if (cCom_FixInspection == null) { Is_Exit = false; } if (Is_Exit && eTaskDialogResult.Yes == CaxPublic.ShowMsgYesNo("此檢、治具已存在上一筆資料,是否更新?")) { #region 刪除Com_FixDimension IList <Com_FixDimension> listComFixDimension = new List <Com_FixDimension>(); CaxSQL.GetListCom_FixDimension(cCom_FixInspection, out listComFixDimension); foreach (Com_FixDimension i in listComFixDimension) { CaxSQL.Delete <Com_FixDimension>(i); } #endregion #region 刪除Com_FixInspection CaxSQL.Delete <Com_FixInspection>(cCom_FixInspection); #endregion Is_Exit = false; } if (!Is_Exit) { cCom_FixInspection = new Com_FixInspection() { comPartOperation = cCom_PartOperation, fixinsDescription = this.Desc.Text, fixinsERP = this.ERPNo.Text, fixinsNo = this.FixInsNo.Text, fixPicPath = this.S_PicPath, fixPartName = Path.GetFileNameWithoutExtension(FixInsUploadDlg.workPart.FullPath) }; IList <Com_FixDimension> listCom_FixDimension = new List <Com_FixDimension>(); foreach (DadDimension i in listDimensionData) { //Com_FixDimension cCom_FixDimension = new Com_FixDimension() //{ // comFixInspection = comFixInspection //}; ////cCom_FixDimension.comFixInspection = comFixInspection; //CaxME.MappingData(i, ref cCom_FixDimension); //listCom_FixDimension.Add(cCom_FixDimension); Com_FixDimension cCom_FixDimension = new Com_FixDimension(); cCom_FixDimension.MappingData(i); cCom_FixDimension.comFixInspection = cCom_FixInspection; listCom_FixDimension.Add(cCom_FixDimension); } cCom_FixInspection.comFixDimension = listCom_FixDimension; CaxSQL.Save <Com_FixInspection>(cCom_FixInspection); //傳OIS圖到SERVER if (!Directory.Exists(S_Folder)) { System.IO.Directory.CreateDirectory(S_Folder); } CaxPublic.DirectoryCopy(this.L_Folder, S_Folder, true); } #endregion MessageBox.Show("上傳完成"); base.Close(); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } }
private void OK_Click(object sender, EventArgs e) { if (DicSelDimension.Keys.Count == 0) { CaxLog.ShowListingWindow("請使用【選擇物件】選擇標註尺寸!"); return; } #region 選擇Assign if (chb_Assign.Checked == true) { if (FAIcheckBox.Checked == false & IQCcheckBox.Checked == false & IPQCcheckBox.Checked == false & FQCcheckBox.Checked == false) { CaxLog.ShowListingWindow("請先選擇一種檢驗報告格式!"); return; } if (Gauge.Text == "" && SelfCheckGauge.Text == "") { CaxLog.ShowListingWindow("資料不足,請先填寫【IQC】或【IPQC】或【SelfCheck】!"); return; } if (Gauge.Text != "" && (Freq_0.Text == "" || Freq_1.Text == "" || Freq_Units.Text == "")) { CaxLog.ShowListingWindow("IQC尚未填寫完畢!"); return; } if (SelfCheckGauge.Text != "" && (SelfCheck_0.Text == "" || SelfCheck_1.Text == "" || SelfCheck_Units.Text == "")) { CaxLog.ShowListingWindow("SelfCheck尚未填寫完畢!"); return; } foreach (KeyValuePair <NXObject, string> kvp in DicSelDimension) { //取得原始顏色 int oldColor = CaxME.GetDimensionColor(kvp.Key); if (oldColor == -1) { oldColor = 125; } //取得檢具顏色 GaugeData cGaugeData = new GaugeData(); if (SelfCheckGauge.Text != "") { status = DicGaugeData.TryGetValue(SelfCheckGauge.Text, out cGaugeData); if (!status) { CaxLog.ShowListingWindow("此檢具資料可能有誤"); return; } } if (Gauge.Text != "") { status = DicGaugeData.TryGetValue(Gauge.Text, out cGaugeData); if (!status) { CaxLog.ShowListingWindow("此檢具資料可能有誤"); return; } } //改變標註尺寸顏色 CaxME.SetDimensionColor(kvp.Key, Convert.ToInt32(cGaugeData.Color)); //塞屬性 kvp.Key.SetAttribute(CaxME.DimenAttr.OldColor, oldColor.ToString());//舊顏色 if (Gauge.Text != "") { if (FAIcheckBox.Checked == true) { kvp.Key.SetAttribute(CaxME.DimenAttr.FAI_Gauge, Gauge.Text);//檢具名稱 kvp.Key.SetAttribute(CaxME.DimenAttr.FAI_Freq, Freq_0.Text + "PC/" + Freq_1.Text + Freq_Units.Text); } if (IQCcheckBox.Checked == true) { kvp.Key.SetAttribute(CaxME.DimenAttr.IQC_Gauge, Gauge.Text);//檢具名稱 kvp.Key.SetAttribute(CaxME.DimenAttr.IQC_Freq, Freq_0.Text + "PC/" + Freq_1.Text + Freq_Units.Text); } if (IPQCcheckBox.Checked == true) { kvp.Key.SetAttribute(CaxME.DimenAttr.IPQC_Gauge, Gauge.Text);//檢具名稱 kvp.Key.SetAttribute(CaxME.DimenAttr.IPQC_Freq, Freq_0.Text + "PC/" + Freq_1.Text + Freq_Units.Text); } if (FQCcheckBox.Checked == true) { kvp.Key.SetAttribute(CaxME.DimenAttr.FQC_Gauge, Gauge.Text);//檢具名稱 kvp.Key.SetAttribute(CaxME.DimenAttr.FQC_Freq, Freq_0.Text + "PC/" + Freq_1.Text + Freq_Units.Text); } } if (SelfCheckGauge.Text != "") { kvp.Key.SetAttribute(CaxME.DimenAttr.SelfCheck_Gauge, SelfCheckGauge.Text); //檢具名稱 kvp.Key.SetAttribute(CaxME.DimenAttr.SelfCheck_Freq, SelfCheck_0.Text + "PC/" + SelfCheck_1.Text + SelfCheck_Units.Text); //SelfCheck } /* * //泡泡順序增加 * BallonNum++; * //取得泡泡的座標 * CaxME.BoxCoordinate TextCoordi = new CaxME.BoxCoordinate(); * Point3d CreateBallonPt = new Point3d(); * CaxME.GetTextBoxCoordinate(kvp.Key.Tag, out TextCoordi); * if (Math.Abs(TextCoordi.upper_left[0] - TextCoordi.lower_left[0]) < 0.01) * { * CreateBallonPt.X = (TextCoordi.upper_left[0] + TextCoordi.lower_left[0]) / 2 - 2; * CreateBallonPt.Y = (TextCoordi.upper_left[1] + TextCoordi.lower_left[1]) / 2; * } * else * { * CreateBallonPt.X = (TextCoordi.upper_left[0] + TextCoordi.lower_left[0]) / 2; * CreateBallonPt.Y = (TextCoordi.upper_left[1] + TextCoordi.lower_left[1]) / 2 - 2; * } * //插入泡泡 * CaxME.CreateBallonOnSheet(BallonNum.ToString(), CreateBallonPt); * //取得泡泡在圖紙的區域 * string SheetNum = ListSheet.Text, RegionX = "", RegionY = ""; * for (int i = 0; i < cCoordinateData.DraftingCoordinate.Count;i++ ) * { * string SheetSize = cCoordinateData.DraftingCoordinate[i].SheetSize; * if (Math.Ceiling(SheetHeight) != Convert.ToDouble(SheetSize.Split(',')[0]) || Math.Ceiling(SheetLength) != Convert.ToDouble(SheetSize.Split(',')[1])) * { * continue; * } * //比對X * for (int j = 0; j < cCoordinateData.DraftingCoordinate[i].RegionX.Count;j++ ) * { * string X0 = cCoordinateData.DraftingCoordinate[i].RegionX[j].X0; * string X1 = cCoordinateData.DraftingCoordinate[i].RegionX[j].X1; * if (CreateBallonPt.X >= Convert.ToDouble(X0) && CreateBallonPt.X <= Convert.ToDouble(X1)) * { * RegionX = cCoordinateData.DraftingCoordinate[i].RegionX[j].Zone; * } * } * //比對Y * for (int j = 0; j < cCoordinateData.DraftingCoordinate[i].RegionY.Count; j++) * { * string Y0 = cCoordinateData.DraftingCoordinate[i].RegionY[j].Y0; * string Y1 = cCoordinateData.DraftingCoordinate[i].RegionY[j].Y1; * if (CreateBallonPt.Y >= Convert.ToDouble(Y0) && CreateBallonPt.Y <= Convert.ToDouble(Y1)) * { * RegionY = cCoordinateData.DraftingCoordinate[i].RegionY[j].Zone; * } * } * } * //塞泡泡屬性 * kvp.Key.SetAttribute(CaxME.DimenAttr.BallonNum, BallonNum.ToString()); * kvp.Key.SetAttribute(CaxME.DimenAttr.BallonLocation, SheetNum + "-" + RegionY + RegionX); */ } } #endregion #region 選擇Remove if (chb_Remove.Checked == true) { foreach (KeyValuePair <NXObject, string> kvp in DicSelDimension) { //恢復原始顏色 string oldColor = ""; try { //第二次以上指定顏色的話,抓出來的顏色就不是內建顏色EX:125->108->186,抓到的是108 oldColor = kvp.Key.GetStringAttribute(CaxME.DimenAttr.OldColor); //內建原始顏色 oldColor = "125"; } catch (System.Exception ex) { oldColor = "125"; } CaxME.SetDimensionColor(kvp.Key, Convert.ToInt32(oldColor)); //取得泡泡資訊 string BallonNum = ""; try { BallonNum = kvp.Key.GetStringAttribute(CaxME.DimenAttr.BallonNum); } catch (System.Exception ex) { BallonNum = ""; } if (BallonNum != "") { CaxME.DeleteBallon(BallonNum); } kvp.Key.DeleteAllAttributesByType(NXObject.AttributeType.String); } } #endregion SelectObject.Text = "選擇物件(0)"; }
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("完成!"); }
//------------------------------------------------------------------------------ // 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(); Part workPart = theSession.Parts.Work; Part displayPart = theSession.Parts.Display; bool status; DefineVariable.Is_Local = Environment.GetEnvironmentVariable("UGII_ENV_FILE"); if (DefineVariable.Is_Local != "") { //取得本機ShopDoc.xls路徑 DefineVariable.SelfCheckPath = string.Format(@"{0}\{1}\{2}", Path.GetDirectoryName(displayPart.FullPath), "MODEL", "SelfCheck.xls"); } //取得料號 string PartNo = Path.GetFileNameWithoutExtension(displayPart.FullPath); //取得日期 string CurrentDate = DateTime.Now.ToShortDateString(); int SheetCount = 0; NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); DefineVariable.DicDimenData = new Dictionary <string, TextData>(); 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) { //記錄第一張Sheet DefineVariable.FirstDrawingSheet = CurrentSheet; } DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects(); foreach (DisplayableObject singleObj in SheetObj) { TextData cTextData = new TextData(); string singleObjType = singleObj.GetType().ToString(); string SelfCheck_Gauge = "", BallonNum = "", Frequency = "", Location = ""; string[] mainText; string[] dualText; #region 取SelfCheck共用屬性(泡泡值、檢具名稱、檢驗頻率、泡泡所在區域),如果都沒屬性就找下一個 try { SelfCheck_Gauge = singleObj.GetStringAttribute(CaxME.DimenAttr.IPQC_Gauge); BallonNum = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonNum); Frequency = singleObj.GetStringAttribute(CaxME.DimenAttr.IPQC_Freq); Location = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonLocation); } catch (System.Exception ex) { SelfCheck_Gauge = ""; } if (SelfCheck_Gauge == "") { continue; } #endregion #region 紀錄共用屬性(泡泡值、檢具名稱、檢驗頻率、泡泡所在區域) //取得泡泡值 cTextData.BallonNum = BallonNum; //取得檢具名稱 cTextData.Gauge = SelfCheck_Gauge; //取得檢驗頻率 cTextData.Frequency = Frequency; //取得泡泡所在區域 cTextData.Location = Location; #endregion if (singleObjType == "NXOpen.Annotations.VerticalDimension") { #region VerticalDimension取Text cTextData.Type = "NXOpen.Annotations.VerticalDimension"; NXOpen.Annotations.VerticalDimension temp = (NXOpen.Annotations.VerticalDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.PerpendicularDimension") { #region PerpendicularDimension取Text cTextData.Type = "NXOpen.Annotations.PerpendicularDimension"; NXOpen.Annotations.PerpendicularDimension temp = (NXOpen.Annotations.PerpendicularDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.MinorAngularDimension") { #region MinorAngularDimension取Text cTextData.Type = "NXOpen.Annotations.MinorAngularDimension"; NXOpen.Annotations.MinorAngularDimension temp = (NXOpen.Annotations.MinorAngularDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.RadiusDimension") { #region MinorAngularDimension取Text cTextData.Type = "NXOpen.Annotations.RadiusDimension"; NXOpen.Annotations.RadiusDimension temp = (NXOpen.Annotations.RadiusDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.HorizontalDimension") { #region HorizontalDimension取Text cTextData.Type = "NXOpen.Annotations.HorizontalDimension"; NXOpen.Annotations.HorizontalDimension temp = (NXOpen.Annotations.HorizontalDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.IdSymbol") { #region IdSymbol取Text cTextData.Type = "NXOpen.Annotations.IdSymbol"; NXOpen.Annotations.IdSymbol temp = (NXOpen.Annotations.IdSymbol)singleObj; #endregion } else if (singleObjType == "NXOpen.Annotations.Note") { #region Note取Text cTextData.Type = "NXOpen.Annotations.Note"; NXOpen.Annotations.Note temp = (NXOpen.Annotations.Note)singleObj; cTextData.MainText = temp.GetText()[0]; #endregion } else if (singleObjType == "NXOpen.Annotations.DraftingFcf") { #region DraftingFcf取Text NXOpen.Annotations.DraftingFcf temp = (NXOpen.Annotations.DraftingFcf)singleObj; CaxME.FcfData sFcfData = new CaxME.FcfData(); CaxME.GetFcfData(temp, out sFcfData); cTextData.Type = "NXOpen.Annotations.DraftingFcf"; cTextData.Characteristic = sFcfData.Characteristic; cTextData.ZoneShape = sFcfData.ZoneShape; cTextData.ToleranceValue = sFcfData.ToleranceValue; cTextData.MaterialModifier = sFcfData.MaterialModifier; cTextData.PrimaryDatum = sFcfData.PrimaryDatum; cTextData.PrimaryMaterialModifier = sFcfData.PrimaryMaterialModifier; cTextData.SecondaryDatum = sFcfData.SecondaryDatum; cTextData.SecondaryMaterialModifier = sFcfData.SecondaryMaterialModifier; cTextData.TertiaryDatum = sFcfData.TertiaryDatum; cTextData.TertiaryMaterialModifier = sFcfData.TertiaryMaterialModifier; #endregion } else if (singleObjType == "NXOpen.Annotations.Label") { #region Label取Text cTextData.Type = "NXOpen.Annotations.Label"; NXOpen.Annotations.Label temp = (NXOpen.Annotations.Label)singleObj; cTextData.MainText = temp.GetText()[0]; #endregion } else if (singleObjType == "NXOpen.Annotations.DraftingDatum") { #region DraftingDatum取Text cTextData.Type = "NXOpen.Annotations.DraftingDatum"; NXOpen.Annotations.DraftingDatum temp = (NXOpen.Annotations.DraftingDatum)singleObj; #endregion } else if (singleObjType == "NXOpen.Annotations.DiameterDimension") { #region DiameterDimension取Text cTextData.Type = "NXOpen.Annotations.DiameterDimension"; NXOpen.Annotations.DiameterDimension temp = (NXOpen.Annotations.DiameterDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.AngularDimension") { #region AngularDimension取Text cTextData.Type = "NXOpen.Annotations.AngularDimension"; NXOpen.Annotations.AngularDimension temp = (NXOpen.Annotations.AngularDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.CylindricalDimension") { #region CylindricalDimension取Text cTextData.Type = "NXOpen.Annotations.CylindricalDimension"; NXOpen.Annotations.CylindricalDimension temp = (NXOpen.Annotations.CylindricalDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } if (temp.ToleranceType.ToString() == "BilateralTwoLines") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } if (temp.ToleranceType.ToString() == "UnilateralAbove") { cTextData.TolType = "UnilateralAbove"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = "0"; } if (temp.ToleranceType.ToString() == "UnilateralBelow") { cTextData.TolType = "UnilateralBelow"; cTextData.UpperTol = "0"; cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.ChamferDimension") { #region ChamferDimension取Text cTextData.Type = "NXOpen.Annotations.ChamferDimension"; NXOpen.Annotations.ChamferDimension temp = (NXOpen.Annotations.ChamferDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0] + "X" + "45" + "<$s>"; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } if (temp.ToleranceType.ToString() == "BilateralTwoLines") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } if (temp.ToleranceType.ToString() == "UnilateralAbove") { cTextData.TolType = "UnilateralAbove"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = "0"; } if (temp.ToleranceType.ToString() == "UnilateralBelow") { cTextData.TolType = "UnilateralBelow"; cTextData.UpperTol = "0"; cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } #endregion } //計算泡泡總數 DefineVariable.BallonCount++; DefineVariable.DicDimenData[BallonNum] = cTextData; } } //設定輸出路徑--Local //string[] FolderFile = System.IO.Directory.GetFileSystemEntries(Path.GetDirectoryName(displayPart.FullPath), "*.xls"); //string OutputPath = string.Format(@"{0}\{1}", Path.GetDirectoryName(displayPart.FullPath), // Path.GetFileNameWithoutExtension(displayPart.FullPath) + "_" + "SelfCheck" + "_" + (FolderFile.Length + 1) + ".xls"); //設定輸出路徑--Server string OperNum = Regex.Replace(Path.GetFileNameWithoutExtension(displayPart.FullPath).Split('_')[1], "[^0-9]", ""); string Local_Folder_OIS = string.Format(@"{0}\{1}\{2}", Path.GetDirectoryName(displayPart.FullPath), "OP" + OperNum, "OIS"); if (!File.Exists(Local_Folder_OIS)) { System.IO.Directory.CreateDirectory(Local_Folder_OIS); } string[] FolderFile = System.IO.Directory.GetFileSystemEntries(Local_Folder_OIS, "*.xls"); List <string> ListFolderFileWithIPQC = new List <string>(); foreach (string i in FolderFile) { if (i.Contains("SelfCheck")) { ListFolderFileWithIPQC.Add(i); } } string OutputPath = string.Format(@"{0}\{1}", Local_Folder_OIS, Path.GetFileNameWithoutExtension(displayPart.FullPath) + "_" + "SelfCheck" + "_" + (ListFolderFileWithIPQC.Count + 1) + ".xls"); //檢查PC有無Excel在執行 foreach (var item in Process.GetProcesses()) { if (item.ProcessName == "EXCEL") { CaxLog.ShowListingWindow("請先關閉所有Excel再重新執行輸出,如沒有EXCEL在執行,請開啟工作管理員關閉背景EXCEL"); return(retValue); } else { continue; } } Excel.ApplicationClass x = new Excel.ApplicationClass(); Excel.Workbook book = null; Excel.Worksheet sheet = null; Excel.Range oRng = null; try { x.Visible = false; if (DefineVariable.Is_Local != "") { if (File.Exists(DefineVariable.SelfCheckPath)) { book = x.Workbooks.Open(DefineVariable.SelfCheckPath); } else { book = x.Workbooks.Open(@"D:\SelfCheck.xls"); } } else { book = x.Workbooks.Open(@"D:\SelfCheck.xls"); } sheet = (Excel.Worksheet)book.Sheets[1]; //由檢驗總數開啟符合總數的頁數 int needSheetNo = (DefineVariable.BallonCount / 11); int needSheetNo_Reserve = (DefineVariable.BallonCount % 11); if (needSheetNo_Reserve != 0) { needSheetNo++; } for (int i = 1; i < needSheetNo; i++) { sheet.Copy(System.Type.Missing, x.Workbooks[1].Worksheets[1]); } //更改每一個Sheet的名稱與頁數 for (int i = 0; i < book.Worksheets.Count; i++) { sheet = (Excel.Worksheet)book.Sheets[i + 1]; if (i == 0 && book.Worksheets.Count > 1) { sheet.Name = PartNo; oRng = (Excel.Range)sheet.Cells[4, 5]; oRng.Value = oRng.Value.ToString().Replace("1/1", "1/" + (book.Worksheets.Count).ToString()); } else { sheet.Name = PartNo + "(" + (i + 1) + ")"; oRng = (Excel.Range)sheet.Cells[4, 5]; string temp = (i + 1).ToString(); oRng.Value = oRng.Value.ToString().Replace("1/1", temp + "/" + (book.Worksheets.Count).ToString()); } } //填表 int ExcelSequenceNo = -1; for (int i = 1; i < 1000; i++) { ExcelSequenceNo++; TextData cTextData; DefineVariable.DicDimenData.TryGetValue(i.ToString(), out cTextData); if (cTextData == null) { ExcelSequenceNo--; continue; } RowColumn sRowColumn; DefineVariable.GetExcelRowColumn(ExcelSequenceNo, out sRowColumn); int currentSheet_Value = (ExcelSequenceNo / 11); int currentSheet_Reserve = (ExcelSequenceNo % 11); if (currentSheet_Value == 0) { sheet = (Excel.Worksheet)book.Sheets[1]; } else { sheet = (Excel.Worksheet)book.Sheets[currentSheet_Value + 1]; } oRng = (Excel.Range)sheet.Cells; if (cTextData.Type == "NXOpen.Annotations.DraftingFcf") { #region DraftingFcf填資料 if (cTextData.Characteristic != "") { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = DefineVariable.GetCharacteristicSymbol(cTextData.Characteristic); //oRng[sRowColumn.CharacteristicRow, sRowColumn.CharacteristicColumn] = DefineVariable.GetCharacteristicSymbol(cTextData.Characteristic); } if (cTextData.ZoneShape != "") { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + DefineVariable.GetZoneShapeSymbol(cTextData.ZoneShape); //oRng[sRowColumn.ZoneShapeRow, sRowColumn.ZoneShapeColumn] = DefineVariable.GetZoneShapeSymbol(cTextData.ZoneShape); } oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.ToleranceValue; //oRng[sRowColumn.ToleranceValueRow, sRowColumn.ToleranceValueColumn] = cTextData.ToleranceValue; if (cTextData.MaterialModifier != "" & cTextData.MaterialModifier != "None") { string ValueStr = cTextData.MaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + ValueStr; //oRng[sRowColumn.MaterialModifierRow, sRowColumn.MaterialModifierColumn] = ValueStr; } //Primary oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.PrimaryDatum; //oRng[sRowColumn.PrimaryDatumRow, sRowColumn.PrimaryDatumColumn] = cTextData.PrimaryDatum; if (cTextData.PrimaryMaterialModifier != "" & cTextData.PrimaryMaterialModifier != "None") { string ValueStr = cTextData.PrimaryMaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + ValueStr; //oRng[sRowColumn.PrimaryMaterialModifierRow, sRowColumn.PrimaryMaterialModifierColumn] = ValueStr; } //Secondary oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.SecondaryDatum; //oRng[sRowColumn.SecondaryDatumRow, sRowColumn.SecondaryDatumColumn] = cTextData.SecondaryDatum; if (cTextData.SecondaryMaterialModifier != "" & cTextData.SecondaryMaterialModifier != "None") { string ValueStr = cTextData.SecondaryMaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + ValueStr; //oRng[sRowColumn.SecondaryMaterialModifierRow, sRowColumn.SecondaryMaterialModifierColumn] = ValueStr; } //Tertiary oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.TertiaryDatum; //oRng[sRowColumn.TertiaryDatumRow, sRowColumn.TertiaryDatumColumn] = cTextData.TertiaryDatum; if (cTextData.TertiaryMaterialModifier != "" & cTextData.TertiaryMaterialModifier != "None") { string ValueStr = cTextData.TertiaryMaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + ValueStr; //oRng[sRowColumn.TertiaryMaterialModifierRow, sRowColumn.TertiaryMaterialModifierColumn] = ValueStr; } #endregion } else if (cTextData.Type == "NXOpen.Annotations.Label") { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = cTextData.MainText; //((Range)oRng[sRowColumn.MainTextRow, sRowColumn.MainTextColumn]).Interior.ColorIndex = 50; } else { #region Dimension填資料 if (cTextData.BeforeText != null) { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + DefineVariable.GetGDTWord(cTextData.BeforeText); //oRng[sRowColumn.BeforeTextRow, sRowColumn.BeforeTextColumn] = DefineVariable.GetGDTWord(cTextData.BeforeText); } oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + DefineVariable.GetGDTWord(cTextData.MainText); //oRng[sRowColumn.MainTextRow, sRowColumn.MainTextColumn] = DefineVariable.GetGDTWord(cTextData.MainText); //Range ab = (Range)oRng[sRowColumn.MainTextRow, sRowColumn.MainTextColumn]; //ab.Interior.ColorIndex = 39; if (cTextData.UpperTol != "" & cTextData.TolType == "BilateralOneLine") { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + "±"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.UpperTol; string MaxMinStr = "(" + (Convert.ToDouble(cTextData.MainText) + Convert.ToDouble(cTextData.UpperTol)).ToString() + "-" + (Convert.ToDouble(cTextData.MainText) - Convert.ToDouble(cTextData.UpperTol)).ToString() + ")"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + MaxMinStr; //oRng[sRowColumn.ToleranceSymbolRow, sRowColumn.ToleranceSymbolColumn] = "±"; //oRng[sRowColumn.UpperTolRow, sRowColumn.UpperTolColumn] = cTextData.UpperTol; } else if (cTextData.UpperTol != "" & cTextData.TolType == "BilateralTwoLines") { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + "+"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.UpperTol; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + "/"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.LowerTol; string MaxMinStr = "(" + (Convert.ToDouble(cTextData.MainText) + Convert.ToDouble(cTextData.UpperTol)).ToString() + "-" + (Convert.ToDouble(cTextData.MainText) + Convert.ToDouble(cTextData.LowerTol)).ToString() + ")"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + MaxMinStr; } else if (cTextData.UpperTol != "" & cTextData.TolType == "UnilateralAbove") { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + "+"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.UpperTol; } else if (cTextData.UpperTol != "" & cTextData.TolType == "UnilateralBelow") { //oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + "-"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.LowerTol; } #endregion } #region 檢具、頻率、Max、Min、泡泡、泡泡位置、料號、日期 oRng[sRowColumn.GaugeRow, sRowColumn.GaugeColumn] = cTextData.Gauge; oRng[sRowColumn.FrequencyRow, sRowColumn.FrequencyColumn] = cTextData.Frequency; oRng[sRowColumn.BallonRow, sRowColumn.BallonColumn] = cTextData.BallonNum; oRng[sRowColumn.LocationRow, sRowColumn.LocationColumn] = cTextData.Location; oRng[sRowColumn.PartNoRow, sRowColumn.PartNoColumn] = PartNo; oRng[sRowColumn.DateRow, sRowColumn.DateColumn] = CurrentDate; #endregion } book.SaveAs(OutputPath, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); book.Close(Type.Missing, Type.Missing, Type.Missing); x.Quit(); //切回第一張Sheet DefineVariable.FirstDrawingSheet.Open(); UI.GetUI().NXMessageBox.Show("SelfCheck", NXMessageBox.DialogType.Information, "輸出完成"); theProgram.Dispose(); } catch (System.Exception ex) { book.SaveAs(OutputPath, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); book.Close(Type.Missing, Type.Missing, Type.Missing); x.Quit(); } } catch (NXOpen.NXException ex) { // ---- Enter your exception handling code here ----- } return(retValue); }
//------------------------------------------------------------------------------ // 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; DefineVariable.Is_Local = Environment.GetEnvironmentVariable("UGII_ENV_FILE"); if (DefineVariable.Is_Local != "") { //取得本機"FAI.xls路徑 DefineVariable.FAIPath = string.Format(@"{0}\{1}\{2}", Path.GetDirectoryName(displayPart.FullPath), "MODEL", "FAI.xls"); } //取得料號 string PartNo = Path.GetFileNameWithoutExtension(displayPart.FullPath); //取得零件名稱 string PartDescription = ""; try { PartDescription = displayPart.GetStringAttribute("PARTDESCRIPTIONPOS"); } catch (System.Exception ex) { PartDescription = ""; } int SheetCount = 0; NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); DefineVariable.DicDimenData = new Dictionary <string, TextData>(); 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) { //記錄第一張Sheet DefineVariable.FirstDrawingSheet = CurrentSheet; } DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects(); foreach (DisplayableObject singleObj in SheetObj) { TextData cTextData = new TextData(); string singleObjType = singleObj.GetType().ToString(); string FAI_Gauge = "", BallonNum = "", Frequency = "", Location = ""; string[] mainText; string[] dualText; #region 取FAI共用屬性(泡泡值、檢具名稱、檢驗頻率、泡泡所在區域),如果都沒屬性就找下一個 try { FAI_Gauge = singleObj.GetStringAttribute(CaxME.DimenAttr.FAI_Gauge); BallonNum = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonNum); Frequency = singleObj.GetStringAttribute(CaxME.DimenAttr.FAI_Freq); Location = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonLocation); } catch (System.Exception ex) { FAI_Gauge = ""; } if (FAI_Gauge == "") { continue; } #endregion #region 紀錄共用屬性(泡泡值、檢具名稱、檢驗頻率、泡泡所在區域) //取得泡泡值 cTextData.BallonNum = BallonNum; //取得檢具名稱 cTextData.Gauge = FAI_Gauge; //取得檢驗頻率 cTextData.Frequency = Frequency; //取得泡泡所在區域 cTextData.Location = Location; #endregion if (singleObjType == "NXOpen.Annotations.VerticalDimension") { #region VerticalDimension取Text cTextData.Type = "NXOpen.Annotations.VerticalDimension"; NXOpen.Annotations.VerticalDimension temp = (NXOpen.Annotations.VerticalDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.PerpendicularDimension") { #region PerpendicularDimension取Text cTextData.Type = "NXOpen.Annotations.PerpendicularDimension"; NXOpen.Annotations.PerpendicularDimension temp = (NXOpen.Annotations.PerpendicularDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.MinorAngularDimension") { #region MinorAngularDimension取Text cTextData.Type = "NXOpen.Annotations.MinorAngularDimension"; NXOpen.Annotations.MinorAngularDimension temp = (NXOpen.Annotations.MinorAngularDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.RadiusDimension") { #region MinorAngularDimension取Text cTextData.Type = "NXOpen.Annotations.RadiusDimension"; NXOpen.Annotations.RadiusDimension temp = (NXOpen.Annotations.RadiusDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.HorizontalDimension") { #region HorizontalDimension取Text cTextData.Type = "NXOpen.Annotations.HorizontalDimension"; NXOpen.Annotations.HorizontalDimension temp = (NXOpen.Annotations.HorizontalDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } if (temp.ToleranceType.ToString() == "BilateralTwoLines") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } if (temp.ToleranceType.ToString() == "UnilateralAbove") { cTextData.TolType = "UnilateralAbove"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = "0"; } if (temp.ToleranceType.ToString() == "UnilateralBelow") { cTextData.TolType = "UnilateralBelow"; cTextData.UpperTol = "0"; cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.IdSymbol") { #region IdSymbol取Text cTextData.Type = "NXOpen.Annotations.IdSymbol"; NXOpen.Annotations.IdSymbol temp = (NXOpen.Annotations.IdSymbol)singleObj; #endregion } else if (singleObjType == "NXOpen.Annotations.Note") { #region Note取Text cTextData.Type = "NXOpen.Annotations.Note"; NXOpen.Annotations.Note temp = (NXOpen.Annotations.Note)singleObj; //判斷是否由CAX產生的Note string createby = ""; try { createby = temp.GetStringAttribute("Createby"); } catch (System.Exception ex) { createby = ""; } if (createby == "") { string tempStr = temp.GetText()[0].Replace("<F2>", ""); tempStr = tempStr.Replace("<F>", ""); cTextData.MainText = tempStr; } else { cTextData.MainText = temp.GetText()[0]; } #endregion } else if (singleObjType == "NXOpen.Annotations.DraftingFcf") { #region DraftingFcf取Text NXOpen.Annotations.DraftingFcf temp = (NXOpen.Annotations.DraftingFcf)singleObj; CaxME.FcfData sFcfData = new CaxME.FcfData(); CaxME.GetFcfData(temp, out sFcfData); cTextData.Type = "NXOpen.Annotations.DraftingFcf"; cTextData.Characteristic = sFcfData.Characteristic; cTextData.ZoneShape = sFcfData.ZoneShape; cTextData.ToleranceValue = sFcfData.ToleranceValue; cTextData.MaterialModifier = sFcfData.MaterialModifier; cTextData.PrimaryDatum = sFcfData.PrimaryDatum; cTextData.PrimaryMaterialModifier = sFcfData.PrimaryMaterialModifier; cTextData.SecondaryDatum = sFcfData.SecondaryDatum; cTextData.SecondaryMaterialModifier = sFcfData.SecondaryMaterialModifier; cTextData.TertiaryDatum = sFcfData.TertiaryDatum; cTextData.TertiaryMaterialModifier = sFcfData.TertiaryMaterialModifier; #endregion } else if (singleObjType == "NXOpen.Annotations.Label") { #region Label取Text cTextData.Type = "NXOpen.Annotations.Label"; NXOpen.Annotations.Label temp = (NXOpen.Annotations.Label)singleObj; cTextData.MainText = temp.GetText()[0]; #endregion } else if (singleObjType == "NXOpen.Annotations.DraftingDatum") { #region DraftingDatum取Text cTextData.Type = "NXOpen.Annotations.DraftingDatum"; NXOpen.Annotations.DraftingDatum temp = (NXOpen.Annotations.DraftingDatum)singleObj; #endregion } else if (singleObjType == "NXOpen.Annotations.DiameterDimension") { #region DiameterDimension取Text cTextData.Type = "NXOpen.Annotations.DiameterDimension"; NXOpen.Annotations.DiameterDimension temp = (NXOpen.Annotations.DiameterDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.AngularDimension") { #region AngularDimension取Text cTextData.Type = "NXOpen.Annotations.AngularDimension"; NXOpen.Annotations.AngularDimension temp = (NXOpen.Annotations.AngularDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.CylindricalDimension") { #region CylindricalDimension取Text cTextData.Type = "NXOpen.Annotations.CylindricalDimension"; NXOpen.Annotations.CylindricalDimension temp = (NXOpen.Annotations.CylindricalDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } if (temp.ToleranceType.ToString() == "BilateralTwoLines") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } if (temp.ToleranceType.ToString() == "UnilateralAbove") { cTextData.TolType = "UnilateralAbove"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = "0"; } if (temp.ToleranceType.ToString() == "UnilateralBelow") { cTextData.TolType = "UnilateralBelow"; cTextData.UpperTol = "0"; cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.ChamferDimension") { #region ChamferDimension取Text cTextData.Type = "NXOpen.Annotations.ChamferDimension"; NXOpen.Annotations.ChamferDimension temp = (NXOpen.Annotations.ChamferDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0] + "X" + "45" + "<$s>"; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } if (temp.ToleranceType.ToString() == "BilateralTwoLines") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } if (temp.ToleranceType.ToString() == "UnilateralAbove") { cTextData.TolType = "UnilateralAbove"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = "0"; } if (temp.ToleranceType.ToString() == "UnilateralBelow") { cTextData.TolType = "UnilateralBelow"; cTextData.UpperTol = "0"; cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } #endregion } //計算泡泡總數 DefineVariable.BallonCount++; DefineVariable.DicDimenData[BallonNum] = cTextData; } } //設定輸出路徑--Local //string[] FolderFile = System.IO.Directory.GetFileSystemEntries(Path.GetDirectoryName(displayPart.FullPath), "*.xls"); //string OutputPath = string.Format(@"{0}\{1}", Path.GetDirectoryName(displayPart.FullPath), // Path.GetFileNameWithoutExtension(displayPart.FullPath) + "_" + "IPQC" + "_" + (FolderFile.Length + 1) + ".xls"); //設定輸出路徑--Server string OperNum = Regex.Replace(Path.GetFileNameWithoutExtension(displayPart.FullPath).Split('_')[1], "[^0-9]", ""); string Local_Folder_OIS = string.Format(@"{0}\{1}\{2}", Path.GetDirectoryName(displayPart.FullPath), "OP" + OperNum, "OIS"); if (!File.Exists(Local_Folder_OIS)) { System.IO.Directory.CreateDirectory(Local_Folder_OIS); } string[] FolderFile = System.IO.Directory.GetFileSystemEntries(Local_Folder_OIS, "*.xls"); List <string> ListFolderFileWithFAI = new List <string>(); foreach (string i in FolderFile) { if (i.Contains("FAI")) { ListFolderFileWithFAI.Add(i); } } string OutputPath = string.Format(@"{0}\{1}", Local_Folder_OIS, Path.GetFileNameWithoutExtension(displayPart.FullPath) + "_" + "FAI" + "_" + (ListFolderFileWithFAI.Count + 1) + ".xls"); //檢查PC有無Excel在執行 foreach (var item in Process.GetProcesses()) { if (item.ProcessName == "EXCEL") { CaxLog.ShowListingWindow("請先關閉所有Excel再重新執行輸出,如沒有EXCEL在執行,請開啟工作管理員關閉背景EXCEL"); return(retValue); } else { continue; } } Excel.ApplicationClass x = new Excel.ApplicationClass(); Excel.Workbook book = null; Excel.Worksheet sheet = null; Excel.Range oRng = null; try { x.Visible = false; if (DefineVariable.Is_Local != "") { if (File.Exists(DefineVariable.FAIPath)) { book = x.Workbooks.Open(DefineVariable.FAIPath); } else { book = x.Workbooks.Open(@"D:\FAI.xls"); } } else { book = x.Workbooks.Open(@"D:\FAI.xls"); } //取得第一頁sheet sheet = (Excel.Worksheet)book.Sheets[1]; #region 處理第一頁 oRng = (Excel.Range)sheet.Cells; oRng[10, 1] = PartNo; oRng[10, 2] = PartDescription; #endregion //取得第二頁sheet sheet = (Excel.Worksheet)book.Sheets[2]; #region 處理第二頁 oRng = (Excel.Range)sheet.Cells; oRng[10, 1] = PartNo; oRng[10, 2] = PartDescription; #endregion //取得第三頁sheet sheet = (Excel.Worksheet)book.Sheets[3]; #region 處理第三頁 oRng = (Excel.Range)sheet.Cells; oRng[10, 1] = PartNo; oRng[10, 5] = PartDescription; //Insert所需欄位並填入資料 int CurrentRow = 16, BallonColumn = 1, LocationColumn = 2, DimenColumn = 4, GaugeColumn = 6; for (int i = 1; i < DefineVariable.BallonCount; i++) { oRng = (Excel.Range)sheet.Range["A17"].EntireRow; oRng.Insert(Excel.XlInsertShiftDirection.xlShiftDown, Excel.XlInsertFormatOrigin.xlFormatFromRightOrBelow); } //填表 for (int i = 1; i < 1000; i++) { TextData cTextData; DefineVariable.DicDimenData.TryGetValue(i.ToString(), out cTextData); if (cTextData == null) { continue; } oRng = (Excel.Range)sheet.Cells; //取得Row,Column CurrentRow = CurrentRow + 1; if (cTextData.Type == "NXOpen.Annotations.DraftingFcf") { #region DraftingFcf填資料 if (cTextData.Characteristic != "") { oRng[CurrentRow, DimenColumn] = DefineVariable.GetCharacteristicSymbol(cTextData.Characteristic); //oRng[sRowColumn.CharacteristicRow, sRowColumn.CharacteristicColumn] = DefineVariable.GetCharacteristicSymbol(cTextData.Characteristic); } if (cTextData.ZoneShape != "") { oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + DefineVariable.GetZoneShapeSymbol(cTextData.ZoneShape); //oRng[sRowColumn.ZoneShapeRow, sRowColumn.ZoneShapeColumn] = DefineVariable.GetZoneShapeSymbol(cTextData.ZoneShape); } oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.ToleranceValue; //oRng[sRowColumn.ToleranceValueRow, sRowColumn.ToleranceValueColumn] = cTextData.ToleranceValue; if (cTextData.MaterialModifier != "" & cTextData.MaterialModifier != "None") { string ValueStr = cTextData.MaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + ValueStr; //oRng[sRowColumn.MaterialModifierRow, sRowColumn.MaterialModifierColumn] = ValueStr; } //Primary oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.PrimaryDatum; //oRng[sRowColumn.PrimaryDatumRow, sRowColumn.PrimaryDatumColumn] = cTextData.PrimaryDatum; if (cTextData.PrimaryMaterialModifier != "" & cTextData.PrimaryMaterialModifier != "None") { string ValueStr = cTextData.PrimaryMaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + ValueStr; //oRng[sRowColumn.PrimaryMaterialModifierRow, sRowColumn.PrimaryMaterialModifierColumn] = ValueStr; } //Secondary oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.SecondaryDatum; //oRng[sRowColumn.SecondaryDatumRow, sRowColumn.SecondaryDatumColumn] = cTextData.SecondaryDatum; if (cTextData.SecondaryMaterialModifier != "" & cTextData.SecondaryMaterialModifier != "None") { string ValueStr = cTextData.SecondaryMaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + ValueStr; //oRng[sRowColumn.SecondaryMaterialModifierRow, sRowColumn.SecondaryMaterialModifierColumn] = ValueStr; } //Tertiary oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.TertiaryDatum; //oRng[sRowColumn.TertiaryDatumRow, sRowColumn.TertiaryDatumColumn] = cTextData.TertiaryDatum; if (cTextData.TertiaryMaterialModifier != "" & cTextData.TertiaryMaterialModifier != "None") { string ValueStr = cTextData.TertiaryMaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + ValueStr; //oRng[sRowColumn.TertiaryMaterialModifierRow, sRowColumn.TertiaryMaterialModifierColumn] = ValueStr; } #endregion } else if (cTextData.Type == "NXOpen.Annotations.Label") { oRng[CurrentRow, DimenColumn] = cTextData.MainText; //((Range)oRng[sRowColumn.MainTextRow, sRowColumn.MainTextColumn]).Interior.ColorIndex = 50; } else { #region Dimension填資料 if (cTextData.BeforeText != null) { oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + DefineVariable.GetGDTWord(cTextData.BeforeText); //oRng[sRowColumn.BeforeTextRow, sRowColumn.BeforeTextColumn] = DefineVariable.GetGDTWord(cTextData.BeforeText); } oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + DefineVariable.GetGDTWord(cTextData.MainText); //oRng[sRowColumn.MainTextRow, sRowColumn.MainTextColumn] = DefineVariable.GetGDTWord(cTextData.MainText); //Range a = (Range)oRng[sRowColumn.MainTextRow, sRowColumn.MainTextColumn]; //a.Interior.ColorIndex = 39; if (cTextData.UpperTol != "" & cTextData.TolType == "BilateralOneLine") { oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + "±"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.UpperTol; string MaxMinStr = "(" + (Convert.ToDouble(cTextData.MainText) + Convert.ToDouble(cTextData.UpperTol)).ToString() + "-" + (Convert.ToDouble(cTextData.MainText) - Convert.ToDouble(cTextData.UpperTol)).ToString() + ")"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + MaxMinStr; //oRng[sRowColumn.ToleranceSymbolRow, sRowColumn.ToleranceSymbolColumn] = "±"; //oRng[sRowColumn.UpperTolRow, sRowColumn.UpperTolColumn] = cTextData.UpperTol; } else if (cTextData.UpperTol != "" & cTextData.TolType == "BilateralTwoLines") { oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + "+"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.UpperTol; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + "/"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.LowerTol; string MaxMinStr = "(" + (Convert.ToDouble(cTextData.MainText) + Convert.ToDouble(cTextData.UpperTol)).ToString() + "-" + (Convert.ToDouble(cTextData.MainText) + Convert.ToDouble(cTextData.LowerTol)).ToString() + ")"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + MaxMinStr; } else if (cTextData.UpperTol != "" & cTextData.TolType == "UnilateralAbove") { oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + "+"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.UpperTol; } else if (cTextData.UpperTol != "" & cTextData.TolType == "UnilateralBelow") { //oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + "-"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.LowerTol; } #endregion } #region 檢具、頻率、Max、Min、泡泡、泡泡位置、料號、日期 oRng[CurrentRow, GaugeColumn] = cTextData.Gauge; //oRng[sRowColumn.FrequencyRow, sRowColumn.FrequencyColumn] = cTextData.Frequency; oRng[CurrentRow, BallonColumn] = cTextData.BallonNum; oRng[CurrentRow, LocationColumn] = cTextData.Location; //oRng[sRowColumn.PartNoRow, sRowColumn.PartNoColumn] = PartNo; //oRng[sRowColumn.DateRow, sRowColumn.DateColumn] = CurrentDate; #endregion } #endregion book.SaveAs(OutputPath, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); book.Close(Type.Missing, Type.Missing, Type.Missing); x.Quit(); //切回第一張Sheet DefineVariable.FirstDrawingSheet.Open(); UI.GetUI().NXMessageBox.Show("FAI", NXMessageBox.DialogType.Information, "輸出完成"); } catch (System.Exception ex) { book.SaveAs(OutputPath, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); book.Close(Type.Missing, Type.Missing, Type.Missing); x.Quit(); } } catch (NXOpen.NXException ex) { // ---- Enter your exception handling code here ----- } theProgram.Dispose(); return(retValue); }
private void OK_Click(object sender, EventArgs e) { CaxPart.SaveAll(); //Part上傳 List <string> ListPartName = new List <string>(); status = CaxMEUpLoad.UploadPart(DicPartDirData, out ListPartName); //status = Function.UploadPart(DicPartDirData, out ListPartName); if (!status) { this.Close(); return; } System.IO.File.WriteAllLines(string.Format(@"{0}\{1}\{2}", sDownUpLoadDat.Server_ShareStr, "OP" + cCaxMEUpLoad.OpNum, "PartNameText_OIS.txt"), ListPartName.ToArray()); //新增TE的下載文件 if (TEDownloadText.Count > 0) { string PartNameText_CAM = string.Format(@"{0}\{1}\{2}", sDownUpLoadDat.Server_ShareStr, "OP" + cCaxMEUpLoad.OpNum, "PartNameText_CAM.txt"); foreach (string i in TEDownloadText) { using (StreamWriter sw = File.AppendText(PartNameText_CAM)) { sw.WriteLine(i); } } } #region (註解)Excel上傳 /* * //Excel上傳 * if (File.Exists(sExcelDirData.ExcelIPQCLocalDir)) * { * try * { * File.Copy(sExcelDirData.ExcelIPQCLocalDir, sExcelDirData.ExcelIPQCServerDir, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("IPQC.xls上傳失敗"); * this.Close(); * } * } * * if (File.Exists(sExcelDirData.ExcelSelfCheckLocalDir)) * { * try * { * File.Copy(sExcelDirData.ExcelSelfCheckLocalDir, sExcelDirData.ExcelSelfCheckServerDir, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("SelfCheck.xls上傳失敗"); * this.Close(); * } * } * * if (File.Exists(sExcelDirData.ExcelIQCLocalDir)) * { * try * { * File.Copy(sExcelDirData.ExcelIQCLocalDir, sExcelDirData.ExcelIQCServerDir, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("IQC.xls上傳失敗"); * this.Close(); * } * } * * if (File.Exists(sExcelDirData.ExcelFAILocalDir)) * { * try * { * File.Copy(sExcelDirData.ExcelFAILocalDir, sExcelDirData.ExcelFAIServerDir, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("FAI.xls上傳失敗"); * this.Close(); * } * } * * if (File.Exists(sExcelDirData.ExcelFQCLocalDir)) * { * try * { * File.Copy(sExcelDirData.ExcelFQCLocalDir, sExcelDirData.ExcelFQCServerDir, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("FQC.xls上傳失敗"); * this.Close(); * } * } */ #endregion int SheetCount = 0; NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); List <NXOpen.Drawings.DrawingSheet> listDrawingSheet = new List <NXOpen.Drawings.DrawingSheet>(); for (int i = 0; i < SheetCount; i++) { //打開Sheet並記錄所有OBJ NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); listDrawingSheet.Add(CurrentSheet); } #region 輸出OIS //輸出PDF if (ExportPFD.Checked == true) { //建立PFD資料夾 string PFDFullPath = string.Format(@"{0}\{1}", sDownUpLoadDat.Local_Folder_OIS, cCaxMEUpLoad.PartName + "_OIS" + cCaxMEUpLoad.OpNum + ".pdf"); CaxME.CreateOISPDF(listDrawingSheet, PFDFullPath); //OIS資料夾上傳 status = CaxPublic.DirectoryCopy(sDownUpLoadDat.Local_Folder_OIS, sDownUpLoadDat.Server_Folder_OIS, true); if (!status) { MessageBox.Show("OIS資料夾複製失敗,請聯繫開發工程師"); this.Close(); } } #endregion #region 資料上傳至Database //取得WorkPart資訊並檢查資料是否完整 DadDimension.WorkPartAttribute sWorkPartAttribute = new DadDimension.WorkPartAttribute(); //status = Function.GetWorkPartAttribute(workPart, out sWorkPartAttribute); status = DadDimension.GetWorkPartAttribute(workPart, out sWorkPartAttribute); if (!status) { MessageBox.Show("量測資訊不足,僅上傳CAD檔案,上傳完成!"); this.Close(); return; } #region 取得所有量測尺寸資料 /* * //取得泡泡特徵,並記錄總共有幾個泡泡,後續比對數量用 * IdSymbolCollection BallonCollection = workPart.Annotations.IdSymbols; * IdSymbol[] BallonAry = BallonCollection.ToArray(); * int balloonCount = 0; * foreach (IdSymbol i in BallonAry) * { * try * { * i.GetStringAttribute("BalloonAtt"); * balloonCount++; * } * catch (System.Exception ex) * { * continue; * } * } * * List<CaxME.DimensionData> listDimensionData = new List<CaxME.DimensionData>(); * List<int> listBalloonCount = new List<int>(); * NXOpen.Drawings.DrawingSheet FirstSheet = null; * while (listBalloonCount.Count != balloonCount) * { * for (int i = 0; i < SheetCount; i++) * { * //打開Sheet並記錄所有OBJ * NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); * if (CurrentSheet.Name == "S1") * { * FirstSheet = CurrentSheet; * } * CurrentSheet.Open(); * CurrentSheet.View.UpdateDisplay(); * DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects(); * status = CaxME.RecordDimension(SheetObj, sWorkPartAttribute, ref listDimensionData); * if (!status) * { * this.Close(); * return; * } * } * foreach (CaxME.DimensionData i in listDimensionData) * { * if (!listBalloonCount.Contains(i.ballonNum)) * { * listBalloonCount.Add(i.ballonNum); * } * } * * } */ //List<CaxME.DimensionData> listDimensionData = new List<CaxME.DimensionData>(); List <DadDimension> listDimensionData = new List <DadDimension>(); NXOpen.Drawings.DrawingSheet FirstSheet = null; for (int i = 0; i < SheetCount; i++) { //打開Sheet並記錄所有OBJ NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); if (CurrentSheet.Name == "S1") { FirstSheet = CurrentSheet; } CurrentSheet.Open(); CurrentSheet.View.UpdateDisplay(); DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects(); status = Com_Dimension.RecordDimension(SheetObj, sWorkPartAttribute, ref listDimensionData); if (!status) { this.Close(); return; } } #endregion //切回首頁 if (FirstSheet != null) { FirstSheet.Open(); } //由料號查Com_PEMain Com_PEMain cCom_PEMain = new Com_PEMain(); status = CaxSQL.GetCom_PEMain(cCaxMEUpLoad.CusName, cCaxMEUpLoad.PartName, cCaxMEUpLoad.CusRev, cCaxMEUpLoad.OpRev, out cCom_PEMain); if (!status) { return; } //由Com_PEMain和Op查Com_PartOperation Com_PartOperation cCom_PartOperation = new Com_PartOperation(); status = CaxSQL.GetCom_PartOperation(cCom_PEMain, cCaxMEUpLoad.OpNum, out cCom_PartOperation); if (!status) { return; } #region (註解)由excelType查meExcelSrNo //Sys_MEExcel sysMEExcel = new Sys_MEExcel(); //try //{ // sysMEExcel = session.QueryOver<Sys_MEExcel>().Where(x => x.meExcelType == meExcelType).SingleOrDefault<Sys_MEExcel>(); //} //catch (System.Exception ex) //{ // MessageBox.Show("資料庫中沒有此料號的紀錄,故無法上傳量測尺寸,僅成功上傳實體檔案"); // return; //} #endregion #region 比對資料庫MEMain是否有同筆數據 IList <Com_MEMain> ListCom_MEMain = new List <Com_MEMain>(); CaxSQL.GetListCom_MEMain(out ListCom_MEMain); bool Is_Exist = false; Com_MEMain currentComMEMain = new Com_MEMain(); foreach (Com_MEMain i in ListCom_MEMain) { if (i.comPartOperation == cCom_PartOperation) { Is_Exist = true; currentComMEMain = i; break; } } #endregion #region 如果本次上傳的資料不存在於資料庫,則開始上傳資料;如果已存在資料庫,則詢問是否要更新尺寸 bool Is_Update = true; if (Is_Exist) { if (eTaskDialogResult.Yes == CaxPublic.ShowMsgYesNo("此料號已存在上一次的標註尺寸資料,是否更新?")) { #region 刪除Com_Dimension資料表 IList <Com_Dimension> ListCom_Dimension = new List <Com_Dimension>(); CaxSQL.GetListCom_Dimension(currentComMEMain, out ListCom_Dimension); foreach (Com_Dimension i in ListCom_Dimension) { CaxSQL.Delete <Com_Dimension>(i); } #endregion #region 刪除Com_MEMain資料表 Com_MEMain cCom_MEMain = new Com_MEMain(); CaxSQL.GetCom_MEMain(cCom_PartOperation, out cCom_MEMain); CaxSQL.Delete <Com_MEMain>(cCom_MEMain); #endregion } else { Is_Update = false; } } if (Is_Update) { #region 整理資料並上傳 try { Com_MEMain cCom_MEMain = new Com_MEMain(); cCom_MEMain.comPartOperation = cCom_PartOperation; //cCom_MEMain.sysMEExcel = sysMEExcel; cCom_MEMain.partDescription = sWorkPartAttribute.partDescription; cCom_MEMain.createDate = sWorkPartAttribute.createDate; cCom_MEMain.material = sWorkPartAttribute.material; cCom_MEMain.draftingVer = sWorkPartAttribute.draftingVer; IList <Com_Dimension> listCom_Dimension = new List <Com_Dimension>(); foreach (DadDimension i in listDimensionData) { Com_Dimension cCom_Dimension = new Com_Dimension(); cCom_Dimension.MappingData(i); cCom_Dimension.comMEMain = cCom_MEMain; listCom_Dimension.Add(cCom_Dimension); //Com_Dimension cCom_Dimension = new Com_Dimension(); //cCom_Dimension.comMEMain = cCom_MEMain; //CaxME.MappingData(i, ref cCom_Dimension); //listCom_Dimension.Add(cCom_Dimension); } cCom_MEMain.comDimension = listCom_Dimension; CaxSQL.Save <Com_MEMain>(cCom_MEMain); } catch (System.Exception ex) { MessageBox.Show("上傳資料庫時發生錯誤,僅上傳實體檔案"); } #endregion } #endregion #endregion CaxPart.Save(); MessageBox.Show("上傳完成!"); this.Close(); }