Пример #1
0
        /// <summary>
        /// 获取所有的侧面
        /// </summary>
        protected static List <Snap.NX.Face> GetBaseSideFaces(Snap.NX.Face baseFace, List <Snap.NX.Face> allSideFaces)
        {
            var result              = new List <Snap.NX.Face>();
            var faceDirection       = baseFace.GetFaceDirection();
            var baseFaceCenterPoint = baseFace.GetCenterPoint();
            var orientation         = new Snap.Orientation(faceDirection);
            var firstFace           = allSideFaces.Where(u => SnapEx.Helper.Equals(u.GetFaceDirection(), -orientation.AxisY));
            var twoFace             = allSideFaces.Where(u => SnapEx.Helper.Equals(u.GetFaceDirection(), orientation.AxisX));
            var threeFace           = allSideFaces.Where(u => SnapEx.Helper.Equals(u.GetFaceDirection(), orientation.AxisY));
            var fourFace            = allSideFaces.Where(u => SnapEx.Helper.Equals(u.GetFaceDirection(), -orientation.AxisX));

            Action <List <Snap.NX.Face> > action = itemFace => {
                if (itemFace.Count() > 1)
                {
                    var fFace = itemFace
                                .Where(u => Snap.Compute.Distance(u, baseFace) < SnapEx.Helper.Tolerance)
                                .OrderByDescending(u => Snap.Compute.Distance(baseFaceCenterPoint, ((Snap.NX.Face.Plane)u).Geometry))
                                .ThenByDescending(u => u.GetPlaneProjectArea())
                                .FirstOrDefault();
                    if (fFace != null)
                    {
                        result.Add(fFace);
                    }
                }
                else
                {
                    result.AddRange(itemFace);
                }
            };

            action(firstFace.ToList());
            action(twoFace.ToList());
            action(threeFace.ToList());
            action(fourFace.ToList());
            return(result);
        }
Пример #2
0
        public static void SetEactElectrode(Snap.NX.Body body, ref Snap.NX.Face topFace, ref Snap.NX.Face baseFace, ref Snap.NX.Point basePoint)
        {
            var faces = body.Faces.ToList();

            //清空相关属性
            if (body.IsHasAttr(EactElectrode.EACT_ELECT_GROUP))
            {
                body.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, EactElectrode.EACT_ELECT_GROUP);
            }
            faces.ToList().ForEach(u => {
                if (u.IsHasAttr(EactElectrode.EACT_ELECT_GROUP))
                {
                    u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, EactElectrode.EACT_ELECT_GROUP);
                }

                if (u.IsHasAttr(EactElectrode.BASE_BOT))
                {
                    u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, EactElectrode.BASE_BOT);
                }

                if (u.IsHasAttr(EactElectrode.BASE_TOP))
                {
                    u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, EactElectrode.BASE_TOP);
                }
            });

            if (topFace != null && baseFace != null && basePoint != null)//手动
            {
            }
            else//自动
            {
                Snap.Position basePos = new Snap.Position();
                GetEactElectrode(body, ref topFace, ref baseFace, ref basePoint, ref basePos);
                if (basePoint == null && baseFace != null)
                {
                    basePoint       = Snap.Create.Point(baseFace.GetCenterPoint());
                    basePoint.Layer = body.Layer;
                    basePoint.Color = System.Drawing.Color.Green;
                }
            }

            //赋属性
            if (topFace != null)
            {
                topFace.SetStringAttribute(EactElectrode.BASE_BOT, "1");
            }
            if (baseFace != null)
            {
                baseFace.SetStringAttribute(EactElectrode.BASE_TOP, "1");
            }
            if (basePoint != null)
            {
                var guid = Guid.NewGuid().ToString();
                body.SetStringAttribute(EactElectrode.EACT_ELECT_GROUP, guid);
                basePoint.SetStringAttribute(EactElectrode.EACT_ELECT_GROUP, guid);
            }

            if (topFace != null && baseFace != null && basePoint != null)
            {
                body.SetStringAttribute(ElectrodeInfo.EACT_SPECIALSHAPED, "1");
            }
        }