//应用回调 private void Apply() { try { NXFun.SetHighlight(oldhighlight, false); Session.UndoMarkId undomark = Program.theSession.SetUndoMark(Session.MarkVisibility.Visible, "打标号"); foreach (DimInfor listitem in LabelDimList) { if (listitem.isLabel == "是") { if (listitem.is_herited) //PMIdimention { NXOpen.Annotations.BalloonNote balloon = NXFun.FindObjectByAttr <NXOpen.Annotations.BalloonNote>("GUID", listitem.guid); if (balloon == null) { //没找到 添加 NXFun.SetDisplayState(1); NXOpen.Annotations.BalloonNote balloonnote = NXFun.AddBalloonNote((NXOpen.Annotations.Annotation)listitem.dim, listitem.id.ToString(), listitem); NXFun.SetDisplayState(2); //找到二维继承的BalloonNote并设置大小。 NXOpen.Annotations.PmiAttribute[] bns = Session.GetSession().Parts.Work.PmiManager.PmiAttributes.ToArray(); foreach (NXOpen.Annotations.PmiAttribute pmi in bns) { NXOpen.Annotations.Lettering Lettering = balloonnote.GetLetteringPreferences().GetDimensionText(); if (NXFun.GetInheritParent(pmi).Equals(balloonnote) && !pmi.Equals(balloonnote)) { NXFun.EditBalloonNoteSize((NXOpen.Annotations.BalloonNote)pmi, Lettering); } } } else { //找到 改写 NXFun.EditBalloonNote(balloon, listitem.id.ToString(), listitem); } NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel); NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id); } else //普通dimention { //找到IdSymbol 并改写 否则添加 NXOpen.Annotations.IdSymbol idsymbol = NXFun.FindObjectByAttr <NXOpen.Annotations.IdSymbol>("GUID", listitem.guid); if (idsymbol == null) { //没找到 添加 NXFun.AddIdSymbol((NXOpen.Annotations.Annotation)listitem.dim, listitem.id.ToString(), listitem); } else { //找到 改写 NXFun.EditIdSymbol(idsymbol, listitem.id.ToString(), listitem); } NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel); NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id); } } else if (listitem.isLabel == "否") { if (listitem.is_herited) //PMIdimention { NXOpen.Annotations.BalloonNote balloon = NXFun.FindObjectByAttr <NXOpen.Annotations.BalloonNote>("GUID", listitem.guid); if (balloon != null) { NXFun.DeleteBalloonNoteByAttr("GUID", listitem.guid); } NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel); NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id); } else //普通dimention { //找到IdSymbol 并改写 否则添加 NXOpen.Annotations.IdSymbol idsymbol = NXFun.FindObjectByAttr <NXOpen.Annotations.IdSymbol>("GUID", listitem.guid); if (idsymbol != null) { NXFun.DeleteIdSymbolByAttr("GUID", listitem.guid); } NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel); NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id); } } } foreach (DimInfor listitem in LabelFcfList) { string num = "J<C0.5>" + listitem.id.ToString() + "<C>"; if (listitem.isLabel == "是") { if (listitem.is_herited) //Fcf { NXOpen.Annotations.BalloonNote balloon = NXFun.FindObjectByAttr <NXOpen.Annotations.BalloonNote>("GUID", listitem.guid); if (balloon == null) { //没找到 添加 NXFun.SetDisplayState(1); NXOpen.Annotations.BalloonNote balloonnote = NXFun.AddBalloonNote((NXOpen.Annotations.Annotation)listitem.dim, num, listitem); NXFun.SetDisplayState(2); //找到二维继承的BalloonNote并设置大小。 NXOpen.Annotations.PmiAttribute[] bns = Session.GetSession().Parts.Work.PmiManager.PmiAttributes.ToArray(); foreach (NXOpen.Annotations.PmiAttribute pmi in bns) { NXOpen.Annotations.Lettering Lettering = balloonnote.GetLetteringPreferences().GetDimensionText(); if (NXFun.GetInheritParent(pmi).Equals(balloonnote) && !pmi.Equals(balloonnote)) { NXFun.EditBalloonNoteSize((NXOpen.Annotations.BalloonNote)pmi, Lettering); } } } else { //找到 改写 NXFun.EditBalloonNote(balloon, num, listitem); } NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel); NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id); } else //普通DraftingFcf { //找到IdSymbol 并改写 否则添加 NXOpen.Annotations.IdSymbol idsymbol = NXFun.FindObjectByAttr <NXOpen.Annotations.IdSymbol>("GUID", listitem.guid); if (idsymbol == null) { //没找到 添加 NXFun.AddIdSymbol((NXOpen.Annotations.Annotation)listitem.dim, num, listitem); } else { //找到 改写 NXFun.EditIdSymbol(idsymbol, num, listitem); } NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel); NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id); } } else if (listitem.isLabel == "否") { if (listitem.is_herited) //Fcf { NXOpen.Annotations.BalloonNote balloon = NXFun.FindObjectByAttr <NXOpen.Annotations.BalloonNote>("GUID", listitem.guid); if (balloon != null) { NXFun.DeleteBalloonNoteByAttr("GUID", listitem.guid); } NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel); NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id); } else //DraftingFcf { //找到IdSymbol 并改写 否则添加 NXOpen.Annotations.IdSymbol idsymbol = NXFun.FindObjectByAttr <NXOpen.Annotations.IdSymbol>("GUID", listitem.guid); if (idsymbol != null) { NXFun.DeleteIdSymbolByAttr("GUID", listitem.guid); } NXFun.SetStringAttr((NXObject)listitem.dimParent, "DISP", listitem.isLabel); NXFun.SetIntegerAttr((NXObject)listitem.dimParent, "ID", listitem.id); } } } Program.theSession.UpdateManager.DoUpdate(undomark); } catch (System.Exception ex) { UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message); } }
//------------------------------------------------------------------------------ // 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 != "") { //取得本機IPQC.xls路徑 DefineVariable.FQCPath = string.Format(@"{0}\{1}\{2}", Path.GetDirectoryName(displayPart.FullPath), "MODEL", "FQC.xls"); } //取得料號 string PartNo = ""; try { PartNo = displayPart.GetStringAttribute("PARTNUMBERPOS"); } catch (System.Exception ex) { PartNo = ""; } 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 FQC_Gauge = "", BallonNum = "", Frequency = "", Location = ""; string[] mainText; string[] dualText; #region 取FQC共用屬性(泡泡值、檢具名稱、檢驗頻率、泡泡所在區域),如果都沒屬性就找下一個 try { FQC_Gauge = singleObj.GetStringAttribute(CaxME.DimenAttr.FQC_Gauge); BallonNum = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonNum); Frequency = singleObj.GetStringAttribute(CaxME.DimenAttr.FQC_Freq); Location = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonLocation); } catch (System.Exception ex) { FQC_Gauge = ""; } if (FQC_Gauge == "") { continue; } #endregion #region 紀錄共用屬性(泡泡值、檢具名稱、檢驗頻率、泡泡所在區域) //取得泡泡值 cTextData.BallonNum = BallonNum; //取得檢具名稱 cTextData.Gauge = FQC_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"); int ExcelCount = 0; foreach (string i in FolderFile) { if (i.Contains("FQC")) { ExcelCount++; } } string OutputPath = string.Format(@"{0}\{1}", Local_Folder_OIS, Path.GetFileNameWithoutExtension(displayPart.FullPath) + "_" + "FQC" + "_" + (ExcelCount + 1) + ".xls"); //檢查PC有無Excel在執行 foreach (var item in Process.GetProcesses()) { if (item.ProcessName == "EXCEL") { MessageBox.Show("請先關閉所有Excel再重新執行輸出,如沒有EXCEL在執行,請開啟工作管理員關閉背景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.FQCPath)) { book = x.Workbooks.Open(DefineVariable.FQCPath); } else { book = x.Workbooks.Open(@"D:\FQC.xls"); } } else { book = x.Workbooks.Open(@"D:\FQC.xls"); } sheet = (Excel.Worksheet)book.Sheets[1]; oRng = (Excel.Range)sheet.Cells; oRng[5, 5] = PartNo; //Insert所需欄位並填入資料 int CurrentRow = 7, BallonColumn = 1, LocationColumn = 2, DimenColumn = 3, GaugeColumn = 4; //填表 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 } 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("FQC", 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); }
public static bool CreateBallonOnSheet(string Number, Point3d BallonPt) { try {// ---------------------------------------------- // Menu: Insert->Annotation->Identification Symbol... // ---------------------------------------------- NXOpen.Session.UndoMarkId markId1; markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start"); NXOpen.Annotations.IdSymbol nullAnnotations_IdSymbol = null; NXOpen.Annotations.IdSymbolBuilder idSymbolBuilder1; idSymbolBuilder1 = workPart.Annotations.IdSymbols.CreateIdSymbolBuilder(nullAnnotations_IdSymbol); idSymbolBuilder1.Origin.Plane.PlaneMethod = NXOpen.Annotations.PlaneBuilder.PlaneMethodType.XyPlane; idSymbolBuilder1.Origin.SetInferRelativeToGeometry(false); idSymbolBuilder1.Origin.Anchor = NXOpen.Annotations.OriginBuilder.AlignmentPosition.MidCenter; idSymbolBuilder1.UpperText = "<C0.7>" + Number + "<C>"; idSymbolBuilder1.Size = 3.5; theSession.SetUndoMarkName(markId1, "Identification Symbol Dialog"); idSymbolBuilder1.Origin.Plane.PlaneMethod = NXOpen.Annotations.PlaneBuilder.PlaneMethodType.XyPlane; idSymbolBuilder1.Origin.SetInferRelativeToGeometry(false); NXOpen.Annotations.LeaderData leaderData1; leaderData1 = workPart.Annotations.CreateLeaderData(); leaderData1.StubSize = 5.0; leaderData1.Arrowhead = NXOpen.Annotations.LeaderData.ArrowheadType.FilledArrow; idSymbolBuilder1.Leader.Leaders.Append(leaderData1); leaderData1.StubSide = NXOpen.Annotations.LeaderSide.Inferred; idSymbolBuilder1.Origin.SetInferRelativeToGeometry(false); idSymbolBuilder1.Origin.SetInferRelativeToGeometry(false); NXOpen.Annotations.Annotation.AssociativeOriginData assocOrigin1; assocOrigin1.OriginType = NXOpen.Annotations.AssociativeOriginType.Drag; View nullView = null; assocOrigin1.View = nullView; assocOrigin1.ViewOfGeometry = nullView; Point nullPoint = null; assocOrigin1.PointOnGeometry = nullPoint; assocOrigin1.VertAnnotation = null; assocOrigin1.VertAlignmentPosition = NXOpen.Annotations.AlignmentPosition.TopLeft; assocOrigin1.HorizAnnotation = null; assocOrigin1.HorizAlignmentPosition = NXOpen.Annotations.AlignmentPosition.TopLeft; assocOrigin1.AlignedAnnotation = null; assocOrigin1.DimensionLine = 0; assocOrigin1.AssociatedView = nullView; assocOrigin1.AssociatedPoint = nullPoint; assocOrigin1.OffsetAnnotation = null; assocOrigin1.OffsetAlignmentPosition = NXOpen.Annotations.AlignmentPosition.TopLeft; assocOrigin1.XOffsetFactor = 0.0; assocOrigin1.YOffsetFactor = 0.0; assocOrigin1.StackAlignmentPosition = NXOpen.Annotations.StackAlignmentPosition.Above; idSymbolBuilder1.Origin.SetAssociativeOrigin(assocOrigin1); Point3d point1 = new Point3d(BallonPt.X, BallonPt.Y, 0.0); idSymbolBuilder1.Origin.Origin.SetValue(null, nullView, point1); idSymbolBuilder1.Origin.SetInferRelativeToGeometry(false); NXOpen.Session.UndoMarkId markId2; markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Identification Symbol"); NXObject nXObject1; nXObject1 = idSymbolBuilder1.Commit(); theSession.DeleteUndoMark(markId2, null); theSession.SetUndoMarkName(markId1, "Identification Symbol"); theSession.SetUndoMarkVisibility(markId1, null, NXOpen.Session.MarkVisibility.Visible); idSymbolBuilder1.Destroy(); NXOpen.Session.UndoMarkId markId3; markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start"); NXOpen.Annotations.IdSymbolBuilder idSymbolBuilder2; idSymbolBuilder2 = workPart.Annotations.IdSymbols.CreateIdSymbolBuilder(nullAnnotations_IdSymbol); idSymbolBuilder2.Origin.Plane.PlaneMethod = NXOpen.Annotations.PlaneBuilder.PlaneMethodType.XyPlane; idSymbolBuilder2.Origin.SetInferRelativeToGeometry(false); idSymbolBuilder2.Origin.Anchor = NXOpen.Annotations.OriginBuilder.AlignmentPosition.MidCenter; idSymbolBuilder2.UpperText = "<C1>5<C>"; idSymbolBuilder2.Size = 3.5; idSymbolBuilder2.Style.LineArrowStyle.TextToLineDistance = 0.0; theSession.SetUndoMarkName(markId3, "Identification Symbol Dialog"); idSymbolBuilder2.Origin.Plane.PlaneMethod = NXOpen.Annotations.PlaneBuilder.PlaneMethodType.XyPlane; idSymbolBuilder2.Origin.SetInferRelativeToGeometry(false); NXOpen.Annotations.LeaderData leaderData2; leaderData2 = workPart.Annotations.CreateLeaderData(); leaderData2.StubSize = 5.0; leaderData2.Arrowhead = NXOpen.Annotations.LeaderData.ArrowheadType.FilledArrow; idSymbolBuilder2.Leader.Leaders.Append(leaderData2); leaderData2.StubSide = NXOpen.Annotations.LeaderSide.Inferred; idSymbolBuilder2.Origin.SetInferRelativeToGeometry(false); idSymbolBuilder2.Origin.SetInferRelativeToGeometry(false); // ---------------------------------------------- // Dialog Begin Identification Symbol // ---------------------------------------------- idSymbolBuilder2.Destroy(); theSession.UndoToMark(markId3, null); theSession.DeleteUndoMark(markId3, null); // ---------------------------------------------- // Menu: Tools->Journal->Stop Recording // ---------------------------------------------- } catch (System.Exception ex) { return(false); } return(true); }