private void DraftingBox_SelectedIndexChanged(object sender, EventArgs e) { try { //清空Panel資訊 panel.Rows.Clear(); //取得試圖上的所有尺寸 NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(DraftingBox.Text); CurrentSheet.Open(); CurrentSheet.View.UpdateDisplay(); DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects(); GridRow row = new GridRow(); int count = -1; foreach (DisplayableObject singleObj in SheetObj) { //取得泡泡,如果沒泡泡表示不是尺寸的資訊 string balloon = ""; try { balloon = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonNum); } catch (System.Exception ex) { continue; } string customerBalloon = ""; try { customerBalloon = singleObj.GetStringAttribute("CustomerBalloon"); } catch (System.Exception ex) { customerBalloon = ""; } listDisplayObj.Add(singleObj); count++; //singleObj.Highlight(); row = new GridRow(balloon, customerBalloon); panel.Rows.Add(row); panel.GetCell(count, 0).Tag = singleObj.Tag; } } catch (System.Exception ex) { } }
public static bool RenameSheet(int SheetCount, Tag[] SheetTagAry) { try { int count = 2;//續頁從S2開始 for (int i = 0; i < SheetCount; i++) { //輪巡每個Sheet NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); CurrentSheet.Open(); NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray(); string SheetType = ""; foreach (NXObject obj in SheetObj) { try { SheetType = obj.GetStringAttribute("SheetType"); break; } catch (System.Exception ex) { continue; } } if (SheetType == "1") { CaxME.SheetRename(CurrentSheet, "S1"); } else { CaxME.SheetRename(CurrentSheet, "S" + count.ToString()); count++; } } } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return(false); } return(true); }
private bool InitialDraftingData() { try { int SheetCount = 0; //NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); for (int i = 0; i < SheetCount; i++) { NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); DraftingBox.Items.Add(CurrentSheet.Name); } //預設開啟sheet1圖紙 NXOpen.Drawings.DrawingSheet DefaultSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0]); DraftingBox.Text = DefaultSheet.Name; DefaultSheet.Open(); } catch (System.Exception ex) { return(false); } return(true); }
//------------------------------------------------------------------------------ // 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); }
//------------------------------------------------------------------------------ // 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); }
private void OK_Click(object sender, EventArgs e) { //抓取目前圖紙數量和Tag int SheetCount = 0; NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); //NXOpen.Drawings.DrawingSheet aaa = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0]); //NXOpen.Drawings.DrawingSheet bb = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[1]); TablePosi cTablePosi = new TablePosi(); DicPartInformation = new Dictionary <string, string>(); for (int i = 0; i < SheetCount; i++) { if (i == 0) { DicPartInformation.Add(cTablePosi.PartNumberPos, PartNumberText.Text); DicPartInformation.Add(cTablePosi.PartDescriptionPos, PartDescriptionText.Text); DicPartInformation.Add(cTablePosi.PartUnitPos, PartUnitText.Text); DicPartInformation.Add(cTablePosi.RevStartPos, DraftingRevText.Text); DicPartInformation.Add(cTablePosi.RevDateStartPos, DateTime.Now.ToShortDateString()); DicPartInformation.Add(cTablePosi.AuthDatePos, DateTime.Now.ToShortDateString()); DicPartInformation.Add(cTablePosi.MaterialPos, MaterialText.Text); DicPartInformation.Add(cTablePosi.PageNumberPos, "1/" + SheetCount.ToString()); } else { bool check = false; string tempSecondPartNumberPos = "", tempSecondPageNumberPos = ""; check = DicPartInformation.TryGetValue(cTablePosi.SecondPartNumberPos, out tempSecondPartNumberPos); if (!check) { DicPartInformation.Add(cTablePosi.SecondPartNumberPos, PartNumberText.Text); } //check = DicPartInformation.TryGetValue(cTablePosi.SecondPageNumberPos, out tempSecondPageNumberPos); //if (check) //{ // tempSecondPageNumberPos = tempSecondPageNumberPos + "," + (i + 1).ToString() + "/" + SheetCount.ToString(); // DicPartInformation[cTablePosi.SecondPageNumberPos] = tempSecondPageNumberPos; //} //else //{ // DicPartInformation.Add(cTablePosi.SecondPageNumberPos, (i + 1).ToString() + "/" + SheetCount.ToString()); //} } } for (int i = 0; i < SheetCount; i++) { //輪巡每個Sheet NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); NXOpen.Drawings.DrawingSheet drawingSheet1 = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(CurrentSheet.Name); drawingSheet1.Open(); //寫入頁數資訊(加入sheet2以上) if (i > 0) { string tempString = (i + 1).ToString() + "/" + SheetCount.ToString(); DicPartInformation[cTablePosi.SecondPageNumberPos] = tempString; } for (int ii = 0; ii < cDraftingConfig.Drafting.Count; ii++) { string SheetSize = cDraftingConfig.Drafting[ii].SheetSize; if (Math.Ceiling(CurrentSheet.Height) == Convert.ToDouble(SheetSize.Split(',')[0]) && Math.Ceiling(CurrentSheet.Length) == Convert.ToDouble(SheetSize.Split(',')[1])) { foreach (KeyValuePair <string, string> kvp in DicPartInformation) { if (i == 0 && (kvp.Key == cTablePosi.SecondPageNumberPos || kvp.Key == cTablePosi.SecondPartNumberPos)) { continue; } else if (i != 0 && kvp.Key != cTablePosi.SecondPageNumberPos && kvp.Key != cTablePosi.SecondPartNumberPos) { continue; } Point3d TextPt = new Point3d(); string FontSize = ""; GetTextPos(ii, kvp.Key, kvp.Value, out TextPt, out FontSize); InsertNote(kvp.Value, TextPt, FontSize); } } } } //塞入屬性 foreach (KeyValuePair <string, string> kvp in DicPartInformation) { if (kvp.Key == cTablePosi.SecondPageNumberPos || kvp.Key == cTablePosi.SecondPartNumberPos) { continue; } workPart.SetAttribute(kvp.Key, kvp.Value); } //Tag b; //theUfSession.Draw.AskCurrentDrawing(out b); //NXOpen.Drawings.DrawingSheet aa = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(b); //for (int i = 0; i < cDraftingConfig.Drafting.Count;i++ ) //{ // string SheetSize = cDraftingConfig.Drafting[i].SheetSize; // if (Math.Ceiling(aa.Height) == Convert.ToDouble(SheetSize.Split(',')[0]) && Math.Ceiling(aa.Length) == Convert.ToDouble(SheetSize.Split(',')[1])) // { // foreach (KeyValuePair<string,string> kvp in DicPartInformation) // { // Point3d TextPt = new Point3d(); // string FontSize = ""; // GetTextPos(i, kvp.Key, kvp.Value, out TextPt, out FontSize); // InsertNote(kvp.Value, TextPt, FontSize); // } // } //} }
private void ListSheet_SelectedIndexChanged(object sender, EventArgs e) { NXOpen.Drawings.DrawingSheet drawingSheet1 = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(ListSheet.Text); drawingSheet1.Open(); }
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 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(); }