private void SGC_Panel_CellClick(object sender, GridCellClickEventArgs e) { try { if (CurrentRowIndex != -1) { DisplayableObject unhighlight = (DisplayableObject)NXObjectManager.Get((Tag)panel.GetCell(CurrentRowIndex, 0).Tag); unhighlight.Unhighlight(); } CurrentRowIndex = e.GridCell.GridRow.Index; DisplayableObject highlight = (DisplayableObject)NXObjectManager.Get((Tag)panel.GetCell(CurrentRowIndex, 0).Tag); highlight.Highlight(); workPart.Views.Refresh(); } catch (System.Exception ex) { } }
private void OK_Click(object sender, EventArgs e) { if (chb_keepOrigination.Checked == false && chb_Regeneration.Checked == false && chb_UserDefine.Checked == false) { this.Hide(); UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Information, "請先選擇一個選項"); this.Show(); return; } if (chb_keepOrigination.Checked == true) { Is_Keep = true; this.DialogResult = DialogResult.Yes; this.Close(); } if (chb_Regeneration.Checked == true) { Is_Keep = false; this.DialogResult = DialogResult.Yes; this.Close(); } if (chb_UserDefine.Checked == true) { //判斷所有的泡泡是否有重複 List <string> ListIsRepeat = new List <string>(); foreach (GridRow i in SGC.PrimaryGrid.Rows) { if (i.Cells["自定泡泡號"].Value.ToString() == "") { continue; } if (ListIsRepeat.Contains(i.Cells["自定泡泡號"].Value.ToString())) { MessageBox.Show("泡泡號【" + i.Cells["自定泡泡號"].Value.ToString() + "】重複,請重新檢查"); return; } else { ListIsRepeat.Add(i.Cells["自定泡泡號"].Value.ToString()); } } CoordinateData cCoordinateData = new CoordinateData(); CaxGetDatData.GetDraftingCoordinateData(out cCoordinateData); //開始插入自定義泡泡 foreach (GridRow i in SGC.PrimaryGrid.Rows) { //判斷是否有舊的泡泡,如果舊泡泡與自定的相同,則跳下一個 //判斷是否有舊的泡泡,如果舊泡泡與自定的不相同,則先刪除泡泡再重新產生 //如有Dicount也要加入一起生成 //如果沒有自定泡泡就跳下一個row if (i.Cells["自定泡泡號"].Value.ToString() == "") { //判斷是否需刪除已存在的泡泡 NXOpen.Drawings.DrawingSheet drawingSheet1 = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(i.Cells["尺寸位置"].Value.ToString()); string oldBalloon = ""; try { oldBalloon = ((NXObject)i.Cells["Dimension"].Value).GetStringAttribute(CaxME.DimenAttr.BallonNum); } catch (System.Exception ex) { continue; } NXObject[] SheetObj = CaxME.FindObjectsInView(drawingSheet1.View.Tag).ToArray(); CaxME.DeleteBallon(oldBalloon, SheetObj); workPart.Views.Refresh(); //刪除屬性 ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.BallonNum); ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.BallonLocation); ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.SheetName); continue; } //如果回傳False,表示舊泡泡=自定泡泡;如果回傳True,表示舊泡泡=\=自定泡泡 if (!JudgmentBalloon(i)) { continue; } InsertBalloon(i, cCoordinateData); } if (exOnj != null) { exOnj.Unhighlight(); workPart.Views.Refresh(); } //(NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(ListSheet.Text) //((NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject("S1")).Open(); this.Close(); } }
private void OK_Click(object sender, EventArgs e) { //抓取目前圖紙數量和Tag int SheetCount = 0; NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); //取得最後一顆泡泡的數字 int MaxBallonNum; try { MaxBallonNum = Convert.ToInt32(workPart.GetStringAttribute(CaxME.DimenAttr.BallonNum)); } catch (System.Exception ex) { MaxBallonNum = 0; } if (chb_Regeneration.Checked == true) { #region 刪除全部泡泡 IdSymbolCollection BallonCollection = workPart.Annotations.IdSymbols; IdSymbol[] BallonAry = BallonCollection.ToArray(); foreach (IdSymbol i in BallonAry) { try { i.GetStringAttribute("BalloonAtt"); } catch (System.Exception ex) { continue; } CaxPublic.DelectObject(i); } workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "BALLONNUM"); #endregion for (int i = 0; i < SheetCount; i++) { //打開Sheet並記錄所有OBJ DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); CurrentSheet.Open(); if (i == 0) { Variables.FirstDrawingSheet = CurrentSheet; } int BallonNum = 0; NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray(); foreach (NXObject singleObj in SheetObj) { string diCount = "", fixDiemnsion = ""; #region 刪除尺寸數量產生的文字(ex:a-c) try { diCount = singleObj.GetStringAttribute(CaxME.DimenAttr.DiCount); } catch (System.Exception ex) { diCount = ""; } try { fixDiemnsion = singleObj.GetStringAttribute(CaxME.DimenAttr.FixDimension); } catch (System.Exception ex) { fixDiemnsion = ""; } if (diCount != "" && fixDiemnsion == "") { CaxPublic.DelectObject(singleObj); } #endregion string AssignExcelType = ""; #region 判斷是否有屬性,沒有屬性就跳下一個 try { AssignExcelType = singleObj.GetStringAttribute(CaxME.DimenAttr.FixDimension); } catch (System.Exception ex) { continue; } #endregion //事先塞入該尺寸所在Sheet singleObj.SetAttribute("SheetName", CurrentSheet.Name); CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate(); CaxME.GetTextBoxCoordinate(singleObj.Tag, out cBoxCoordinate); #region 計算泡泡座標 CaxME.DimenData sDimenData = new CaxME.DimenData(); sDimenData.Obj = singleObj; sDimenData.CurrentSheet = CurrentSheet; CaxME.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData); #endregion sDimenData.CurrentSheet.Open(); Point3d BallonLocation = new Point3d(); BallonLocation.X = sDimenData.LocationX; BallonLocation.Y = sDimenData.LocationY; BallonNum++; InsertBalloon(BallonNum, diCount, BallonLocation); singleObj.SetAttribute(CaxME.DimenAttr.BallonNum, BallonNum.ToString()); } //將最後一顆泡泡的數字插入零件中 workPart.SetAttribute(CaxME.DimenAttr.BallonNum, BallonNum.ToString()); } } else if (chb_keepOrigination.Checked == true) { for (int i = 0; i < SheetCount; i++) { //打開Sheet並記錄所有OBJ DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); CurrentSheet.Open(); if (i == 0) { Variables.FirstDrawingSheet = CurrentSheet; } NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray(); foreach (NXObject singleObj in SheetObj) { //判斷是否取到舊的尺寸,如果是就跳下一個 string OldBallonNum = ""; try { OldBallonNum = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonNum); continue; } catch (System.Exception ex) { } string AssignExcelType = ""; #region 判斷是否有屬性,沒有屬性就跳下一個 try { AssignExcelType = singleObj.GetStringAttribute(CaxME.DimenAttr.FixDimension); } catch (System.Exception ex) { continue; } #endregion //事先塞入該尺寸所在Sheet singleObj.SetAttribute("SheetName", CurrentSheet.Name); CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate(); CaxME.GetTextBoxCoordinate(singleObj.Tag, out cBoxCoordinate); #region 計算泡泡座標 CaxME.DimenData sDimenData = new CaxME.DimenData(); sDimenData.Obj = singleObj; sDimenData.CurrentSheet = CurrentSheet; CaxME.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData); #endregion sDimenData.CurrentSheet.Open(); Point3d BallonLocation = new Point3d(); BallonLocation.X = sDimenData.LocationX; BallonLocation.Y = sDimenData.LocationY; MaxBallonNum++; string diCount = ""; try { diCount = singleObj.GetStringAttribute(CaxME.DimenAttr.DiCount); } catch (System.Exception ex) { diCount = "1"; } InsertBalloon(MaxBallonNum, diCount, BallonLocation); singleObj.SetAttribute(CaxME.DimenAttr.BallonNum, MaxBallonNum.ToString()); } //將最後一顆泡泡的數字插入零件中 workPart.SetAttribute(CaxME.DimenAttr.BallonNum, MaxBallonNum.ToString()); } } else if (chb_UserDefine.Checked == true) { //判斷所有的泡泡是否有重複 List <string> ListIsRepeat = new List <string>(); foreach (GridRow i in SGC.PrimaryGrid.Rows) { if (i.Cells["自定泡泡號"].Value.ToString() == "") { continue; } if (ListIsRepeat.Contains(i.Cells["自定泡泡號"].Value.ToString())) { MessageBox.Show("泡泡號【" + i.Cells["自定泡泡號"].Value.ToString() + "】重複,請重新檢查"); return; } else { ListIsRepeat.Add(i.Cells["自定泡泡號"].Value.ToString()); } } CoordinateData cCoordinateData = new CoordinateData(); CaxGetDatData.GetDraftingCoordinateData(out cCoordinateData); //開始插入自定義泡泡 foreach (GridRow i in SGC.PrimaryGrid.Rows) { //判斷是否有舊的泡泡,如果舊泡泡與自定的相同,則跳下一個 //判斷是否有舊的泡泡,如果舊泡泡與自定的不相同,則先刪除泡泡再重新產生 //如有Dicount也要加入一起生成 //如果沒有自定泡泡就跳下一個row if (i.Cells["自定泡泡號"].Value.ToString() == "") { //判斷是否需刪除已存在的泡泡 NXOpen.Drawings.DrawingSheet drawingSheet1 = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(i.Cells["尺寸位置"].Value.ToString()); string oldBalloon = ""; try { oldBalloon = ((NXObject)i.Cells["Dimension"].Value).GetStringAttribute(CaxME.DimenAttr.BallonNum); } catch (System.Exception ex) { continue; } NXObject[] SheetObj = CaxME.FindObjectsInView(drawingSheet1.View.Tag).ToArray(); CaxME.DeleteBallon(oldBalloon, SheetObj); workPart.Views.Refresh(); //刪除屬性 ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.BallonNum); ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.BallonLocation); ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.SheetName); continue; } //如果回傳False,表示舊泡泡=自定泡泡;如果回傳True,表示舊泡泡=\=自定泡泡 if (!JudgmentBalloon(i)) { continue; } InsertBalloon(i, cCoordinateData); } if (exOnj != null) { exOnj.Unhighlight(); workPart.Views.Refresh(); } } MessageBox.Show("完成!"); }