/// <summary> /// 获取工件实体在装配下的体 /// </summary> /// <param name="ct"></param> /// <param name="pt"></param> /// <returns></returns> private List <Body> GetCompBodys(NXOpen.Assemblies.Component ct, Part pt) { List <Body> bodys = new List <Body>(); if ((ct.Prototype as Part).Equals(pt)) { foreach (Body by in pt.Bodies.ToArray()) { Body bo = AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, by.Tag) as Body; if (bo != null) { bodys.Add(bo); } } } else { foreach (NXOpen.Assemblies.Component co in AssmbliesUtils.GetPartComp(ct.Prototype as Part, pt)) { if (!co.IsSuppressed) { foreach (Body by in pt.Bodies.ToArray()) { Body bo = AssmbliesUtils.GetNXObjectOfOcc(co.Tag, by.Tag) as Body; if (bo != null) { bodys.Add(bo); } } } } } return(bodys); }
/// <summary> /// 创建外形点 /// </summary> /// <returns></returns> private Point[] CreateMinAndMaxPt() { UFSession theUFSession = UFSession.GetUFSession(); Point[] pt = new Point[2]; Point3d centerPt = new Point3d(); Point3d disPt = new Point3d(); List <Body> bodys = new List <Body>(); foreach (Body body in this.workpiece.Bodies.ToArray()) { bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(this.workpieceComp.Tag, body.Tag) as Body); } // Body[] bodys = this.workpiece.Bodies.ToArray(); Matrix4 invers = this.work.WorkMatr.GetInversMatrix(); CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(this.work.WorkMatr, invers);//坐标 BoundingBoxUtils.GetBoundingBoxInLocal(bodys.ToArray(), csys, this.work.WorkMatr, ref centerPt, ref disPt); this.CenterPt = centerPt; this.DisPt = disPt; Point3d minPt = new Point3d(centerPt.X - disPt.X, centerPt.Y - disPt.Y, centerPt.Z - disPt.Z); Point3d maxPt = new Point3d(centerPt.X + disPt.X, centerPt.Y + disPt.Y, centerPt.Z + disPt.Z); invers.ApplyPos(ref maxPt); invers.ApplyPos(ref minPt); // PartUtils.SetPartWork(workpieceComp); pt[0] = PointUtils.CreatePoint(minPt); theUFSession.Obj.SetLayer(pt[0].Tag, 254); pt[1] = PointUtils.CreatePoint(maxPt); theUFSession.Obj.SetLayer(pt[1].Tag, 254); // PartUtils.SetPartWork(null); return(pt); }
private void GetBoundingBox() { Point3d centerPt = new Point3d(); Point3d disPt = new Point3d(); Part workPart = Session.GetSession().Parts.Work; List <Body> bodys = new List <Body>(); // NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(workPart, part)[0]; foreach (NXOpen.Assemblies.Component ct in AssmbliesUtils.GetPartComp(workPart, part)) { if (!ct.IsSuppressed) { foreach (Body body in this.part.Bodies.ToArray()) { bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, body.Tag) as Body); } } } Matrix4 invers = workMatr.GetInversMatrix(); CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(workMatr, invers);//坐标 BoundingBoxUtils.GetBoundingBoxInLocal(bodys.ToArray(), csys, workMatr, ref centerPt, ref disPt); LayerUtils.MoveDisplayableObject(201, bodys.ToArray()); this.CenterPt = centerPt; this.DisPt = disPt; }
/// <summary> /// 转换点 /// </summary> /// <param name="pt"></param> /// <returns></returns> private Point3d GetSetWorkPoint3d(Point pt, Component eleCt) { Point compCt = AssmbliesUtils.GetNXObjectOfOcc(eleCt.Tag, pt.Tag) as Point; Point3d temp = compCt.Coordinates; work.Info.Matr.ApplyPos(ref temp); return(temp); }
/// <summary> /// 获取Work下原点 /// </summary> /// <returns></returns> public Point GetWorkCompPoint() { Part workPart = Session.GetSession().Parts.Work; UFSession theUFSession = UFSession.GetUFSession(); Component ct = AssmbliesUtils.GetPartComp(this.PartTag, work.PartTag)[0]; Point pt = work.CreateCenterPoint(); return(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, pt.Tag) as Point); }
//------------------------------------------------------------------------------ //Callback Name: update_cb //------------------------------------------------------------------------------ public int update_cb(NXOpen.BlockStyler.UIBlock block) { try { if (block == selectionBody) { //---------Enter your code here----------- if (points.Count > 0) { DeleteObject.Delete(points.ToArray()); } points.Clear(); Component ct = selectionBody.GetLastSelectedObjects()[0] as Component; foreach (Body by in (ct.Prototype as Part).Bodies) { if (by.IsBlanked) { nxObjects.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, by.Tag)); } } this.aoo = new NXObjectAooearancePoint(nxObjects.ToArray()); points = aoo.CreatePoint(); } else if (block == get_point) { //---------Enter your code here----------- Point3d temp = this.GetPoint(); if (this.selectionPt != null) { Basic.CsysUtils.SetWcsOfCentePoint(temp); } } else if (block == rotation_x) { //---------Enter your code here----------- CsysUtils.RotateWcs(WCS.Axis.XAxis, 90); } else if (block == rotation_y) { //---------Enter your code here----------- CsysUtils.RotateWcs(WCS.Axis.YAxis, 90); } else if (block == rotation_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); }
/// <summary> /// 获取装配下的体 /// </summary> /// <param name="ct"></param> /// <returns></returns> private Body GetOccsInBods(Component ct) { Part ctPart = ct.Prototype as Part; Body by = ctPart.Bodies.ToArray()[0]; try { return(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, by.Tag) as Body); } catch { return(null); } }
/// <summary> /// 获取边 /// </summary> /// <param name="xEdge"></param> /// <param name="yEdge"></param> public void GetEdge(out List <Edge> xEdge, out Point centerCom) { xEdge = new List <Edge>(); centerCom = null; string str = ""; ElectrodeModel ele = null; foreach (ElectrodeModel em in eleModels) { if (em.Info.AllInfo.SetValue.Positioning == "" || em.Info.AllInfo.SetValue.Positioning.Equals("A", StringComparison.CurrentCultureIgnoreCase)) { ele = em; } } if (ele == null) { return; } List <Face> faces = new List <Face>(); faces.AddRange(ele.PartTag.Bodies.ToArray()[0].GetFaces()); Point elePoint = ele.GetSetPoint(); faces.Sort(delegate(Face a, Face b) { FaceData data1 = FaceUtils.AskFaceData(a); FaceData data2 = FaceUtils.AskFaceData(b); return(data1.Point.Z.CompareTo((data2.Point.Z))); }); foreach (Component ct in AssmbliesUtils.GetPartComp(this.PartTag, ele.PartTag)) { ElectrodeSetValueInfo value = ElectrodeSetValueInfo.GetAttribute(ct); if (value.Positioning == "" || value.Positioning.Equals("A", StringComparison.CurrentCultureIgnoreCase)) { centerCom = AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, elePoint.Tag) as Point; foreach (Edge eg in faces[10].GetEdges()) { NXOpen.UF.UFEval.Line lineData; if (EdgeUtils.GetLineData(eg, out lineData, ref str)) { if (UMathUtils.IsEqual(lineData.start[1], lineData.end[1])) { xEdge.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, eg.Tag) as Edge); } } } } } }
private List <Body> GetBodys() { Part workPart = theSession.Parts.Work; List <Body> bodys = new List <Body>(); Part workpiece = GetWorkpiecePart(); NXOpen.Assemblies.Component workComp = AssmbliesUtils.GetPartComp(workPart, workpiece); workComp.Unblank(); bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(workComp.Tag, workpiece.Bodies.ToArray()[0].Tag) as Body); foreach (ElectrodeModel model in this.DraModel.Eles) { NXOpen.Assemblies.Component eleComp = AssmbliesUtils.GetPartComp(workPart, model.PartTag); bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(eleComp.Tag, model.PartTag.Bodies.ToArray()[0].Tag) as Body); } return(bodys); }
private BodyInfo GetDischargeFace(CartesianCoordinateSystem csys, Component ct) { List <string> err = new List <string>(); Part host = work.GetHostWorkpiece(); if (host == null) { return(null); } Body workBody = host.Bodies.ToArray()[0]; Body eleBody = elePart.Bodies.ToArray()[0]; Body comBody = AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, eleBody.Tag) as Body; ComputeDischargeFace cp = new ComputeDischargeFace(comBody, workBody, work.Info.Matr, csys); return(cp.GetBodyInfoForInterference(false, out err)); }
private List <Body> GetDrawingBody(Part draPart) { List <Body> bodys = new List <Body>(); Body by = eleModel.PartTag.Bodies.ToArray()[0]; foreach (NXOpen.Assemblies.Component ct in AssmbliesUtils.GetPartComp(draPart, eleModel.PartTag)) { try { bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, by.Tag) as Body); } catch { } } return(bodys); }
/// <summary> /// 修改设定值 /// </summary> /// <param name="asm"></param> /// <returns></returns> public bool AlterEleSetValue() { List <ElectrodeModel> eleModels = new List <ElectrodeModel>(); try { foreach (Part pt in Session.GetSession().Parts) { List <NXOpen.Assemblies.Component> ct = AssmbliesUtils.GetPartComp(this.PartTag, pt); if (ct.Count > 0 && ElectrodeModel.IsElectrode(pt)) { eleModels.Add(new ElectrodeModel(pt)); } } foreach (ElectrodeModel em in eleModels) { List <Component> eleCt = AssmbliesUtils.GetPartComp(this.PartTag, em.PartTag); Point pt = em.GetSetPoint(); foreach (Component ct in eleCt) { Point ptOcc = AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, pt.Tag) as Point; Point3d value = ptOcc.Coordinates; this.Info.Matr.ApplyPos(ref value); ElectrodeSetValueInfo setValue = ElectrodeSetValueInfo.GetAttribute(ct); ElectrodeSetValueInfo newSetValue = setValue.Clone() as ElectrodeSetValueInfo; newSetValue.EleSetValue = new double[] { value.X, value.Y, value.Z }; if (setValue.Positioning == "" || setValue.Positioning.Equals("A", StringComparison.CurrentCultureIgnoreCase)) { newSetValue.SetAttribute(em.PartTag); } else { NXObject obj = AssmbliesUtils.GetOccOfInstance(ct.Tag); newSetValue.SetAttribute(obj); } } } return(true); } catch (NXException ex) { ClassItem.WriteLogFile("修改电极设定值错误!" + ex.Message); return(false); } }
/// <summary> /// 获取电极X轴线 /// </summary> /// <returns></returns> public List <Line> GetYLine() { List <Line> le = new List <Line>(); foreach (ElectrodeModel em in eleModels) { Line bo = em.GetYLine(); foreach (Component eleCt in AssmbliesUtils.GetPartComp(this.PartTag, em.PartTag)) { Line temp = AssmbliesUtils.GetNXObjectOfOcc(eleCt.Tag, bo.Tag) as Line; if (temp != null) { le.Add(temp); } } } return(le); }
/// <summary> /// 获取电极设定点 /// </summary> /// <returns></returns> public List <Point> GetEleSetPoint() { List <Point> pt = new List <Point>(); foreach (ElectrodeModel em in eleModels) { Point bo = em.GetSetPoint(); foreach (Component eleCt in AssmbliesUtils.GetPartComp(this.PartTag, em.PartTag)) { Point temp = AssmbliesUtils.GetNXObjectOfOcc(eleCt.Tag, bo.Tag) as Point; if (temp != null) { pt.Add(temp); } } } return(pt); }
/// <summary> /// 获取工件体 /// </summary> /// <returns></returns> public List <Body> GetWorkpieceBody() { List <Body> bodys = new List <Body>(); Part workpiecePart = this.work.GetHostWorkpiece(); foreach (Body body in workpiecePart.Bodies.ToArray()) { foreach (Component workpieceCom in AssmbliesUtils.GetPartComp(this.PartTag, workpiecePart)) { Body by = AssmbliesUtils.GetNXObjectOfOcc(workpieceCom.Tag, body.Tag) as Body; if (by != null) { bodys.Add(by); } } } return(bodys); }
/// <summary> /// 获取电极体 /// </summary> /// <returns></returns> public List <Body> GetEleBody() { // Part workPart = Session.GetSession().Parts.Work; List <Body> by = new List <Body>(); foreach (ElectrodeModel em in eleModels) { Body bo = em.PartTag.Bodies.ToArray()[0]; foreach (Component eleCt in AssmbliesUtils.GetPartComp(this.PartTag, em.PartTag)) { Body temp = AssmbliesUtils.GetNXObjectOfOcc(eleCt.Tag, bo.Tag) as Body; if (temp != null) { by.Add(temp); } } } return(by); }
/// <summary> /// 获取Comp下设定点 /// </summary> /// <returns></returns> public List <Point> GetEleCompPint() { List <Point> eleCompPoints = new List <Point>(); foreach (ElectrodeModel ele in Eles) { Point elePt = null; foreach (Point pt in ele.PartTag.Points) { if (pt.Name.ToUpper().Equals("SetValuePoint".ToUpper())) { elePt = pt; } } if (elePt != null) { NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(this.PartTag, ele.PartTag); eleCompPoints.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, elePt.Tag) as Point); } } return(eleCompPoints); }
public void GetEdge(Face face, out List <Edge> xEdge, out List <Edge> yEdge) { xEdge = new List <Edge>(); yEdge = new List <Edge>(); string str = ""; NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(this.DraModel.PartTag, this.EleModel.PartTag); foreach (Edge eg in face.GetEdges()) { NXOpen.UF.UFEval.Line lineData; if (EdgeUtils.GetLineData(eg, out lineData, ref str)) { if (UMathUtils.IsEqual(lineData.start[1], lineData.end[1])) { xEdge.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, eg.Tag) as Edge); } if (UMathUtils.IsEqual(lineData.start[0], lineData.end[0])) { yEdge.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, eg.Tag) as Edge); } } } }
public void GetBoundingBox(out Point3d centerPt, out Point3d disPt) { // Part workPart = Session.GetSession().Parts.Work; centerPt = new Point3d(); disPt = new Point3d(); List <Body> bodys = new List <Body>(); Part workpiecePart = this.work.GetHostWorkpiece(); foreach (Body body in workpiecePart.Bodies.ToArray()) { foreach (NXOpen.Assemblies.Component ct in AssmbliesUtils.GetPartComp(this.PartTag, workpiecePart)) { Body by = AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, body.Tag) as Body; if (by != null) { bodys.Add(by); } } } foreach (ElectrodeModel em in eleModels) { Body by = em.PartTag.Bodies.ToArray()[0]; foreach (Component eleCt in AssmbliesUtils.GetPartComp(this.PartTag, em.PartTag)) { Body temp = AssmbliesUtils.GetNXObjectOfOcc(eleCt.Tag, by.Tag) as Body; if (temp != null) { bodys.Add(temp); } } } Matrix4 invers = this.work.Info.Matr.GetInversMatrix(); CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(this.work.Info.Matr, invers);//坐标 BoundingBoxUtils.GetBoundingBoxInLocal(bodys.ToArray(), csys, this.work.Info.Matr, ref centerPt, ref disPt); }