/// <summary> /// 替换电极图纸 /// </summary> /// <param name="oldParenInfo"></param> /// <param name="newParenInfo"></param> /// <returns></returns> public List <string> AlterEleDra(ParentAssmblieInfo oldParenInfo, ParentAssmblieInfo newParenInfo) { List <string> err = new List <string>(); UFSession theUFSession = UFSession.GetUFSession(); Part workPart = Session.GetSession().Parts.Work; string oldDra = directoryPath + oldNameInfo.EleName + "_dwg.prt"; if (!File.Exists(oldDra)) { return(err); } string newDra = directoryPath + newNameInfo.EleName + "_dwg.prt"; if (File.Exists(newDra)) { err.Add(newNameInfo.EleName + " 替换失败,替换后有同名工件! "); return(err); } else { foreach (Part pt in Session.GetSession().Parts) { if (pt.Name.Equals(oldNameInfo.EleName + "_dwg", StringComparison.CurrentCultureIgnoreCase)) { pt.Close(NXOpen.BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, null); } } File.Move(oldDra, newDra); Tag partTag; UFPart.LoadStatus error_status; theUFSession.Part.Open(newDra, out partTag, out error_status); Part newPart = NXObjectManager.Get(partTag) as Part; PartUtils.SetPartDisplay(newPart); NXOpen.Assemblies.Component comp = newPart.ComponentAssembly.RootComponent.GetChildren()[0]; string workName = comp.Name.Replace(oldParenInfo.MoldInfo.MoldNumber + "-" + oldParenInfo.MoldInfo.WorkpieceNumber, newParenInfo.MoldInfo.MoldNumber + "-" + newParenInfo.MoldInfo.WorkpieceNumber); try { Basic.AssmbliesUtils.ReplaceComp(comp, this.directoryPath + workName + ".prt", workName); } catch { } if (newPart != null) { newNameInfo.SetAttribute(newPart); ParentAssmblieInfo info = ParentAssmblieInfo.GetAttribute(newPart); info.MoldInfo = newParenInfo.MoldInfo; info.UserModel = newParenInfo.UserModel; info.SetAttribute(newPart); foreach (DrawingSheet st in newPart.DrawingSheets) { Basic.DrawingUtils.UpdateViews(st); } } PartUtils.SetPartDisplay(workPart); err.Add(newNameInfo.EleName + " 图纸替换成功! "); return(err); } }
//------------------------------------------------------------------------------ //Callback Name: filter_cb //------------------------------------------------------------------------------ public int filter_cb(NXOpen.BlockStyler.UIBlock block, NXOpen.TaggedObject selectedObject) { TaggedObject[] obj = this.selePart.GetSelectedObjects(); if (selectedObject is NXOpen.Assemblies.Component) { Part part = (selectedObject as NXOpen.Assemblies.Component).Prototype as Part; ParentAssmblieInfo info = ParentAssmblieInfo.GetAttribute(part); if (info.Type == PartType.Workpiece || info.Type == PartType.Work) { return(NXOpen.UF.UFConstants.UF_UI_SEL_ACCEPT); } } if (obj.Length > 0) { // Part part = (obj[0] as NXOpen.Assemblies.Component).Prototype as Part; if (selectedObject is Face) { Face seleFace = selectedObject as Face; Part selePart = (seleFace.Prototype as Face).OwningPart as Part; if (selePart.Tag == this.selectPart.Tag) { return(UFConstants.UF_UI_SEL_ACCEPT); } } else if (selectedObject is Point) { return(UFConstants.UF_UI_SEL_ACCEPT); } } return(NXOpen.UF.UFConstants.UF_UI_SEL_REJECT); }
public int filter_cb(NXOpen.BlockStyler.UIBlock block, NXOpen.TaggedObject selectedObject) { if (selectedObject is NXOpen.Assemblies.Component) { Part part = (selectedObject as NXOpen.Assemblies.Component).Prototype as Part; ParentAssmblieInfo info = ParentAssmblieInfo.GetAttribute(part); if (info.Type == PartType.Electrode) { return(NXOpen.UF.UFConstants.UF_UI_SEL_ACCEPT); } } return(NXOpen.UF.UFConstants.UF_UI_SEL_REJECT); }
private void GetAllModel() { foreach (Part pt in Session.GetSession().Parts) { string name = pt.Name; if (ParentAssmblieInfo.IsParent(pt)) { ParentAssmblieInfo parent = ParentAssmblieInfo.GetAttribute(pt); switch (parent.Type) { case PartType.ASM: Asm.Add(new ASMModel(pt)); break; case PartType.EDM: Edm.Add(new EDMModel(pt)); break; case PartType.Electrode: ElectrodeModel eleModel = new ElectrodeModel(pt); Electrode.Add(eleModel); break; case PartType.Work: Work.Add(new WorkModel(pt)); break; default: Other.Add(pt); break; } } else { Other.Add(pt); } } }
public List <string> AlterEle(ParentAssmblieInfo parenInfo) { Part newElePart; string newEleName = elePt.Name.Replace(oldNameInfo.EleName, newNameInfo.EleName); string newPath = directoryPath + newEleName + ".prt"; List <string> err = new List <string>(); if (File.Exists(newPath)) { err.Add(newEleName + " 替换失败,替换后有同名工件! "); return(err); } ParentAssmblieInfo info = ParentAssmblieInfo.GetAttribute(elePt); err.AddRange(ReplacePart.Replace(elePt, newPath, newEleName, out newElePart)); if (newElePart != null) { info.MoldInfo = parenInfo.MoldInfo; info.UserModel = parenInfo.UserModel; newNameInfo.SetAttribute(newElePart); info.SetAttribute(newElePart); } return(err); }
/// <summary> /// 复制work /// </summary> /// <param name="ct"></param> /// <param name="work"></param> /// <param name="workpieceNumber"></param> /// <param name="user"></param> /// <returns></returns> private List <string> CopyWork(NXOpen.Assemblies.Component ct, WorkModel work, string workpieceNumber, UserModel user) { List <string> err = new List <string>(); Matrix4 mat = new Matrix4(); mat.Identity(); MoldInfo mold = work.Info.MoldInfo.Clone() as MoldInfo; NXOpen.Assemblies.Component moveCt = null; try { moveCt = AssmbliesUtils.MoveCompCopyPart(ct, new Vector3d(), mat); } catch (NXException ex) { err.Add("无法移动工件!" + ex.Message); return(err); } mold.WorkpieceNumber = workpieceNumber; string name = work.WorkpieceDirectoryPath + mold.MoldNumber + "-" + mold.WorkpieceNumber + "-"; if (moveCt != null) { foreach (NXOpen.Assemblies.Component com in moveCt.GetChildren()) { if (ParentAssmblieInfo.IsParent(com)) { ParentAssmblieInfo info1 = ParentAssmblieInfo.GetAttribute(com); if (info1.Type == PartType.EDM) { string edmName = name + "EDM"; if (File.Exists(edmName + ".prt")) { edmName = edmName + "5"; } EDMInfo edm = new EDMInfo(mold, user); try { NXObject make = AssmbliesUtils.MakeUnique(com, edmName + ".prt"); edm.SetAttribute(com.Prototype as Part); break; } catch (NXException ex) { err.Add(name + "EDM.prt" + ex.Message + "无法创建唯一"); } } } } try { NXObject make1 = AssmbliesUtils.MakeUnique(moveCt, name + "WORK" + work.Info.WorkNumber.ToString() + ".prt"); WorkInfo wk = new WorkInfo(mold, user, work.Info.WorkNumber, work.Info.Matr); wk.SetAttribute(moveCt.Prototype as Part); } catch (NXException ex) { err.Add(name + "WORK" + work.Info.WorkNumber.ToString() + ".prt" + ex.Message + "无法创建唯一"); } } return(err); }