NX9+VS2012 using System; using NXOpen; using NXOpen.UF; using NXOpenUI; using NXOpen.Utilities; //获取WCS Tag WcsId = Tag.Null; theUfSession.Csys.AskWcs(out WcsId); //获取WCS的矩阵和原点 Tag MatrixId = Tag.Null; double[] CsysOrigin = new Double[3]; theUfSession.Csys.AskCsysInfo(WcsId, out MatrixId, CsysOrigin); //画两个整圆 UFCurve.Arc HoleArcCoords1 = new UFCurve.Arc(); HoleArcCoords1.matrix_tag = MatrixId; HoleArcCoords1.start_angle = 0 * UFConstants.DEGRA; HoleArcCoords1.end_angle = 360 * UFConstants.DEGRA; HoleArcCoords1.arc_center = new Double[3]; HoleArcCoords1.arc_center[0] = 0.0; HoleArcCoords1.arc_center[1] = 0.0; HoleArcCoords1.arc_center[2] = 0.0; HoleArcCoords1.radius = 100; Tag HoleArcTag1 = Tag.Null; theUfSession.Curve.CreateArc(ref HoleArcCoords1, out HoleArcTag1); UFCurve.Arc HoleArcCoords2 = new UFCurve.Arc(); HoleArcCoords2.matrix_tag = MatrixId; HoleArcCoords2.start_angle = 0 * UFConstants.DEGRA; HoleArcCoords2.end_angle = 360 * UFConstants.DEGRA; HoleArcCoords2.arc_center = new Double[3]; HoleArcCoords2.arc_center[0] = 0.0; HoleArcCoords2.arc_center[1] = 0.0; HoleArcCoords2.arc_center[2] = 0.0; HoleArcCoords2.radius = 120; Tag HoleArcTag2 = Tag.Null; theUfSession.Curve.CreateArc(ref HoleArcCoords2, out HoleArcTag2); //创建链表 Tag[] ArcList = new Tag[2]; theUfSession.Modl.CreateList(out ArcList); //插入对象到链表 theUfSession.Modl.PutListItem(ref ArcList, HoleArcTag1); theUfSession.Modl.PutListItem(ref ArcList, HoleArcTag2); //创建拉伸 string[] HoleLimit = { "0.0", "50.0" }; double[] HolePoint = { 0.0, 0.0, 0.0 }; double[] HoleDirection = { 0.0, 0.0, 1.0 }; Tag[] HoleExtrudedTag = new Tag[1]; theUfSession.Modl.CreateExtruded(ArcList, "0", HoleLimit, HolePoint, HoleDirection, FeatureSigns.Nullsign, out HoleExtrudedTag); //特征找体 Tag HoleBodyTag = Tag.Null; theUfSession.Modl.AskFeatBody(HoleExtrudedTag[0], out HoleBodyTag); //创建颜色 theUfSession.Obj.SetColor(HoleBodyTag, 186); //设置透明度 theUfSession.Obj.SetTranslucency(HoleBodyTag, 60); //画一个整圆 UFCurve.Arc ToolMoveArcCoords1 = new UFCurve.Arc(); ToolMoveArcCoords1.matrix_tag = MatrixId; ToolMoveArcCoords1.start_angle = 0 * UFConstants.DEGRA; ToolMoveArcCoords1.end_angle = 360 * UFConstants.DEGRA; ToolMoveArcCoords1.arc_center = new Double[3]; ToolMoveArcCoords1.arc_center[0] = 120; ToolMoveArcCoords1.arc_center[1] = 0.0; ToolMoveArcCoords1.arc_center[2] = 0.0; ToolMoveArcCoords1.radius = 60; Tag ToolMoveArcTag1 = Tag.Null; theUfSession.Curve.CreateArc(ref ToolMoveArcCoords1, out ToolMoveArcTag1); //创建链表 Tag[] ToolMoveArcList; theUfSession.Modl.CreateList(out ToolMoveArcList); //插入对象到链表 theUfSession.Modl.PutListItem(ref ToolMoveArcList, ToolMoveArcTag1); //创建拉伸 string[] ToolMoveLimit = { "0.0", "50.0" }; double[] ToolMovePoint = { 0.0, 0.0, 0.0 }; double[] ToolMoveDirection = { 0.0, 0.0, 1.0 }; Tag[] ToolMoveExtrudedTag; theUfSession.Modl.CreateExtruded(ToolMoveArcList, "0", ToolMoveLimit, ToolMovePoint, ToolMoveDirection, FeatureSigns.Nullsign, out ToolMoveExtrudedTag); //特征找体 Tag ToolMoveBodyTag = Tag.Null; theUfSession.Modl.AskFeatBody(ToolMoveExtrudedTag[0], out ToolMoveBodyTag); //创建颜色 theUfSession.Obj.SetColor(ToolMoveBodyTag, 211); //布尔求交 int NumResult = 0; Tag[] ResultingBodies; theUfSession.Modl.IntersectBodies(ToolMoveBodyTag, HoleBodyTag, out NumResult, out ResultingBodies); //获得两个圆曲线的两个交点 int num_intersections = 0; double[] data; theUfSession.Modl.IntersectCurveToCurve(HoleArcTag1, ToolMoveArcTag1, out num_intersections, out data); //创建起点 double[] FirstPoint = { data[0], data[1], data[2] }; //创建中点 double[] SecondPoint = { 100, 0, 0 }; //创建终点 double[] ThirdPoint = { data[5], data[6], data[7] }; //三点创建圆弧 Tag Thru3ArcTag = Tag.Null; theUfSession.Curve.CreateArcThru3pts(1, FirstPoint, SecondPoint, ThirdPoint, out Thru3ArcTag); //获得圆弧的长度 NXOpen.Arc arc1 = (NXOpen.Arc)NXObjectManager.Get(Thru3ArcTag); double ArcLength = arc1.GetLength(); Caesar卢尚宇 2020年6月27日