Example #1
0
        /// <summary>
        /// 创建拉伸体
        /// </summary>
        public static Extrude Extrude(Snap.NX.Face face, double height)
        {
            var     curves      = face.EdgeCurves;
            Session theSession  = Session.GetSession();
            Part    workPart    = theSession.Parts.Work;
            Part    displayPart = theSession.Parts.Display;

            var normal = face.Normal(face.BoxUV.MinU, face.BoxUV.MinV);
            var point  = face.Position(face.BoxUV.MinU, face.BoxUV.MinV);

            var curveList = new List <NXOpen.Curve>();

            curves.ToList().ForEach(u =>
            {
                curveList.Add(u);
            });

            //创建拉伸
            NXOpen.Features.Feature nullFeatures_Feature = null;
            ExtrudeBuilder          extrudeBuilder1;

            extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(nullFeatures_Feature);

            //方向
            extrudeBuilder1.Direction = workPart.Directions.CreateDirection(point, normal, SmartObject.UpdateOption.WithinModeling);

            //曲面
            Section section1;

            section1 = workPart.Sections.CreateSection();
            extrudeBuilder1.Section = section1;
            var curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(curveList.ToArray());

            SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
            rules1[0] = curveDumbRule1;
            section1.AddToSection(rules1, curves.FirstOrDefault(), null, null, new Point3d(), NXOpen.Section.Mode.Create);

            //开始值、结束值
            extrudeBuilder1.Limits.StartExtend.Value.Value = 0;
            extrudeBuilder1.Limits.EndExtend.Value.Value   = height;

            Extrude feature1;

            feature1 = (Extrude)extrudeBuilder1.CommitFeature();
            extrudeBuilder1.Destroy();
            return(feature1);
        }
Example #2
0
        /// <summary>
        /// 获取所有的电极头部面
        /// </summary>
        protected static List <Snap.NX.Face> GetElecHeadFaces(List <Snap.NX.Face> faces, Snap.NX.Face baseFace, out List <Snap.NX.Face> sideFaces)
        {
            var headFaces     = new List <Snap.NX.Face>();
            var tempSideFaces = new List <Snap.NX.Face>();

            if (baseFace != null)
            {
                //头部面
                var allFace       = faces.ToList();
                var baseFaceBoxUV = baseFace.BoxUV;
                var elecBasePos   = baseFace.Position((baseFaceBoxUV.MinU + baseFaceBoxUV.MaxU) / 2, (baseFaceBoxUV.MinV + baseFaceBoxUV.MaxV) / 2);
                allFace.RemoveAll(u => u.NXOpenTag == baseFace.NXOpenTag);
                var faceDirection = baseFace.GetFaceDirection();
                var plane         = new Snap.Geom.Surface.Plane(elecBasePos, faceDirection);

                allFace.ToList().ForEach(u =>
                {
                    try
                    {
                        var uv          = u.BoxEx();
                        var cneterPoint = new Snap.Position((uv.MaxX + uv.MinX) / 2, (uv.MaxY + uv.MinY) / 2, (uv.MaxZ + uv.MinZ) / 2);
                        var resullt     = Snap.Compute.ClosestPoints(cneterPoint, plane);
                        var dir         = Snap.Vector.Unit(resullt.Point1 - resullt.Point2);
                        if (SnapEx.Helper.Equals(dir, faceDirection))
                        {
                            headFaces.Add(u);
                        }
                        else if (u.ObjectSubType == Snap.NX.ObjectTypes.SubType.FacePlane && SnapEx.Helper.Equals(dir, -faceDirection))
                        {
                            tempSideFaces.Add(u);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                });
            }
            sideFaces = tempSideFaces;
            return(headFaces);
        }