//------------------------------------------------------------------------------ //Callback Name: apply_cb //------------------------------------------------------------------------------ public int apply_cb() { int errorCode = 0; try { //---- Enter your callback code here ----- Session.UndoMarkId markId = Session.GetSession().SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "删除电极"); ElectrodeModel ele = new ElectrodeModel(); NXOpen.Assemblies.Component eleComp = this.selection_Ele.GetSelectedObjects()[0] as NXOpen.Assemblies.Component; Part elePart = eleComp.Prototype as Part; ele.GetModelForPart(elePart); int ok = theUI.NXMessageBox.Show("删除", NXOpen.NXMessageBox.DialogType.Question, elePart.Name + "电极是否删除"); if (ok == 1) { string path = elePart.FullPath; elePart.Close(NXOpen.BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, null); AssmbliesUtils.DeleteComponent(eleComp); LayerUtils.MoveDisplayableObject(ele.EleInfo.EleNumber + 10, LayerUtils.GetAllObjectsOnLayer(ele.EleInfo.EleNumber + 100)); if (File.Exists(path)) { File.Delete(path); } } } catch (Exception ex) { //---- Enter your exception handling code here ----- errorCode = 1; theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return(errorCode); }
public MachinedSurface() { try { InitializeComponent(); theSession = Session.GetSession(); NXOpenUI.FormUtilities.ReparentForm(this); NXOpenUI.FormUtilities.SetApplicationIcon(this); undomark = theSession.SetUndoMark(Session.MarkVisibility.Visible, "加工面标注"); //记录并改变View的类型 Part workpart = theSession.Parts.Work; foreach (NXOpen.Drawings.DraftingView draftingview in workpart.DraftingViews) { NXOpen.Preferences.GeneralExtractedEdgesOption type = NXFun.GetViewEdgesPreference(draftingview); map.Add(draftingview, type); NXFun.SetViewEdgesPreference(draftingview, NXOpen.Preferences.GeneralExtractedEdgesOption.Associative); } label1.Text = "- 请选择加工面 (0)"; //开始监控选定的东东 this.timer1.Start(); } catch (System.Exception ex) { UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message); } }
internal static Snap.NX.Bsurface CreateBsurface(Position[,] poles, double[,] weights, double[] knotsU, double[] knotsV) { int num10; int num11; Tag tag; int length = poles.GetLength(0); int num2 = knotsU.Length; int ku = num2 - length; int nv = poles.GetLength(1); int num5 = knotsV.Length; int kv = num5 - nv; double[] numArray = new double[(4 * length) * nv]; for (int i = 0; i < length; i++) { for (int j = 0; j < nv; j++) { int index = 4 * ((length * j) + i); numArray[index] = poles[i, j].X * weights[i, j]; numArray[index + 1] = poles[i, j].Y * weights[i, j]; numArray[index + 2] = poles[i, j].Z * weights[i, j]; numArray[index + 3] = weights[i, j]; } } Globals.UFSession.Modl.CreateBsurf(length, nv, ku, kv, knotsU, knotsV, numArray, out tag, out num10, out num11); NXOpen.Body objectFromTag = (NXOpen.Body)Snap.NX.NXObject.GetObjectFromTag(tag); Session.UndoMarkId undoMark = Globals.Session.SetUndoMark(Session.MarkVisibility.Invisible, ""); Globals.Session.UpdateManager.DoUpdate(undoMark); Globals.Session.DeleteUndoMark(undoMark, null); return(new Snap.NX.Bsurface(objectFromTag)); }
/// <summary> /// 创建草绘环境 /// </summary> /// <param name="mat">矩阵</param> /// <param name="name">名字</param> /// <returns></returns> public static Tag CreateShetch(double z) { Tag shetchTag = Tag.Null; string sketch = "SKETCH_001"; int option = 2; double[] matrix = { 1, 0, 0, 0, 1, 0, 0, 0, z }; Tag[] obj = new Tag[2]; int[] reference = new int[2]; int planeDir = 1; try { theUFSession.Sket.InitializeSketch(ref sketch, out shetchTag); theUFSession.Sket.CreateSketch(sketch, option, matrix, obj, reference, planeDir, out shetchTag); Session.UndoMarkId markId = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible); theSession.DeleteUndoMark(markId, ""); return(shetchTag); } catch (NXException ex) { LogMgr.WriteLog("SketchUtils:CreateShetch:" + ex.Message); throw ex; } }
public MachinedSurface() { try { InitializeComponent(); theSession = Session.GetSession(); NXOpenUI.FormUtilities.ReparentForm(this); NXOpenUI.FormUtilities.SetApplicationIcon(this); undomark = theSession.SetUndoMark(Session.MarkVisibility.Visible, "�ӹ����ע"); //��¼���ı�View������ Part workpart = theSession.Parts.Work; foreach (NXOpen.Drawings.DraftingView draftingview in workpart.DraftingViews) { NXOpen.Preferences.GeneralExtractedEdgesOption type = NXFun.GetViewEdgesPreference(draftingview); map.Add(draftingview, type); NXFun.SetViewEdgesPreference(draftingview, NXOpen.Preferences.GeneralExtractedEdgesOption.Associative); } label1.Text = "- ��ѡ��ӹ��� (0)"; //��ʼ���ѡ���Ķ��� this.timer1.Start(); } catch (System.Exception ex) { UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message); } }
public AttributeEdit() { InitializeComponent(); theSession = Session.GetSession(); NXOpenUI.FormUtilities.ReparentForm(this); NXOpenUI.FormUtilities.SetApplicationIcon(this); undomark = theSession.SetUndoMark(Session.MarkVisibility.Visible, "���Ա༭"); }
public AttributeEdit() { InitializeComponent(); theSession = Session.GetSession(); NXOpenUI.FormUtilities.ReparentForm(this); NXOpenUI.FormUtilities.SetApplicationIcon(this); undomark = theSession.SetUndoMark(Session.MarkVisibility.Visible, "属性编辑"); }
public void ReverseDirection() { Session.UndoMarkId undoMark = Globals.Session.SetUndoMark(Session.MarkVisibility.Invisible, ""); NXOpen.Features.DatumPlaneBuilder datumPlaneBuilder = this.DatumPlaneBuilder; datumPlaneBuilder.GetPlane().SetFlip(true); Snap.NX.Feature.CommitFeature(datumPlaneBuilder); datumPlaneBuilder.Destroy(); Globals.Session.UpdateManager.DoUpdate(undoMark); Globals.Session.DeleteUndoMark(undoMark, null); }
/// <summary> /// 创建草绘环境 /// </summary> /// <param name="mat">矩阵</param> /// <param name="name">名字</param> /// <returns></returns> public static Tag CreateShetch(double z, string name) { Tag shetchTag = Tag.Null; string sketch = "SKETCH_001"; int option = 2; double[] matrix = { 1, 0, 0, 0, 1, 0, 0, 0, z }; Tag[] obj = new Tag[2]; int[] reference = new int[2]; int planeDir = 1; theUFSession.Sket.InitializeSketch(ref name, out shetchTag); theUFSession.Sket.CreateSketch(sketch, option, matrix, obj, reference, planeDir, out shetchTag); Session.UndoMarkId markId = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible); theSession.DeleteUndoMark(markId, ""); return(shetchTag); }
/// <summary> /// 新建装配档文件 /// </summary> /// <param name="partName">装配Part名字</param> /// <param name="partPath">Part档地址</param> /// <returns></returns> public static NXObject CreateNew(string partName, string partPath) { Part workPart = theSession.Parts.Work; FileNew fileNew1 = theSession.Parts.FileNew(); fileNew1.TemplateFileName = "molex-plain-1-mm-template.prt"; fileNew1.UseBlankTemplate = false; fileNew1.ApplicationName = "ModelTemplate"; fileNew1.Units = NXOpen.Part.Units.Millimeters; fileNew1.RelationType = ""; fileNew1.UsesMasterModel = "No"; fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item; fileNew1.TemplatePresentationName = "Molex"; fileNew1.ItemType = ""; fileNew1.Specialization = ""; fileNew1.SetCanCreateAltrep(false); fileNew1.NewFileName = string.Concat(partPath); fileNew1.MasterFileName = ""; fileNew1.MakeDisplayedPart = false; NXOpen.Assemblies.CreateNewComponentBuilder createNewComponentBuilder1; createNewComponentBuilder1 = workPart.AssemblyManager.CreateNewComponentBuilder(); createNewComponentBuilder1.ReferenceSet = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentReferenceSetType.EntirePartOnly; createNewComponentBuilder1.NewComponentName = partName; createNewComponentBuilder1.ComponentOrigin = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentOriginType.Wcs; createNewComponentBuilder1.NewFile = fileNew1; bool validate = createNewComponentBuilder1.Validate(); try { NXObject nXObject1 = createNewComponentBuilder1.Commit(); return(nXObject1); } catch (Exception ex) { LogMgr.WriteLog("AssmbliesUtils:CreateNew:" + ex.Message); return(null); } finally { createNewComponentBuilder1.Destroy(); Session.UndoMarkId markId = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible); theSession.DeleteUndoMark(markId, ""); } }
/// <summary> ///偏置面 /// </summary> /// <param name="side"></param> /// <param name="isok"></param> /// <param name="faces"></param> /// <returns></returns> public static NXObject Offset(double side, out bool isok, params Face[] faces) { isok = true; Session theSession = Session.GetSession(); Part workPart = theSession.Parts.Work; Session.UndoMarkId mark = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Offset"); NXOpen.Features.AdmOffsetRegion nullNXOpen_Features_AdmOffsetRegion = null; NXOpen.Features.AdmOffsetRegionBuilder admOffsetRegionBuilder1; admOffsetRegionBuilder1 = workPart.Features.CreateAdmOffsetRegionBuilder(nullNXOpen_Features_AdmOffsetRegion); NXOpen.FaceDumbRule faceDumbRule; faceDumbRule = workPart.ScRuleFactory.CreateRuleFaceDumb(faces); NXOpen.SelectionIntentRule[] rules = new NXOpen.SelectionIntentRule[1]; rules[0] = faceDumbRule; admOffsetRegionBuilder1.FaceToOffset.FaceCollector.ReplaceRules(rules, false); admOffsetRegionBuilder1.Distance.Value = side; NXOpen.NXObject nXObject1 = null; try { nXObject1 = admOffsetRegionBuilder1.Commit(); return(nXObject1); } catch (NXException ex) { isok = false; LogMgr.WriteLog("OffsetRegion:Offset:" + ex.Message); return(null); } finally { admOffsetRegionBuilder1.Destroy(); if (!isok) { theSession.UndoToMark(mark, "Offset"); } theSession.DeleteUndoMark(mark, "Offset"); } }
/// <summary> /// 删除 /// </summary> /// <param name="nxObject"></param> /// <returns></returns> public static bool Delete(params NXObject[] nxObject) { Session.UndoMarkId mark = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Delete"); int dt = theSession.UpdateManager.AddToDeleteList(nxObject); try { int nErrs = theSession.UpdateManager.DoUpdate(mark); return(dt != 0); } catch (Exception ex) { LogMgr.WriteLog("DeleteObject.UpdateObject: 删除失败!" + ex.Message); return(false); } finally { theSession.DeleteUndoMark(mark, null); } }
//应用回调 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); } }
//------------------------------------------------------------------------------ // Callback Name: apply_cb // Following callback is associated with the "changeDialog" Styler item. // Input: eventObject - object of UIStyler.StylerEvent class //------------------------------------------------------------------------------ //Following is Apply Callback - This function is responsible for creating Edge Blend. public NXOpen.UIStyler.DialogState apply_cb(NXOpen.UIStyler.StylerEvent eventObject) { try { Part workPart = theSession.Parts.Work; Part displayPart = theSession.Parts.Display; // ---------------------------------------------- // Menu: Insert->Detail Feature->Edge Blend... // ---------------------------------------------- Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start"); NXOpen.Features.Feature nullFeatures_Feature = null; NXOpen.Features.EdgeBlendBuilder edgeBlendBuilder1 = workPart.Features.CreateEdgeBlendBuilder(nullFeatures_Feature); theSession.SetUndoMarkName(markId1, "Edge Blend"); Boolean featureAlerts1 = theSession.Preferences.Modeling.FeatureAlerts; ScCollector scCollector1 = workPart.ScCollectors.CreateCollector(); NXOpen.Features.Block block1 = (NXOpen.Features.Block)workPart.Features.FindObject("BLOCK(1)"); Boolean featureAlerts2 = theSession.Preferences.Modeling.FeatureAlerts; Boolean featureAlerts3 = theSession.Preferences.Modeling.FeatureAlerts; Edge[] seedEdges1 = new Edge[htEdges.Count]; IDictionaryEnumerator en = htEdges.GetEnumerator(); int EdgeIndex = 0; while (en.MoveNext()) { Edge edgeVar = (Edge)en.Value;; seedEdges1[EdgeIndex] = edgeVar; EdgeIndex += 1; } EdgeMultipleSeedTangentRule edgeMultipleSeedTangentRule2 = workPart.ScRuleFactory.CreateRuleEdgeMultipleSeedTangent(seedEdges1, 0.5, true); SelectionIntentRule[] rules2 = new SelectionIntentRule[1]; rules2[0] = edgeMultipleSeedTangentRule2; scCollector1.ReplaceRules(rules2, false); Boolean featureAlerts4 = theSession.Preferences.Modeling.FeatureAlerts; Boolean featureAlerts5 = theSession.Preferences.Modeling.FeatureAlerts; Session.UndoMarkId markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Edge Blend"); //Following can set the Tolerance for Edge Blend. edgeBlendBuilder1.Tolerance = changeReal6.ItemValue; edgeBlendBuilder1.AllInstancesOption = false; //Following can set the Remove Self Intersection option for the Edge Blend. edgeBlendBuilder1.RemoveSelfIntersection = changeToggle6.ItemValue; edgeBlendBuilder1.ConvexConcaveY = false; edgeBlendBuilder1.RollOverSmoothEdge = true; edgeBlendBuilder1.RollOntoEdge = true; edgeBlendBuilder1.MoveSharpEdge = true; edgeBlendBuilder1.OverlapOption = NXOpen.Features.EdgeBlendBuilder.Overlap.AnyConvexityRollOver; edgeBlendBuilder1.BlendOrder = NXOpen.Features.EdgeBlendBuilder.OrderOfBlending.ConvexFirst; edgeBlendBuilder1.SetbackOption = NXOpen.Features.EdgeBlendBuilder.Setback.SeparateFromCorner; //Following sets the value for Blend Radius. int csIndex1 = edgeBlendBuilder1.AddChainset(scCollector1, changeStr0.ItemValue); NXOpen.Features.Feature feature1 = edgeBlendBuilder1.CommitFeature(); theSession.DeleteUndoMark(markId2, null); edgeBlendBuilder1.Destroy(); htEdges.Clear(); changeLabel1.SetLabel("Select Edges (0)"); } catch (NXOpen.NXException ex) { // ---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("UI Styler", NXMessageBox.DialogType.Error, ex.Message); } // Callback acknowledged, do not terminate dialog // A return value of NXOpen.UIStyler.DialogState.ExitDialog will not be accepted // for this callback type. You must respond to your apply button. return(NXOpen.UIStyler.DialogState.ContinueDialog); }