//------------------------------------------------------------------------------ //Callback Name: apply_cb //------------------------------------------------------------------------------ public int apply_cb() { int errorCode = 0; try { //---- Enter your callback code here ----- CoordinateSystem wcs = theSession.Parts.Work.WCS.CoordinateSystem; Matrix4 mat = new Matrix4(); mat.Identity(); mat.TransformToCsys(wcs, ref mat); Component ct = selectionBody.GetSelectedObjects()[0] as Component; Part parent = ct.Parent.Prototype as Part; if (!parent.Equals(workPart)) { PartUtils.SetPartWork(ct.Parent); } AssmbliesUtils.MoveCompPartForCsys(mat, ct); PartUtils.SetPartWork(null); if (points.Count > 0) { DeleteObject.Delete(points.ToArray()); } CsysUtils.SetWcsToAbs(); } 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="asm"></param> /// <returns></returns> public bool SaveCsys(Part asm) { UFSession theUFSession = UFSession.GetUFSession(); try { PartUtils.SetPartDisplay(asm); List <NXOpen.Assemblies.Component> ct = AssmbliesUtils.GetPartComp(asm, this.PartTag); CsysUtils.SetWcsOfCenteAndMatr(this.Info.Matr.GetCenter(), this.Info.Matr.GetMatrix3()); PartUtils.SetPartWork(ct[0]); CartesianCoordinateSystem csys = asm.WCS.Save(); string name = "WORK" + this.Info.WorkNumber.ToString(); Tag objTag = Tag.Null; theUFSession.Obj.CycleByName(name, ref objTag); if (objTag != Tag.Null) { theUFSession.Obj.DeleteObject(objTag); } csys.Name = name; csys.Layer = 200; csys.Color = 186; PartUtils.SetPartWork(null); CsysUtils.SetWcsToAbs(); return(true); } catch (NXException ex) { ClassItem.WriteLogFile("创建坐标错误" + ex.Message); return(false); } }
//------------------------------------------------------------------------------ //This method shows the dialog on the screen //------------------------------------------------------------------------------ public NXOpen.UIStyler.DialogResponse Show() { try { UserSingleton user = UserSingleton.Instance(); if (user.UserSucceed && user.Jurisd.GetComm()) { CsysUtils.SetWcsToAbs(); Component ct = workPart.ComponentAssembly.RootComponent; if (ct == null) { theUI.NXMessageBox.Show("错误", NXMessageBox.DialogType.Error, "显示部件不是装配档!"); return(0); } theDialog.Show(); } } 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="filePath"></param> /// <returns></returns> public NXOpen.Assemblies.Component CreateCompPart() { CsysUtils.SetWcsOfCenteAndMatr(this.CenterPt, this.EleMatr.GetMatrix3()); NXObject obj = AssmbliesUtils.CreateNew(this.AssembleName, WorkpiecePath); NXOpen.Assemblies.Component comp = obj as NXOpen.Assemblies.Component; this.PartTag = obj.Prototype as Part; SetAttribute(); CsysUtils.SetWcsToAbs(); return(comp); }
//------------------------------------------------------------------------------ //This method shows the dialog on the screen //------------------------------------------------------------------------------ public NXOpen.UIStyler.DialogResponse Show() { try { CsysUtils.SetWcsToAbs(); theDialog.Show(); } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return(0); }
public static void CreateBuilder(MoldInfoModel moldInfo) { Part workPart = Session.GetSession().Parts.Work; NXOpen.Assemblies.Component ct = workPart.ComponentAssembly.RootComponent; if (ct != null) { UI.GetUI().NXMessageBox.Show("错误!", NXMessageBox.DialogType.Error, "工件是装配关系"); return; } CsysUtils.SetWcsToAbs(); Matrix4 mat = new Matrix4(); mat.Identity(); string name = moldInfo.MoldNumber + "-" + moldInfo.WorkpieceNumber + moldInfo.EditionNumber; string partfull = workPart.FullPath; string path; if (workPart.Name.Equals(name)) { path = Path.GetDirectoryName(partfull) + "\\"; } else { path = Path.GetDirectoryName(partfull) + "\\" + moldInfo.WorkpieceNumber + "-" + moldInfo.EditionNumber + "\\"; } CreateAsmPart asm = new CreateAsmPart(path, moldInfo); CreateEdmPart edm = new CreateEdmPart(path, moldInfo); CreateWorkPart work = new CreateWorkPart(path, moldInfo, 1, mat); CreateWorkpiecePart workpiece = new CreateWorkpiecePart(path, workPart, moldInfo); workpiece.CreatePart(); asm.CreatePart(); edm.CreatePart(); work.CreatePart(); workpiece.Load(edm.Model.PartTag); edm.Load(work.Model.PartTag); work.Load(asm.Model.PartTag); work.Model.WaveBodys(); PartUtils.SetPartDisplay(asm.Model.PartTag); bool anyPartsModified1; NXOpen.PartSaveStatus partSaveStatus1; Session.GetSession().Parts.SaveAll(out anyPartsModified1, out partSaveStatus1); }
//------------------------------------------------------------------------------ //Callback Name: apply_cb //------------------------------------------------------------------------------ public int apply_cb() { int errorCode = 0; try { //---- Enter your callback code here ----- Part workPart = theSession.Parts.Work; CoordinateSystem wcs = workPart.WCS.CoordinateSystem; Matrix4 matr = new Matrix4(); matr.Identity(); matr.TransformToCsys(wcs, ref matr); string number = this.workNumber.ValueAsString.Substring(4); if (addOrModify.Value) { AddWorkBuilder.CreateWork(matr, Convert.ToInt32(number), asmPart); } else { AddWorkBuilder.AlterMatr(matr, Convert.ToInt32(number), asmPart); } CartesianCoordinateSystem csys = workPart.WCS.Save(); csys.Name = this.workNumber.ValueAsString; csys.Layer = 200; csys.Color = 186; PartUtils.SetPartDisplay(asmPart); CsysUtils.SetWcsToAbs(); DeleteObject.Delete(this.points.ToArray()); 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); }
//------------------------------------------------------------------------------ //This method shows the dialog on the screen //------------------------------------------------------------------------------ public NXOpen.UIStyler.DialogResponse Show() { try { UserSingleton user = UserSingleton.Instance(); if (user.UserSucceed && user.Jurisd.GetComm()) { CsysUtils.SetWcsToAbs(); theDialog.Show(); } } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return(0); }
//------------------------------------------------------------------------------ //Callback Name: apply_cb //------------------------------------------------------------------------------ public int apply_cb() { int errorCode = 0; try { //---- Enter your callback code here ----- CoordinateSystem wcs = theSession.Parts.Work.WCS.CoordinateSystem; Basic.MoveObject.MoveObjectOfCsys(wcs, nxObjects.ToArray()); DeleteObject.Delete(points.ToArray()); CsysUtils.SetWcsToAbs(); } 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="filePath"></param> /// <returns></returns> public NXOpen.Assemblies.Component CreateCompPart(string directoryPath) { this.WorkpieceDirectoryPath = directoryPath; this.WorkpiecePath = directoryPath + this.AssembleName + ".prt"; CsysUtils.SetWcsToAbs(); CsysUtils.SetWcsOfCenteAndMatr(this.Info.Matr.GetCenter(), this.Info.Matr.GetMatrix3()); try { NXObject obj = AssmbliesUtils.CreateNew(this.AssembleName, WorkpiecePath); NXOpen.Assemblies.Component comp = obj as NXOpen.Assemblies.Component; this.PartTag = obj.Prototype as Part; if (this.PartTag != null) { SetAttribute(this.PartTag); } CsysUtils.SetWcsToAbs(); return(comp); } catch (NXException ex) { ClassItem.WriteLogFile("创建装配档错误!" + ex.Message); throw ex; } }
//------------------------------------------------------------------------------ //Callback Name: update_cb //------------------------------------------------------------------------------ public int update_cb(NXOpen.BlockStyler.UIBlock block) { try { if (block == selePart) { //---------Enter your code here----------- TaggedObject[] obj = this.selePart.GetLastSelectedObjects(); if (obj.Length > 0) { this.seleCt = obj[0] as NXOpen.Assemblies.Component; Part temp = (this.seleCt).Prototype as Part; if (ParentAssmblieInfo.IsWork(temp)) { WorkModel wk = new WorkModel(temp); this.group.Show = true; this.workNumber.SetEnumMembers(GetWorkpieceName(wk).ToArray()); selectPart = GetWorkPieceForWork(wk); } else { selectPart = temp; this.group.Show = false; this.group1.Show = true; this.group2.Show = true; } List <Body> bodys = GetCompBodys(this.seleCt, selectPart); if (bodys.Count > 0) { aoo = new NXObjectAooearancePoint(bodys.ToArray()); this.points = aoo.CreatePoint(); } this.selePoint.Enable = true; } else { this.selePoint.Enable = false; selectPart = null; this.seleCt = null; DeleteObject.Delete(this.points.ToArray()); this.points.Clear(); this.selectPt = null; this.selectFace = null; CsysUtils.SetWcsToAbs(); } } else if (block == addOrModify) { //---------Enter your code here----------- if (this.addOrModify.Value) { this.workNumber.Show = true; if (this.points.Count > 0) { DeleteObject.Delete(this.points.ToArray()); this.points.Clear(); } this.group2.Show = false; this.group1.Show = false; } else { if (selectPart != null) { List <Body> bodys = GetCompBodys(this.seleCt, this.selectPart); if (bodys.Count > 0) { aoo = new NXObjectAooearancePoint(bodys.ToArray()); this.points = aoo.CreatePoint(); } } // this.workNumber.Show = false; this.group1.Show = true; this.group2.Show = true; } } else if (block == workNumber) { //---------Enter your code here----------- } else if (block == selePoint) { //---------Enter your code here----------- if (selePoint.GetSelectedObjects().Length != 0) { TaggedObject obj = selePoint.GetSelectedObjects()[0]; //---------Enter your code here----------- if (obj is Point) { this.selectPt = obj as Point; } if (obj is Face) { Face temp = obj as Face; if (this.selectFace != null) { this.selectFace.Unhighlight(); if (this.selectFace.Equals(temp)) { this.selectFace = null; } else { this.selectFace = temp; } } else { this.selectFace = temp; } if (this.selectFace != null) { this.selectFace.Highlight(); } } if (selectPt != null) { Point3d temp; if (selectFace != null) { temp = NXObjectAooearancePoint.GetPointToFaceDis(selectPt, selectFace); } else { temp = selectPt.Coordinates; } CsysUtils.SetWcsOfCentePoint(temp); } } } else if (block == button_X) { //---------Enter your code here----------- CsysUtils.RotateWcs(WCS.Axis.XAxis, 90); } else if (block == button_Y) { //---------Enter your code here----------- CsysUtils.RotateWcs(WCS.Axis.YAxis, 90); } else if (block == button_Z) { //---------Enter your code here----------- CsysUtils.RotateWcs(WCS.Axis.ZAxis, 90); } } catch (Exception ex) { //---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString()); } return(0); }
//------------------------------------------------------------------------------ //Callback Name: apply_cb //------------------------------------------------------------------------------ public int apply_cb() { int errorCode = 0; try { //---- Enter your callback code here ----- if (this.selectPart != null) { CoordinateSystem wcs = workPart.WCS.CoordinateSystem; Matrix4 matr = new Matrix4(); matr.Identity(); Part temp = this.seleCt.Prototype as Part; List <string> err = new List <string>(); if (WorkModel.IsWork(temp)) { WorkModel wm = new WorkModel(temp); if (!this.addOrModify.Value) { matr.TransformToCsys(wcs, ref matr); if (!this.AlterWork(wm, matr)) { theUI.NXMessageBox.Show("错误", NXMessageBox.DialogType.Error, "修改设定坐标错误!"); } } else { AddWorkBuilder add = new AddWorkBuilder(asmModel, this.seleCt); string workpieceName = this.GetWorkpieceNumber(this.workNumber.ValueAsString, wm); if (wm.Info.MoldInfo.WorkpieceNumber.Equals(workpieceName, StringComparison.CurrentCultureIgnoreCase)) { err.AddRange(add.CopWork(user.CreatorUser)); } else { err.AddRange(add.CopOtherWork(user.CreatorUser, this.workNumber.ValueAsString)); } } } else { if (!this.addOrModify.Value) { matr.TransformToCsys(wcs, ref matr); } else { matr = GetParentWorkMatr(seleCt); } AddWorkBuilder add = new AddWorkBuilder(asmModel, this.seleCt.Parent.Parent); err.AddRange(add.CreateWork(user.CreatorUser, this.seleCt, matr)); } if (err.Count > 0) { ClassItem.Print(err.ToArray()); } if (points.Count != 0) { DeleteObject.Delete(this.points.ToArray()); } CsysUtils.SetWcsToAbs(); 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); }