//------------------------------------------------------------------------------ //Callback Name: apply_cb //------------------------------------------------------------------------------ public int apply_cb() { int errorCode = 0; try { //---- Enter your callback code here ----- NXOpen.Assemblies.Component ct = this.seleComp.GetSelectedObjects()[0] as NXOpen.Assemblies.Component; Part pt = ct.Prototype as Part; string type = AttributeUtils.GetAttrForString(pt, "PartType"); if (type.Equals("Electrode", StringComparison.CurrentCultureIgnoreCase)) { ElectrodeModel model = new ElectrodeModel(); model.GetModelForPart(pt); ReplacePart.ReplaceElectrode(model, this.strEleName.Value.ToUpper()); } else { ReplacePart.Replace(pt, this.strEleName.Value.ToUpper()); } bool anyPartsModified; PartSaveStatus saveStatus; theSession.Parts.SaveAll(out anyPartsModified, out saveStatus); } catch (Exception ex) { //---- Enter your exception handling code here ----- errorCode = 1; theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return(errorCode); }
//------------------------------------------------------------------------------ //This method shows the dialog on the screen //------------------------------------------------------------------------------ public NXOpen.UIStyler.DialogResponse Show() { try { Part workPart = theSession.Parts.Work; string type = AttributeUtils.GetAttrForString(workPart, "PartType"); if (type != "ASM") { theUI.NXMessageBox.Show("错误", NXMessageBox.DialogType.Error, "请切换ASM档为工作部件!"); return(0); } MoldInfoModel mold = new MoldInfoModel(workPart); assemble = AssembleSingleton.Instance().GetAssemble(mold.MoldNumber + "-" + mold.WorkpieceNumber); theDialog.Show(); if (err.Count != 0) { bool anyPartsModified; PartSaveStatus saveStatus; Part part = null; if ((part = ReplacePart.Replace(assemble.Asm, moldInfo)) != null) { moldInfo.SetAttribute(part); theSession.Parts.SaveAll(out anyPartsModified, out saveStatus); err.Add("修改" + assemble.Asm.AssembleName + "成功!"); } foreach (string st in err) { ClassItem.Print(st); } } } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return(0); }