//------------------------------------------------------------------------------ //Callback Name: apply_cb //------------------------------------------------------------------------------ public int apply_cb() { int errorCode = 0; try { //---- Enter your callback code here ----- MoldInfo info = new MoldInfo() { MoldNumber = this.MoldNumber.WideValue.ToUpper(), WorkpieceNumber = this.PartNumber.WideValue.ToUpper(), EditionNumber = this.EditionNumber.WideValue.ToUpper(), ClientName = this.ClientNumber.WideValue, MoldType = this.MoldType.WideValue.ToUpper(), MachineType = this.MachineType.WideValue.ToUpper() }; string directoryPath = GetDirectoryPath(info); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); //创建件号文件夹 } CreateBulder(info, directoryPath); bool anyPartsModified1; NXOpen.PartSaveStatus partSaveStatus1; Session.GetSession().Parts.SaveAll(out anyPartsModified1, out partSaveStatus1); } catch (Exception ex) { //---- Enter your exception handling code here ----- errorCode = 1; theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return(errorCode); }
/// <summary> /// 设置电极 /// </summary> /// <param name="model"></param> /// <param name="sheet"></param> /// <param name="style"></param> private void SetEleMoldInfoToExcel(MoldInfo model, ISheet sheet, ICellStyle style) { ExcelUtils.SetValue(sheet, style, 3, 0, model.MoldNumber); ExcelUtils.SetValue(sheet, style, 2, 2, "电极名"); ExcelUtils.SetValue(sheet, style, 3, 2, this.info.GetEleName()); ExcelUtils.SetValue(sheet, style, 3, 5, "A"); }
private List <WorkpieceModel> CreateBulder(Part edmPart, List <string> openFiles, out List <string> err) { List <WorkpieceModel> workpiece = new List <WorkpieceModel>(); err = new List <string>(); EDMModel edm = new EDMModel(edmPart); MoldInfo moldInfo = edm.Info.MoldInfo.Clone() as MoldInfo; moldInfo.MoldNumber = this.strMoldNumber.Value.ToUpper(); moldInfo.EditionNumber = this.strEditionNumber.Value.ToUpper(); WorkPieceInfo info = new WorkPieceInfo(edm.Info.MoldInfo, user.CreatorUser); foreach (string st in openFiles) { MoldInfo temp = moldInfo.Clone() as MoldInfo; string name = Path.GetFileNameWithoutExtension(st); temp.WorkpieceNumber = name; WorkpieceModel model = new WorkpieceModel(new WorkPieceInfo(temp, user.CreatorUser)); if (model.CreatePart(edm.WorkpieceDirectoryPath, st)) { workpiece.Add(model); } else { err.Add(name + "没创建成功"); } } return(workpiece); }
private string GetEleNameForCMM(Part ele) { ElectrodeNameInfo nameInfo = ElectrodeNameInfo.GetAttribute(ele); MoldInfo moldInfo = MoldInfo.GetAttribute(ele); return(moldInfo.MoldNumber + "-" + moldInfo.WorkpieceNumber + "-E" + nameInfo.EleNumber.ToString()); }
/// <summary> /// 创建Work /// </summary> /// <param name="workpiece"></param> /// <param name="mat"></param> /// <param name="user"></param> /// <returns></returns> private List <string> CreateNewWork(NXOpen.Assemblies.Component ct, WorkpieceModel workpiece, Matrix4 mat, UserModel user) { List <string> err = new List <string>(); MoldInfo moldInfo = workpiece.Info.MoldInfo; int num = asmColl.GetWorkCollection(moldInfo).Work.Count; WorkInfo workInfo = new WorkInfo(workpiece.Info.MoldInfo, user, num + 1, mat); EDMModel edm = GetEdm(ct); if (edm == null) { err.Add("获取EDM错误"); return(err); } WorkCreateAssmbile create; if (edm.Info.MoldInfo.Equals(workInfo.MoldInfo)) { create = new WorkCreateAssmbile(workInfo, edm, asmModel); } else { EDMModel temp = new EDMModel(new EDMInfo(workInfo.MoldInfo, workInfo.UserModel)); create = new WorkCreateAssmbile(workInfo, temp, asmModel, workpiece); } err.AddRange(create.CreatePart(workpiece.WorkpieceDirectoryPath)); err.AddRange(create.LoadAssmbile()); if (err.Count == 0) { create.Work.SaveCsys(workPart); } return(err); }
/// <summary> /// 替换工件 /// </summary> /// <param name="ct"></param> private void AlterWorkpiece(NXOpen.Assemblies.Component ct, UserModel user) { MoldInfo mold; if (!ParentAssmblieInfo.IsParent(ct)) { mold = new MoldInfo() { MoldNumber = this.strMoldNumber.Value.ToUpper(), WorkpieceNumber = this.strWorkpieceNumber.Value.ToUpper(), EditionNumber = this.strEditionNumber.Value.ToUpper() }; } else { mold = MoldInfo.GetAttribute(ct); mold.MoldNumber = this.strMoldNumber.Value; mold.WorkpieceNumber = this.strWorkpieceNumber.Value; mold.EditionNumber = this.strEditionNumber.Value; } WorkPieceInfo wk = new WorkPieceInfo(mold, user); string newName = mold.MoldNumber + "-" + mold.WorkpieceNumber + "-" + mold.EditionNumber; Part pt = ct.Prototype as Part; ReplaceOther ot = new ReplaceOther(pt, wk); List <string> err = ot.Alter(newName); if (err.Count > 0) { ClassItem.Print(err.ToArray()); } }
//------------------------------------------------------------------------------ //Callback Name: apply_cb //------------------------------------------------------------------------------ public int apply_cb() { int errorCode = 0; try { //---- Enter your callback code here ----- NXOpen.Assemblies.Component ct = seleComp.GetSelectedObjects()[0] as NXOpen.Assemblies.Component; Part workPart = theSession.Parts.Work; if (ct != null) { List <string> err = new List <string>(); bool isBorrow; if (this.enum0.ValueAsString == "借用电极") { isBorrow = true; } else { isBorrow = false; } MoldInfo old = MoldInfo.GetAttribute(ct); MoldInfo mold = new MoldInfo() { MoldNumber = this.MoldNumber.WideValue.ToUpper(), WorkpieceNumber = this.PartNumber.WideValue.ToUpper(), ClientName = this.ClientNumber.WideValue.ToUpper(), EditionNumber = this.EditionNumber.WideValue.ToUpper(), MoldType = old.MoldType }; ParentAssmblieInfo info = new ParentAssmblieInfo(mold, user.CreatorUser); WorkCollection wkColl = asmColl.GetWorkCollection(old); err.AddRange(AlterWork(wkColl.Work, info)); err.AddRange(AlterEdm(wkColl.EdmModel, info)); err.AddRange(AlterElectrode(wkColl.Electrodes, info, isBorrow)); PartUtils.SetPartDisplay(workPart); ASMModel asm = new ASMModel(workPart); if (asm.Info.MoldInfo.Equals(old)) { err.AddRange(AlterAsm(asm, info)); } if (err.Count > 0) { ClassItem.Print(err.ToArray()); } } } catch (Exception ex) { //---- Enter your exception handling code here ----- errorCode = 1; theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return(errorCode); }
/// <summary> /// 修改版本 /// </summary> /// <param name="editionNumber"></param> private void UpdateEditionNumber(string editionNumber) { UFSession theUFSession = UFSession.GetUFSession(); Session theSession = Session.GetSession(); MoldInfo mf = asm.Info.MoldInfo; mf.EditionNumber = editionNumber; mf.SetAttribute(asm.PartTag); foreach (ElectrodeModel em in asmColl.GetElectrodes()) { MoldInfo mi = em.Info.MoldInfo; mi.EditionNumber = editionNumber; mi.SetAttribute(em.PartTag); string dwgName = em.Info.AllInfo.Name.EleName + "_dwg"; string dwg = em.WorkpieceDirectoryPath + em.Info.AllInfo.Name.EleName + "_dwg.prt"; if (File.Exists(dwg)) { Part dwgPart = null; try { dwgPart = theSession.Parts.FindObject(dwgName) as Part; if (dwgPart != null) { mi.SetAttribute(dwgPart); continue; } } catch { } Tag part; UFPart.LoadStatus error_status; theUFSession.Part.Open(dwg, out part, out error_status); mi.SetAttribute(NXObjectManager.Get(part) as Part); } } foreach (MoldInfo mi in asmColl.MoldInfo) { WorkCollection wkColl = asmColl.GetWorkCollection(mi); foreach (WorkModel wm in wkColl.Work) { MoldInfo wmMold = wm.Info.MoldInfo; wmMold.EditionNumber = editionNumber; wmMold.SetAttribute(wm.PartTag); } foreach (EDMModel em in wkColl.EdmModel) { MoldInfo wmMold = em.Info.MoldInfo; wmMold.EditionNumber = editionNumber; wmMold.SetAttribute(em.PartTag); } } PartUtils.SetPartDisplay(asm.PartTag); }
/// <summary> /// 获取文件夹 /// </summary> /// <param name="mold"></param> /// <returns></returns> private string GetDirectoryPath(MoldInfo mold) { string name = mold.MoldNumber + mold.WorkpieceNumber + mold.EditionNumber; if (workPart.Name.Replace("-", "").Equals(name, StringComparison.CurrentCultureIgnoreCase)) { return(Path.GetDirectoryName(workPart.FullPath) + "\\"); } else { return(Path.GetDirectoryName(workPart.FullPath) + "\\" + mold.WorkpieceNumber + "-" + mold.EditionNumber + "\\"); } }
//------------------------------------------------------------------------------ //Callback Name: update_cb //------------------------------------------------------------------------------ public int update_cb(NXOpen.BlockStyler.UIBlock block) { try { if (block == seleComp) { //---------Enter your code here----------- TaggedObject[] objs = seleComp.GetSelectedObjects(); if (objs.Length > 0) { NXOpen.Assemblies.Component ct = objs[0] as NXOpen.Assemblies.Component; if (ct != null) { if (ParentAssmblieInfo.IsParent(ct)) { MoldInfo mold = MoldInfo.GetAttribute(ct); this.ClientNumber.Value = mold.ClientName; } } } } else if (block == MoldNumber) { //---------Enter your code here----------- } else if (block == PartNumber) { //---------Enter your code here----------- } else if (block == EditionNumber) { //---------Enter your code here----------- } else if (block == ClientNumber) { //---------Enter your code here----------- } else if (block == enum0) { //---------Enter your code here----------- } } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return(0); }
/// <summary> /// 创建特征 /// </summary> /// <param name="mold"></param> private void CreateBulder(MoldInfo mold, string directoryPath) { UserSingleton user = UserSingleton.Instance(); if (user.UserSucceed && user.Jurisd.GetElectrodeJurisd()) { AbstractCreateAssmbile asm = new AsmCreateAssmbile(mold, user.CreatorUser, workPart); List <string> err = asm.CreatePart(directoryPath); err.AddRange(asm.LoadAssmbile()); if (err.Count != 0) { ClassItem.Print(err.ToArray()); } } }
/// <summary> /// 默认电极名 /// </summary> /// <returns></returns> private string GetDefEleName(MoldInfo mold) { WorkCollection wc = new WorkCollection(mold); if (wc.Electrodes.Count == 0) { return(mold.MoldNumber + "-" + mold.WorkpieceNumber + "E1"); } else { ElectrodeNameInfo nameInfo = (wc.Electrodes[wc.Electrodes.Count - 1].Info).AllInfo.Name; string name = nameInfo.EleName.Substring(0, nameInfo.EleName.LastIndexOf("E")); return(name + "E" + (nameInfo.EleNumber + 1).ToString()); } }
/// <summary> /// 获取电极的Work档 /// </summary> /// <param name="coms"></param> /// <returns></returns> private Part GetEleWorkPart(List <NXOpen.Assemblies.Component> coms) { foreach (NXOpen.Assemblies.Component ct in coms) { NXOpen.Assemblies.Component parentCt = ct.Parent; if (parentCt != null) { MoldInfo parentMold = MoldInfo.GetAttribute(parentCt.Prototype as Part); MoldInfo eleMold = MoldInfo.GetAttribute(elePart); if (eleMold.Equals(parentMold)) { return(parentCt.Prototype as Part); } } } return(null); }
private List <string> CreateNewWork1(NXOpen.Assemblies.Component ct, WorkpieceModel workpiece, Matrix4 mat, UserModel user) { List <string> err = new List <string>(); MoldInfo moldInfo = workpiece.Info.MoldInfo; int num = asmColl.GetWorkCollection(moldInfo).Work.Count; WorkInfo workInfo = new WorkInfo(workpiece.Info.MoldInfo, user, num + 1, mat); string workName = workInfo.MoldInfo.MoldNumber + "-" + workInfo.MoldInfo.WorkpieceNumber + "-" + "WORK" + workInfo.WorkNumber.ToString(); EDMModel edm = GetEdm(ct); if (edm == null) { err.Add("获取EDM错误"); return(err); } NXOpen.Assemblies.Component comp = AssmbliesUtils.MoveCompCopyPart(ct.Parent.Parent, new Vector3d(0, 0, 0), mat); AssmbliesUtils.MakeUnique(comp, edm.WorkpieceDirectoryPath + workName + ".prt"); workInfo.SetAttribute(comp.Prototype as Part); WorkModel wm = new WorkModel(comp.Prototype as Part); if (wm != null) { wm.SaveCsys(workPart); } if (!edm.Info.MoldInfo.Equals(workInfo.MoldInfo)) { EDMInfo edmInfo = new EDMInfo(workInfo.MoldInfo, workInfo.UserModel); string edmName = edmInfo.MoldInfo.MoldNumber + "-" + edmInfo.MoldInfo.WorkpieceNumber + "-" + "EDM"; foreach (NXOpen.Assemblies.Component cp in comp.GetChildren()) { if (ParentAssmblieInfo.IsEDM(cp)) { AssmbliesUtils.MakeUnique(cp, edm.WorkpieceDirectoryPath + edmName + ".prt"); edmInfo.SetAttribute(cp.Prototype as Part); foreach (NXOpen.Assemblies.Component co in cp.GetChildren()) { if (!(co.Prototype as Part).Equals(workpiece.PartTag)) { AssmbliesUtils.DeleteComponent(co); } } } } } return(err); }
/// <summary> /// 获取模具号 /// </summary> /// <returns></returns> public MoldInfo GetMoldInfo() { if (ParentAssmblieInfo.IsParent(this.pt)) { return(MoldInfo.GetAttribute(this.pt)); } else { return(new MoldInfo() { ClientName = "", EditionNumber = "", MachineType = "", MoldNumber = "", MoldType = "", WorkpieceNumber = "" }); } }
public AsmCreateAssmbile(MoldInfo mold, UserModel user, Part workpiecePart) : base(mold, user) { Matrix4 mat = new Matrix4(); mat.Identity(); AbstractAssmbileModel asm = new ASMModel(new ASMInfo(base.moldInfo, base.userModel)); AbstractAssmbileModel work = new WorkModel(new WorkInfo(base.moldInfo, base.userModel, 1, mat)); AbstractAssmbileModel edm = new EDMModel(new EDMInfo(base.moldInfo, base.userModel)); AbstractAssmbileModel workpiece = new WorkpieceModel(new WorkPieceInfo(base.moldInfo, base.userModel), workpiecePart); work.SetParentModel(asm); edm.SetParentModel(work); workpiece.SetParentModel(edm); this.asmModel = asm; models.Add(asm); models.Add(work); models.Add(edm); models.Add(workpiece); }
public void CreateExcel() { string dllPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; string excelTemplatePath = dllPath.Replace("application\\", "Cofigure\\ShopDoc_Template-test.xlsx"); string path = part.FullPath; path = System.IO.Path.GetDirectoryName(path) + "\\" + part.Name + ".xlsx"; IWorkbook workbook = ExcelUtils.CreateExeclFile(excelTemplatePath); if (workbook == null) { return; } IFont font = workbook.CreateFont(); font.FontName = "微软雅黑"; font.FontHeightInPoints = 8; ICellStyle style = ExcelUtils.SetCellStyle(workbook, font); ICellStyle styleDate = ExcelUtils.SetCellStyle(workbook, font); styleDate.DataFormat = 21; ISheet sheet = workbook.GetSheetAt(0); MoldInfo mold = this.info.GetMoldInfo(); if (this.info.IsWorkpiece()) { SetMoldInfoToExcel(mold, sheet, style); } else { SetEleMoldInfoToExcel(mold, sheet, style); } SetUser(sheet, style); SetRowData(sheet, style, styleDate); FileStream fs = File.Create(path); workbook.Write(fs); fs.Close(); workbook.Close(); }
private List <string> CopWork(NXOpen.Assemblies.Component ct, WorkModel work, UserModel user) { List <string> err = new List <string>(); Matrix4 mat = new Matrix4(); mat.Identity(); MoldInfo mold = work.Info.MoldInfo.Clone() as MoldInfo; WorkCollection workColl = new WorkCollection(mold); NXOpen.Assemblies.Component moveCt = null; try { moveCt = AssmbliesUtils.MoveCompCopyPart(ct, new Vector3d(), mat); } catch (NXException ex) { err.Add("无法移动工件!" + ex.Message); return(err); } string name = work.WorkpieceDirectoryPath + mold.MoldNumber + "-" + mold.WorkpieceNumber + "-"; if (moveCt != null) { WorkInfo wk = new WorkInfo(mold, user, work.Info.WorkNumber, work.Info.Matr); try { NXObject make1 = AssmbliesUtils.MakeUnique(moveCt, name + "WORK" + (workColl.Work[workColl.Work.Count - 1].Info.WorkNumber + 1).ToString() + ".prt"); wk.WorkNumber = (workColl.Work[workColl.Work.Count - 1].Info.WorkNumber + 1); wk.SetAttribute(moveCt.Prototype as Part); } catch (NXException ex) { err.Add(name + "WORK" + (workColl.Work[workColl.Work.Count - 1].Info.WorkNumber + 1).ToString() + ".prt" + ex.Message + "无法创建唯一"); } } return(err); }
public WorkCollection(MoldInfo moldInfo) { this.info = moldInfo; coll = new AssmbileCollection(); }
/// <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); }
public AbstractCreateAssmbile(MoldInfo mold, UserModel user) { this.moldInfo = mold; this.userModel = user; }
/// <summary> /// 设置模具 /// </summary> /// <param name="model"></param> /// <param name="sheet"></param> /// <param name="style"></param> private void SetMoldInfoToExcel(MoldInfo model, ISheet sheet, ICellStyle style) { ExcelUtils.SetValue(sheet, style, 3, 0, model.MoldNumber); ExcelUtils.SetValue(sheet, style, 3, 2, model.WorkpieceNumber); ExcelUtils.SetValue(sheet, style, 3, 5, model.EditionNumber); }
/// <summary> /// 获取WorkCollection /// </summary> /// <param name="mold"></param> /// <returns></returns> public WorkCollection GetWorkCollection(MoldInfo mold) { return(new WorkCollection(mold)); }