Exemplo n.º 1
0
        internal static Snap.NX.SplitBody CreateSplitBody(Snap.NX.Body targetBody, Snap.NX.Face[] toolFaces)
        {
            NXOpen.Part work = Globals.Session.Parts.Work;
            NXOpen.Features.SplitBodyBuilder featureBuilder = work.Features.CreateSplitBodyBuilder(null);
            featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.PrepareMappingData();
            featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.DistanceTolerance = Globals.DistanceTolerance;
            featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.ChainingTolerance = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095;
            ScCollector collector = work.ScCollectors.CreateCollector();

            NXOpen.Body[] bodies = new NXOpen.Body[] { targetBody };
            BodyDumbRule  rule   = work.ScRuleFactory.CreateRuleBodyDumb(bodies);

            SelectionIntentRule[] rules = new SelectionIntentRule[] { rule };
            collector.ReplaceRules(rules, false);
            featureBuilder.TargetBodyCollector = collector;
            SelectionIntentRule[] ruleArray2 = new SelectionIntentRule[toolFaces.Length];
            for (int i = 0; i < toolFaces.Length; i++)
            {
                ruleArray2[i] = work.ScRuleFactory.CreateRuleFaceBody((NXOpen.Body)toolFaces[i].Body);
            }
            featureBuilder.BooleanTool.FacePlaneTool.ToolFaces.FaceCollector.ReplaceRules(ruleArray2, false);
            NXOpen.Features.SplitBody split = (NXOpen.Features.SplitBody)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.Destroy();
            return(new Snap.NX.SplitBody(split));
        }
Exemplo n.º 2
0
        internal static Snap.NX.TrimBody CreateTrimBody(Snap.NX.Body targetBody, Snap.NX.DatumPlane toolDatumPlane, bool direction)
        {
            NXOpen.Part     workPart       = (NXOpen.Part)Globals.WorkPart;
            TrimBodyBuilder featureBuilder = workPart.Features.CreateTrimBodyBuilder(null);

            //featureBuilder.Tolerance = Globals.DistanceTolerance;
            //featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.DistanceTolerance = Globals.DistanceTolerance;
            //featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.ChainingTolerance = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095;
            //ScCollector collector = workPart.ScCollectors.CreateCollector();
            //NXOpen.Body[] bodies = new NXOpen.Body[] { targetBody };
            //BodyDumbRule rule = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies);
            //SelectionIntentRule[] rules = new SelectionIntentRule[] { rule };
            //collector.ReplaceRules(rules, false);
            //featureBuilder.TargetBodyCollector = collector;
            featureBuilder.SetTargets(new NXOpen.Body[] { targetBody });
            featureBuilder.Tool          = toolDatumPlane.NXOpenDisplayableObject;
            featureBuilder.TrimDirection = direction ? TrimBodyBuilder.DirectionType.PositiveNormal : TrimBodyBuilder.DirectionType.NegativeNormal;
            //SelectionIntentRule[] ruleArray2 = new SelectionIntentRule[1];
            //NXOpen.DatumPlane[] faces = new NXOpen.DatumPlane[] { toolDatumPlane.NXOpenDatumPlaneFeature.DatumPlane };
            //ruleArray2[0] = workPart.ScRuleFactory.CreateRuleFaceDatum(faces);
            //featureBuilder.BooleanTool.FacePlaneTool.ToolFaces.FaceCollector.ReplaceRules(ruleArray2, false);
            //featureBuilder.BooleanTool.ReverseDirection = direction;
            NXOpen.Features.TrimBody trim = (NXOpen.Features.TrimBody)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.Destroy();
            return(new Snap.NX.TrimBody(trim));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取对角线
        /// </summary>
        static Snap.NX.Line GetDiagonalLine(Snap.NX.Body body, out Snap.NX.Face baseFace)
        {
            Snap.NX.Line result   = null;
            var          workPart = Snap.Globals.WorkPart;
            var          box      = body.Box;
            var          p2       = new Snap.Position((box.MaxX + box.MinX) / 2, (box.MaxY + box.MinY) / 2);
            var          lines    = new List <NXOpen.NXObject>();

            if (!string.IsNullOrEmpty(body.Name))
            {
                lines = workPart.NXOpenPart.Layers.GetAllObjectsOnLayer(body.Layer).Where(l => l is NXOpen.Line).ToList();
                lines.ToList().ForEach(u =>
                {
                    Snap.NX.Line line = u as NXOpen.Line;
                    bool isRemove     = true;
                    if (Snap.Compute.Distance(line, body) < SnapEx.Helper.Tolerance)
                    {
                        var p1 = (line.StartPoint + line.EndPoint) / 2;
                        p2.Z   = p1.Z;
                        if (SnapEx.Helper.Equals(p1, p2, SnapEx.Helper.Tolerance))
                        {
                            isRemove = false;
                        }
                    }

                    if (isRemove)
                    {
                        lines.Remove(u);
                    }
                });
            }
            GetBaseFace(body, Enumerable.Select(lines, u => Snap.NX.Line.Wrap(u.Tag)).ToList(), out baseFace, out result);
            return(result);
        }
Exemplo n.º 4
0
        public static Electrode GetElectrode(Snap.NX.Body body)
        {
            Electrode result   = null;
            var       elecName = body.Name;
            var       faces    = body.Faces;
            //顶面
            var topFace = faces.FirstOrDefault(u => u.MatchAttrValue(UP_PART_MOLD_FACE_TYPE, BASE_BOT));
            //基准面
            var baseFace = faces.FirstOrDefault(u => u.MatchAttrValue(UP_PART_MOLD_FACE_TYPE, BASE_TOP));
            //基准台侧面
            var baseSideFaces = faces.Where(u =>
                                            u.MatchAttrValue(UP_PART_MOLD_FACE_TYPE, BASE_SIDE2) ||
                                            u.MatchAttrValue(UP_PART_MOLD_FACE_TYPE, BASE_SIDE3) ||
                                            u.MatchAttrValue(UP_PART_MOLD_FACE_TYPE, BASE_SIDE5) ||
                                            u.MatchAttrValue(UP_PART_MOLD_FACE_TYPE, BASE_SIDE6)
                                            ).ToList();
            //象限面
            var chamferFace = faces.FirstOrDefault(u => u.MatchAttrValue(UP_PART_MOLD_FACE_TYPE, BASE_CHAMFER));

            if (!string.IsNullOrEmpty(elecName) && topFace != null && baseFace != null && baseSideFaces.Count >= 4)
            {
                var model = new UPElectrode();
                model.BaseFace      = baseFace;
                model.TopFace       = topFace;
                model.BaseSideFaces = baseSideFaces.ToList();
                model.ElecBody      = body;
                model.ChamferFace   = chamferFace;
                //model.ElecHeadFaces = Electrode.GetElecHeadFaces(faces.ToList(), baseFace, out baseSideFaces);
                result = model;
                model.AllObject.Add(body);
            }
            return(result);
        }
Exemplo n.º 5
0
        public static Electrode GetElectrode(Snap.NX.Body body)
        {
            Electrode result   = null;
            var       elecName = body.Name;
            var       faces    = body.Faces;
            //顶面
            var topFace = faces.FirstOrDefault(u => u.MatchAttrValue(BASE_BOT, 1));
            //基准面
            var baseFaces = faces.Where(u => u.MatchAttrValue(BASE_TOP, 1)).ToList();
            var baseFace  = baseFaces.FirstOrDefault();

            if (baseFaces.Count > 1)
            {
                baseFace = baseFaces.OrderByDescending(u => Snap.Compute.Perimeter(u)).FirstOrDefault();
            }
            var attrValue = body.GetAttrValue(EACT_ELECT_GROUP);
            //基准点
            var elecBasePoint = Snap.Globals.WorkPart.Points.FirstOrDefault(u => !string.IsNullOrEmpty(attrValue) && u.MatchAttrValue(EACT_ELECT_GROUP, attrValue));

            if (!string.IsNullOrEmpty(elecName) && topFace != null && baseFace != null)
            {
                var model = new EactElectrode();
                model.BaseFace      = baseFace;
                model.TopFace       = topFace;
                model.ElecBasePoint = elecBasePoint;
                model.ElecBody      = body;
                result = model;
                model.AllObject.Add(body);
                if (elecBasePoint != null)
                {
                    model.AllObject.Add(elecBasePoint);
                }
            }
            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取对角线
        /// </summary>
        Snap.NX.Line GetDiagonalLine(Snap.NX.Body body)
        {
            Snap.NX.Line result   = null;
            var          workPart = Snap.Globals.WorkPart;

            var box = body.Box;

            var p2 = new Snap.Position((box.MaxX + box.MinX) / 2, (box.MaxY + box.MinY) / 2);

            if (!string.IsNullOrEmpty(body.Name))
            {
                var lines = workPart.NXOpenPart.Layers.GetAllObjectsOnLayer(body.Layer).Where(l => l is NXOpen.Line).ToList();
                lines.ForEach(u =>
                {
                    Snap.NX.Line line = u as NXOpen.Line;
                    var p1            = (line.StartPoint + line.EndPoint) / 2;
                    p2.Z = p1.Z;
                    if (SnapEx.Helper.Equals(p1, p2, JYElecHelper._tolerance))
                    {
                        result = line;
                        return;
                    }
                });
            }

            return(result);
        }
Exemplo n.º 7
0
        public static bool IsElec(Snap.NX.Body body)
        {
            bool result = false;

            result = body.GetAttributeInfo().Where(u => u.Title == JYElecConst.ELEC_FINISH_NUMBER || u.Title == JYElecConst.ELEC_MIDDLE_NUMBER || u.Title == JYElecConst.ELEC_ROUGH_NUMBER).Count() > 0;
            return(result);
        }
Exemplo n.º 8
0
        public static double GetAttrValue(Snap.NX.Body body, string title)
        {
            double d;

            if (body.GetAttributeInfo().Where(u => u.Title == title).Count() > 0)
            {
                var attr = body.GetAttributeInfo().FirstOrDefault(u => u.Title == title);
                switch (attr.Type)
                {
                case Snap.NX.NXObject.AttributeType.Integer:
                {
                    d = body.GetIntegerAttribute(title);
                    break;
                }

                case Snap.NX.NXObject.AttributeType.Real:
                {
                    d = body.GetRealAttribute(title);
                    break;
                }

                default:
                {
                    d = 0;
                    break;
                }
                }
            }
            else
            {
                d = 0;
            }
            return(d);
        }
Exemplo n.º 9
0
 static Snap.NX.Face GetElecFace(Snap.NX.Body body, string type)
 {
     return(body.Faces.FirstOrDefault(u =>
     {
         return u.GetAttributeInfo().Where(a => a.Title.Equals(type)).Count() > 0;
     }));
 }
Exemplo n.º 10
0
        public static Electrode GetElectrode(Snap.NX.Body body)
        {
            Electrode result   = null;
            var       elecName = body.Name;
            var       faces    = body.Faces;
            //顶面
            var topFace = faces.FirstOrDefault(u => u.MatchAttrValue(ATTR_NAME_MARK, BASE_BOT));
            //基准面
            var baseFace = faces.FirstOrDefault(u => u.MatchAttrValue(ATTR_NAME_MARK, BASE_TOP));
            //基准台侧面
            var baseSideFaces = faces.Where(u => u.MatchAttrValue(ATTR_NAME_MARK, BASE_SIDE)).ToList();
            //基准点
            var elecBasePoint = Snap.Globals.WorkPart.Points.Where(u => u.MatchAttrValue(ATTR_NAME_MARK, elecName) && u.MatchAttrValue(DIM_PT, DIM_PT))
                                .OrderBy(u => Snap.Compute.Distance(u.Position, body)).FirstOrDefault();
            //象限面
            var chamferFace = faces.FirstOrDefault(u => u.MatchAttrValue(ATTR_NAME_MARK, BASE_CHAMFER));

            if (!string.IsNullOrEmpty(elecName) && topFace != null && baseFace != null && baseSideFaces.Count >= 4
                //&& elecBasePoint != null
                )
            {
                var model = new XKElectrode();
                model.BaseFace      = baseFace;
                model.TopFace       = topFace;
                model.BaseSideFaces = baseSideFaces.ToList();
                model.ElecBasePoint = elecBasePoint;
                model.ElecBody      = body;
                model.ChamferFace   = chamferFace;
                //model.ElecHeadFaces = Electrode.GetElecHeadFaces(faces.ToList(), baseFace, out baseSideFaces);
                result = model;
                model.AllObject.Add(body);
                model.AllObject.Add(elecBasePoint);
            }
            return(result);
        }
Exemplo n.º 11
0
        public static Snap.Position?GetElecMidPosition(Snap.NX.Part workPart, Snap.NX.Body body)
        {
            Snap.Position?result = null;
            var           point  = GetElecMidPointInPart(workPart, body);

            if (point == null)
            {
                var name = GetStringAttribute(body, SnapEx.EactConstString.EACT_ELECT_GROUP);
                if (!string.IsNullOrEmpty(name))
                {
                    if (body.NXOpenBody.OwningComponent != null && body.OwningComponent.Prototype != null)
                    {
                        var           part     = body.OwningComponent.Prototype;
                        Snap.NX.Point oldPoint = GetElecMidPointInPart(part, body);
                        if (oldPoint != null)
                        {
                            var           oldPosition = new Snap.Position(oldPoint.X, oldPoint.Y, oldPoint.Z);
                            var           vCom        = Snap.Vector.Unit(body.OwningComponent.Orientation.AxisZ);
                            var           v2          = new Snap.Vector(oldPosition);
                            Snap.Position newPosition = body.OwningComponent.Position - (vCom + v2);
                            result = newPosition;
                        }
                    }
                }
            }
            else
            {
                result = point.Position;
            }

            return(result);
        }
Exemplo n.º 12
0
 public static Snap.NX.Body[] Copy(Transform xform, params Snap.NX.Body[] original)
 {
     Snap.NX.Body[] bodyArray = new Snap.NX.Body[original.Length];
     for (int i = 0; i < original.Length; i++)
     {
         bodyArray[i] = original[i].Copy(xform);
     }
     return(bodyArray);
 }
Exemplo n.º 13
0
 public Electrode(Snap.NX.Body body)
 {
     _body  = body;
     _faces = _body.Faces.ToList();
     _horizontalDatumFace = GetHorizontalDatumFace();
     if (_horizontalDatumFace == null)
     {
         throw new Exception("该实体无法取点!");
     }
 }
Exemplo n.º 14
0
 public XKElectrodeInfo(Snap.NX.Body body) : base(body)
 {
     ELEC_FINISH_NUMBER = XKElecConst.ELE_F_COUNT;
     ELEC_MIDDLE_NUMBER = XKElecConst.ELE_S_COUNT;
     ELEC_ROUGH_NUMBER  = XKElecConst.ELE_R_COUNT;
     ELEC_FINISH_SPACE  = XKElecConst.ELE_F_SG;
     ELEC_MIDDLE_SPACE  = XKElecConst.ELE_S_SG;
     ELEC_ROUGH_SPACE   = XKElecConst.ELE_R_SG;
     ELEC_MAT_NAME      = XKElecConst.ELE_MATERIAL;
 }
Exemplo n.º 15
0
        /// <summary>
        /// WAVE
        /// </summary>
        public static NXOpen.Tag CreateLinkedBody(Snap.NX.Body body, Snap.NX.Component comp, Snap.NX.Component toComp)
        {
            var ufSession = NXOpen.UF.UFSession.GetUFSession();

            NXOpen.Tag tempTag;
            ufSession.So.CreateXformAssyCtxt(toComp.Prototype.NXOpenTag, comp.NXOpenTag, toComp.NXOpenTag, out tempTag);
            NXOpen.Tag linkTag;
            ufSession.Wave.CreateLinkedBody(body.NXOpenTag, tempTag, toComp.Prototype.NXOpenTag, false, out linkTag);
            NXOpen.Tag tgTag;
            ufSession.Modl.AskFeatBody(linkTag, out tgTag);
            return(tgTag);
        }
Exemplo n.º 16
0
        /// <summary>
        /// 获取基准面
        /// </summary>
        static void GetBaseFace(Snap.NX.Body body, List <Snap.NX.Line> diagonalLines, out Snap.NX.Face face, out Snap.NX.Line line)
        {
            Snap.NX.Face outFace = null;
            Snap.NX.Line outLine = null;
            var          faces   = body.Faces.ToList();

            faces = faces.Where(u => u.ObjectSubType == Snap.NX.ObjectTypes.SubType.FacePlane).ToList();
            var baseFace = faces.Where(u => u.IsHasAttr(ELEC_BASE_EDM_FACE)).FirstOrDefault();

            if (baseFace != null)
            {
                faces = new List <Snap.NX.Face> {
                    baseFace
                };
            }
            var tempFaces = faces.Where(u => SnapEx.Helper.Equals(u.GetFaceDirection(), -Snap.Globals.WcsOrientation.AxisZ, SnapEx.Helper.Tolerance)).ToList();

            tempFaces = tempFaces.OrderByDescending(u => {
                var uv = u.BoxUV;
                return(Math.Abs(uv.MinU - uv.MaxU) * Math.Abs(uv.MaxV - uv.MinV));
            }).ToList();

            tempFaces.ForEach(u =>
            {
                faces.Remove(u);
            });

            faces.InsertRange(0, tempFaces);

            foreach (var u in faces)
            {
                var corners = u.Box.Corners.Distinct().ToList();
                foreach (var item in diagonalLines)
                {
                    Snap.NX.Line diagonalLine = item;
                    if (Snap.Compute.Distance(diagonalLine, u) < SnapEx.Helper.Tolerance)
                    {
                        var startPos = corners.Where(m => SnapEx.Helper.Equals(m, diagonalLine.StartPoint, SnapEx.Helper.Tolerance));
                        var endPos   = corners.Where(m => SnapEx.Helper.Equals(m, diagonalLine.EndPoint, SnapEx.Helper.Tolerance));
                        if (startPos.Count() > 0 && endPos.Count() > 0)
                        {
                            outFace = u;
                            outLine = diagonalLine;
                            face    = outFace;
                            line    = outLine;
                            return;
                        }
                    }
                }
            }
            face = outFace;
            line = outLine;
        }
Exemplo n.º 17
0
        internal static Snap.NX.NXObject CreateNXObject(TaggedObject nxopenTaggedObject)
        {
            Snap.NX.NXObject obj2         = null;
            NXOpen.NXObject  nxopenObject = nxopenTaggedObject as NXOpen.NXObject;
            if (nxopenObject != null)
            {
                obj2 = new Snap.NX.NXObject(nxopenObject);
                NXOpen.Curve nxopenCurve = nxopenObject as NXOpen.Curve;
                if (nxopenCurve != null)
                {
                    obj2 = Snap.NX.Curve.CreateCurve(nxopenCurve);
                }
                switch (GetTypeFromTag(nxopenObject.Tag))
                {
                case ObjectTypes.Type.Point:
                    obj2 = new Snap.NX.Point((NXOpen.Point)nxopenObject);
                    break;

                case ObjectTypes.Type.DatumPlane:
                    obj2 = new Snap.NX.DatumPlane((DatumPlaneFeature)nxopenObject);
                    break;

                case ObjectTypes.Type.DatumAxis:
                    obj2 = new Snap.NX.DatumAxis((DatumAxisFeature)nxopenObject);
                    break;

                case ObjectTypes.Type.CoordinateSystem:
                    obj2 = new Snap.NX.CoordinateSystem((NXOpen.CoordinateSystem)nxopenObject);
                    break;

                case ObjectTypes.Type.Body:
                    obj2 = new Snap.NX.Body((NXOpen.Body)nxopenObject);
                    break;

                case ObjectTypes.Type.Face:
                    obj2 = Snap.NX.Face.CreateFace((NXOpen.Face)nxopenObject);
                    break;

                case ObjectTypes.Type.Edge:
                    obj2 = Snap.NX.Edge.CreateEdge((NXOpen.Edge)nxopenObject);
                    break;

                case ObjectTypes.Type.Feature:
                    obj2 = Snap.NX.Feature.CreateFeature((NXOpen.Features.Feature)nxopenObject);
                    break;

                case ObjectTypes.Type.Component:
                    return(new Snap.NX.Component((NXOpen.Assemblies.Component)nxopenObject));
                }
            }
            return(obj2);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 获取进玉电极信息
        /// </summary>
        public JYElecInfo GetJYElecInfo(Snap.NX.Body body)
        {
            JYElecInfo result       = null;
            var        diagonalLine = GetDiagonalLine(body);

            if (diagonalLine != null)
            {
                result          = new JYElecInfo();
                result.ElecName = body.Name;
            }

            return(result);
        }
Exemplo n.º 19
0
 internal static ObjectTypes.SubType GetBodySubType(Snap.NX.Body body)
 {
     ObjectTypes.SubType bodyGeneral = ObjectTypes.SubType.BodyGeneral;
     if (body.NXOpenBody.IsSolidBody)
     {
         bodyGeneral = ObjectTypes.SubType.BodySolid;
     }
     if (body.NXOpenBody.IsSheetBody)
     {
         bodyGeneral = ObjectTypes.SubType.BodySheet;
     }
     return(bodyGeneral);
 }
Exemplo n.º 20
0
        /// <summary>
        /// 自动取点
        /// </summary>
        public static List <PointData> AutoSelPoint(Snap.NX.Body body, CMMConfig config, bool isUploadFile = true)
        {
            var result    = new List <PointData>();
            var electrode = ElecManage.Electrode.GetElectrode(body);

            if (electrode == null)
            {
                throw new Exception("无法识别该电极!");
            }
            electrode.InitAllFace();
            bool   CMMResult = true;
            string CMMInfo   = string.Empty;

            try
            {
                result = AutoSelPoint(electrode, config, isUploadFile);
            }
            catch (Exception ex)
            {
                CMMResult = false;
                CMMInfo   = ex.Message;
                if (!config.IsUploadDataBase)
                {
                    throw ex;
                }
            }

            var info = electrode.GetElectrodeInfo();

            if (!CMMResult)
            {
                Helper.ShowMsg(string.Format("{0}【{1}】", info.Elec_Name, CMMInfo), 1);
            }

            if (config.IsUploadDataBase)
            {
                DataAccess.Model.EACT_AUTOCMM_RECORD record = new DataAccess.Model.EACT_AUTOCMM_RECORD();
                record.CMMDATE   = DateTime.Now;
                record.CMMINFO   = CMMInfo;
                record.CMMRESULT = CMMResult ? 1 : 2;
                record.MODELNO   = info.EACT_MODELNO;
                record.PARTNO    = info.EACT_PARTNO;
                record.PARTNAME  = info.Elec_Name;
                Helper.ShowMsg(string.Format("{0}上传取点记录", info.Elec_Name));
                InitDatabase();
                DataAccess.BOM.UploadAutoCMMRecord(record);
                Helper.ShowMsg(string.Format("{0}取点记录上传完成", info.Elec_Name));
            }

            return(result);
        }
Exemplo n.º 21
0
        /// <summary>
        /// 获取对角线
        /// </summary>
        static Snap.NX.Line GetDiagonalLine(Snap.NX.Body body, out Snap.NX.Face baseFace)
        {
            Snap.NX.Line result = null;
            baseFace = null;
            var workPart = Snap.Globals.WorkPart;
            var box      = body.Box;
            var p2       = new Snap.Position((box.MaxX + box.MinX) / 2, (box.MaxY + box.MinY) / 2, (box.MaxZ + box.MinZ) / 2);
            var lines    = new List <Snap.NX.Line>();

            if (!string.IsNullOrEmpty(body.Name))
            {
                lines = workPart.NXOpenPart.Layers.GetAllObjectsOnLayer(body.Layer).ToArray().Where(u => u is NXOpen.Line).Select(u => Snap.NX.Line.Wrap(u.Tag)).ToList();
                foreach (var line in lines.ToList())
                {
                    if (!Entry.Instance.IsDistinguishSideElec)
                    {
                        var p1      = (line.StartPoint + line.EndPoint) / 2;
                        var tempVec = p1 - p2;
                        var tempOri = Snap.Globals.Wcs.Orientation.AxisZ;
                        if ((
                                SnapEx.Helper.Equals(tempVec, tempOri, SnapEx.Helper.Tolerance) ||
                                SnapEx.Helper.Equals(tempVec, -tempOri, SnapEx.Helper.Tolerance) ||
                                SnapEx.Helper.Equals(p1, p2, SnapEx.Helper.Tolerance)
                                ) && Snap.Compute.Distance(line, body) < SnapEx.Helper.Tolerance
                            )
                        {
                        }
                        else
                        {
                            lines.Remove(line);
                        }
                    }
                    else
                    {
                        if (Snap.Compute.Distance(line, body) < SnapEx.Helper.Tolerance)
                        {
                        }
                        else
                        {
                            lines.Remove(line);
                        }
                    }
                }
            }
            if (lines.Count > 0)
            {
                GetBaseFace(body, lines, out baseFace, out result);
            }
            return(result);
        }
Exemplo n.º 22
0
        internal static Snap.NX.Boolean CreateBoolean(Snap.NX.Body target, Snap.NX.Body[] toolBodies, NXOpen.Features.Feature.BooleanType booleanType)
        {
            NXOpen.Features.BooleanBuilder featureBuilder = Globals.WorkPart.NXOpenPart.Features.CreateBooleanBuilder(null);
            featureBuilder.Operation = booleanType;
            featureBuilder.Target    = target.NXOpenBody;
            foreach (Snap.NX.Body body in toolBodies)
            {
                featureBuilder.Tools.Add(body.NXOpenBody);
            }
            BooleanFeature boolean = (BooleanFeature)Snap.NX.Feature.CommitFeature(featureBuilder);

            featureBuilder.Destroy();
            return(new Snap.NX.Boolean(boolean));
        }
Exemplo n.º 23
0
        public static void ExportStp(Snap.NX.Body body, string path, Func <Snap.Geom.Transform> func = null, params Snap.Geom.Transform[] transfroms)
        {
            var fileName = string.Format("{0}{1}", path, ".stp");

            if (System.IO.File.Exists(fileName))
            {
                System.IO.File.Delete(fileName);
            }
            var workPart = NXOpen.Session.GetSession().Parts.Work;
            var mark     = Snap.Globals.SetUndoMark(Snap.Globals.MarkVisibility.Invisible, "ExportStp");

            try
            {
                if (body.IsOccurrence)
                {
                    transfroms.ToList().ForEach(u =>
                    {
                        var trans        = u.Matrix;
                        Matrix3x3 matrix = new Matrix3x3();
                        matrix.Xx        = trans[0]; matrix.Xy = trans[4]; matrix.Xz = trans[8];
                        matrix.Yx        = trans[1]; matrix.Yy = trans[5]; matrix.Yz = trans[9];
                        matrix.Zx        = trans[2]; matrix.Zy = trans[6]; matrix.Zz = trans[10];
                        workPart.ComponentAssembly.MoveComponent(body.OwningComponent, new Vector3d(trans[3], trans[7], trans[11]), matrix);
                    });
                }
                else
                {
                    var trans = Snap.Geom.Transform.CreateTranslation();
                    transfroms.ToList().ForEach(u =>
                    {
                        trans = Snap.Geom.Transform.Composition(trans, u);
                    });
                    body.Move(trans);
                    if (func != null)
                    {
                        body.Move(func());
                    }
                }

                SnapEx.Create.ExportStp(new List <NXObject> {
                    body
                }, path);
            }
            catch (Exception ex)
            {
                UI.GetUI().NXMessageBox.Show("提示", NXOpen.NXMessageBox.DialogType.Information, ex.Message);
            }

            Snap.Globals.UndoToMark(mark, null);
        }
Exemplo n.º 24
0
 internal static Snap.NX.Sew CreateSew(Snap.NX.Body targetBody, Snap.NX.Body[] toolBodies)
 {
     NXOpen.Features.SewBuilder featureBuilder = Globals.WorkPart.NXOpenPart.Features.CreateSewBuilder(null);
     featureBuilder.Type      = NXOpen.Features.SewBuilder.Types.Sheet;
     featureBuilder.Tolerance = Globals.DistanceTolerance;
     featureBuilder.TargetBodies.Add((DisplayableObject)targetBody);
     for (int i = 0; i < toolBodies.Length; i++)
     {
         featureBuilder.ToolBodies.Add((DisplayableObject)toolBodies[i]);
     }
     NXOpen.Features.Sew sew = (NXOpen.Features.Sew)Snap.NX.Feature.CommitFeature(featureBuilder);
     featureBuilder.Destroy();
     return(new Snap.NX.Sew(sew));
 }
Exemplo n.º 25
0
 public UPElectrodeInfo(Snap.NX.Body body) : base(body)
 {
     ELEC_FINISH_NUMBER = "UP_ELECTRODE_FINE_QUANTITY";
     ELEC_MIDDLE_NUMBER = "UP_ELECTRODE_SUITABLE_QUANTITY";
     ELEC_ROUGH_NUMBER  = "UP_ELECTRODE_ROUGH_QUANTITY";
     ELEC_FINISH_SPACE  = "UP_ELECTRODE_FINE_SPACE";
     ELEC_MIDDLE_SPACE  = "UP_ELECTRODE_SUITABLE_SPACE";
     ELEC_ROUGH_SPACE   = "UP_ELECTRODE_ROUGH_SPACE";
     ELEC_MAT_NAME      = "UP_ELECTRODE_FINE_MATERIAL";
     ELEC_F_MAT_NAME    = "UP_ELECTRODE_FINE_MATERIAL";
     ELEC_M_MAT_NAME    = "UP_ELECTRODE_SUITABLE_MATERIAL";
     ELEC_R_MAT_NAME    = "UP_ELECTRODE_ROUGH_MATERIAL";
     //ELEC_MACH_TYPE = "UP_ELECTRODE_EDM_POSITION";
     EACT_ASSEMBLYEXP  = "UP_PART_WP_PROCESS_RM";
     EACT_ASSEMBLYEXP1 = "UP_PART_WP_TECHNICAL_RM";
 }
Exemplo n.º 26
0
        public static Electrode GetElectrode(Snap.NX.Body body)
        {
            Electrode result = null;

            Snap.NX.Face baseFace     = null;
            var          diagonalLine = GetDiagonalLine(body, out baseFace);

            if (diagonalLine != null)
            {
                var faceDirection = baseFace.GetFaceDirection();
                var model         = new JYElectrode();
                model.DiagonalLine = diagonalLine;
                model.BaseFace     = baseFace;
                model.ElecBody     = body;
                result             = model;
            }
            return(result);
        }
Exemplo n.º 27
0
        public static Electrode GetElectrode(Snap.NX.Body body)
        {
            Electrode result = null;

            result = XKElectrode.GetElectrode(body);
            if (result == null)
            {
                result = UPElectrode.GetElectrode(body);
            }
            if (result == null)
            {
                result = JYElectrode.GetElectrode(body);
            }
            if (result == null)
            {
                result = EactElectrode.GetElectrode(body);
            }
            return(result);
        }
Exemplo n.º 28
0
        public List <JYElecInfo> GetElecList(Snap.NX.Body mouldBody)
        {
            var result   = new List <JYElecInfo>();
            var workPart = Snap.Globals.WorkPart;

            workPart.Bodies.Where(u => u.NXOpenTag != mouldBody.NXOpenTag).ToList().ForEach(u =>
            {
                var distance = Snap.Compute.Distance(mouldBody, u);
                if (distance <= JYElecHelper._tolerance &&
                    result.FirstOrDefault(m => m.ElecName == u.Name) == null)
                {
                    var info = GetJYElecInfo(u);
                    if (info != null)
                    {
                        result.Add(info);
                    }
                }
            });
            return(result);
        }
Exemplo n.º 29
0
 internal static Snap.NX.TrimBody CreateTrimBody(Snap.NX.Body targetBody, Snap.NX.Face toolFace, bool direction)
 {
     NXOpen.Part workPart = (NXOpen.Part) Globals.WorkPart;
     TrimBody2Builder featureBuilder = workPart.Features.CreateTrimBody2Builder(null);
     featureBuilder.Tolerance = Globals.DistanceTolerance;
     featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.DistanceTolerance = Globals.DistanceTolerance;
     featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.ChainingTolerance = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095;
     ScCollector collector = workPart.ScCollectors.CreateCollector();
     NXOpen.Body[] bodies = new NXOpen.Body[] { targetBody };
     BodyDumbRule rule = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies);
     SelectionIntentRule[] rules = new SelectionIntentRule[] { rule };
     collector.ReplaceRules(rules, false);
     featureBuilder.TargetBodyCollector = collector;
     SelectionIntentRule[] ruleArray2 = new SelectionIntentRule[] { workPart.ScRuleFactory.CreateRuleFaceBody((NXOpen.Body) toolFace.Body) };
     featureBuilder.BooleanTool.FacePlaneTool.ToolFaces.FaceCollector.ReplaceRules(ruleArray2, false);
     featureBuilder.BooleanTool.ReverseDirection = direction;
     TrimBody2 trim = (TrimBody2) Snap.NX.Feature.CommitFeature(featureBuilder);
     featureBuilder.Destroy();
     return new Snap.NX.TrimBody(trim);
 }
Exemplo n.º 30
0
        public static Snap.NX.Point GetElecMidPoint(Snap.NX.Part workPart, Snap.NX.Body body)
        {
            var point = GetElecMidPointInPart(workPart, body);

            if (point == null)
            {
                var name = GetStringAttribute(body, SnapEx.EactConstString.EACT_ELECT_GROUP);
                if (!string.IsNullOrEmpty(name))
                {
                    if (body.NXOpenBody.OwningComponent != null && body.OwningComponent.Prototype != null)
                    {
                        var           part     = body.OwningComponent.Prototype;
                        Snap.NX.Point oldPoint = GetElecMidPointInPart(part, body);
                        if (oldPoint != null)
                        {
                            SnapEx.Create.ExtractObject(new List <NXOpen.NXObject> {
                                oldPoint
                            }, workPart.FullPath, false, false);
                            oldPoint = GetElecMidPointInPart(workPart, body);
                            if (oldPoint != null)
                            {
                                var           oldPosition = new Snap.Position(oldPoint.X, oldPoint.Y, oldPoint.Z);
                                var           vCom        = Snap.Vector.Unit(body.OwningComponent.Orientation.AxisZ);
                                var           v2          = new Snap.Vector(oldPosition);
                                Snap.Position newPosition = body.OwningComponent.Position - (vCom + v2);
                                oldPoint.X = newPosition.X;
                                oldPoint.Y = newPosition.Y;
                                oldPoint.Z = newPosition.Z;
                                point      = oldPoint;
                            }
                        }
                    }
                }
            }
            else
            {
                point = point.Copy();
            }

            return(point);
        }