Example #1
0
        internal static Snap.Position[] PointSet(Snap.NX.ICurve icurve, int pointCount)
        {
            Globals.UndoMarkId markId  = Globals.SetUndoMark(Globals.MarkVisibility.Invisible, "Snap_PositionArray_EqualParameter999");
            PointSetBuilder    builder = Globals.WorkPart.NXOpenPart.Features.CreatePointSetBuilder(null);

            builder.Type          = PointSetBuilder.Types.CurvePoints;
            builder.CurvePointsBy = PointSetBuilder.CurvePointsType.EqualArcLength;
            builder.Associative   = false;
            builder.NumberOfPointsExpression.RightHandSide = pointCount.ToString();
            builder.StartPercentage.RightHandSide          = "0";
            builder.EndPercentage.RightHandSide            = "100";
            SelectionIntentRule[] rules = Snap.NX.Section.CreateSelectionIntentRule(new Snap.NX.ICurve[] { icurve });
            NXOpen.NXObject       nXOpenTaggedObject = (NXOpen.NXObject)icurve.NXOpenTaggedObject;
            builder.SingleCurveOrEdgeCollector.AddToSection(rules, nXOpenTaggedObject, null, null, (Point3d)icurve.StartPoint, NXOpen.Section.Mode.Create, false);
            builder.Commit();
            NXOpen.NXObject[] committedObjects = builder.GetCommittedObjects();
            builder.Destroy();
            Snap.Position[] positionArray = new Snap.Position[committedObjects.Length];
            for (int i = 0; i < positionArray.Length; i++)
            {
                TaggedObject  obj3  = committedObjects[i];
                Snap.NX.Point point = (NXOpen.Point)obj3;
                positionArray[i] = point.Position;
            }
            Globals.UndoToMark(markId, "Snap_PositionArray_EqualParameter999");
            Globals.DeleteUndoMark(markId, "Snap_PositionArray_EqualParameter999");
            return(positionArray);
        }
Example #2
0
        internal static void GetEdgeData(Snap.NX.Edge edge, out Snap.Position[] poles, out double[] knots, out double[] weights)
        {
            IntPtr ptr;

            double[]  numArray;
            double[]  numArray2;
            UFSession uFSession = Globals.UFSession;

            uFSession.Eval.Initialize2(edge.NXOpenTag, out ptr);
            int num  = -1;
            int num2 = -1;

            uFSession.Eval.AskSplineControlPts(ptr, out num, out numArray);
            uFSession.Eval.AskSplineKnots(ptr, out num2, out numArray2);
            Snap.Position[] positionArray = new Snap.Position[num];
            double[]        numArray3     = new double[num];
            for (int i = 0; i < num; i++)
            {
                positionArray[i] = new Snap.Position(numArray[i * 4], numArray[(i * 4) + 1], numArray[(i * 4) + 2]);
                numArray3[i]     = numArray[(i * 4) + 3];
            }
            poles   = positionArray;
            weights = numArray3;
            knots   = numArray2;
        }
Example #3
0
        /// <summary>
        /// 是否在相同的象限
        /// </summary>
        public static bool IsSameQuadrant(Snap.Position p1, Snap.Position p2, Snap.Position center)
        {
            var q1 = SnapEx.Helper.GetQuadrantType(p1, center, Snap.Orientation.Identity);
            var q2 = SnapEx.Helper.GetQuadrantType(p2, center, Snap.Orientation.Identity);

            return(q1 == q2);
        }
Example #4
0
    /// <summary>
    /// 创建基本视图
    /// </summary>
    /// <returns></returns>
    public static BaseView CreateBaseView(DrawingSheet ds, Snap.NX.Body body)
    {
        //UFUN创建基本视图函数
        var workPart      = NXOpen.Session.GetSession().Parts.Work;
        var theUFSession  = NXOpen.UF.UFSession.GetUFSession();
        var modelView     = workPart.ModelingViews.FindObject("FRONT");
        var draw_view_tag = CreateView(ds, body, modelView.Tag, new Snap.Position(ds.Length / 2, ds.Height / 2));


        Tag top     = Tag.Null;
        var topFace = body.Faces.FirstOrDefault(u => u.GetAttributeInfo().Where(m => m.Title == "ATTR_NAME_MARK" && u.GetStringAttribute("ATTR_NAME_MARK") == "BASE_BOT").Count() > 0);

        top = topFace.NXOpenTag;

        var box        = body.Box;
        var min        = new Snap.Position((box.MinX + box.MaxX) / 2, (box.MinY + box.MaxY) / 2, box.MinZ);
        var plane      = new Snap.Geom.Surface.Plane(min, topFace.GetFaceDirection());
        var bottomFace =
            body.Faces.OrderBy(u =>
                               Snap.Compute.Distance(min, u)
                               ).FirstOrDefault();

        Tag bottom = Tag.Null;

        //theUFSession.Obj.CycleByName("BOTTOMEDGE", ref bottom);
        bottom = bottomFace.NXOpenTag;

        CreateVerticalDim(draw_view_tag, top, bottom, new Snap.Position((ds.Length / 2) + GetBorderSize(draw_view_tag).X / 2, ds.Height / 2, 0));

        return(null);
    }
Example #5
0
        /// <summary>
        /// 创建探针
        /// </summary>
        Snap.NX.Body CreateProbe(ProbeData data)
        {
            Snap.NX.CoordinateSystem wcs = Globals.WorkPart.NXOpenPart.WCS.CoordinateSystem;
            var vector   = wcs.AxisZ;
            var position = new Snap.Position(0, 0, data.SphereRadius);
            //创建探球
            var body = Snap.Create.Sphere(position, data.SphereRadius * 2).Body;
            //创建测针
            var body1 = Snap.Create.Cylinder(position, position + (data.ArrowLength * vector), data.ArrowRadius * 2).Body;

            body1.IsHidden = true;
            position       = position + (data.ArrowLength * vector);
            //创建加长杆
            var body2 = Snap.Create.Cylinder(position, position + (data.ExtensionBarLength * vector), data.ExtensionBarRadius * 2).Body;

            body2.IsHidden = true;
            //创建测头
            position = position + (data.ExtensionBarLength * vector);
            var body3 = Snap.Create.Cylinder(position, position + (data.HeadLength * vector), data.HeadRadius * 2).Body;

            body3.IsHidden = true;
            var r = Snap.Create.Unite(body, body1, body2, body3);

            r.Orphan();

            return(body);
        }
Example #6
0
        private static Snap.Geom.Transform GetTrans(Snap.Position pos, ProbeData.AB ab)
        {
            var trans = Snap.Geom.Transform.CreateRotation(pos, -Snap.Orientation.Identity.AxisX, ab.A);

            trans = Snap.Geom.Transform.Composition(trans, Snap.Geom.Transform.CreateRotation(pos, -Snap.Orientation.Identity.AxisZ, -ab.B));
            return(trans);
        }
Example #7
0
 internal static Snap.NX.Torus CreateTorus(Snap.Position axisPoint, Vector axisVector, double majorRadius, double minorRadius)
 {
     Snap.Orientation orientation = new Snap.Orientation(axisVector);
     Snap.Position    center      = axisPoint + ((Snap.Position)(majorRadius * orientation.AxisX));
     Snap.NX.Arc      arc         = Create.Circle(center, orientation.AxisY, minorRadius);
     Snap.NX.ICurve[] curves      = new Snap.NX.ICurve[] { arc };
     return(new Snap.NX.Torus(Create.Revolve(curves, axisPoint, axisVector).NXOpenRevolve));
 }
Example #8
0
        public static Transform CreateRotation(Snap.Position basePoint, Vector axis, double angle)
        {
            int       num;
            UFSession uFSession = Globals.UFSession;

            double[] matrix = new double[12];
            uFSession.Trns.CreateRotationMatrix(basePoint.Array, axis.Array, ref angle, matrix, out num);
            return(new Transform(matrix));
        }
Example #9
0
        internal static Snap.NX.Ellipse CreateEllipse(Snap.Position center, Vector axisX, Vector axisY, double a, double b, double angle1, double angle2)
        {
            NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
            double      num      = 0.017453292519943295;

            angle1 *= num;
            angle2 *= num;
            return(new Snap.NX.Ellipse(workPart.Curves.CreateEllipse((Point3d)center, (Vector3d)axisX, (Vector3d)axisY, a, b, angle1, angle2)));
        }
Example #10
0
        public static Vector GetFaceDirectionByPoint(this Snap.NX.Face face, Snap.Position pos)
        {
            var ufSession = NXOpen.UF.UFSession.GetUFSession();

            double[] param = new double[2], faceOnPoint = pos.Array, u1 = new double[3], v1 = new double[3], u2 = new double[3], v2 = new double[3], unitNorm = new double[3], radii = new double[2];
            ufSession.Modl.AskFaceParm(face.NXOpenTag, faceOnPoint, param, faceOnPoint);
            ufSession.Modl.AskFaceProps(face.NXOpenTag, param, faceOnPoint, u1, v1, u2, v2, unitNorm, radii);
            return(Snap.Vector.Unit(new Snap.Vector(unitNorm)));
        }
Example #11
0
        public PointData IsIntervene(Snap.Position p, ProbeData data)
        {
            PointData result = null;

            PointType pointType = PointType.UNKOWN;

            Snap.NX.Face face = null;

            //基准顶面
            if (_horizontalDatumFace != null)
            {
                if (IsPointAtFace(_horizontalDatumFace, p))
                {
                    face      = _horizontalDatumFace;
                    pointType = PointType.HorizontalDatumFace;
                }
            }

            if (pointType == PointType.UNKOWN)
            {
                foreach (var u in GetVerticalDatumFaces())
                {
                    if (IsPointAtFace(u, p))
                    {
                        face      = u;
                        pointType = PointType.VerticalDatumFace;
                        break;
                    }
                }
            }

            if (pointType == PointType.UNKOWN)
            {
                foreach (var u in GetElectrodeHeadFace())
                {
                    if (IsPointAtFace(u, p))
                    {
                        face      = u;
                        pointType = PointType.HeadFace;
                        break;
                    }
                }
            }

            if (pointType != PointType.UNKOWN)
            {
                result = IsIntervene(p, face.GetFaceDirection(), data);
                if (result != null)
                {
                    result.PointType = pointType;
                }
            }


            return(result);
        }
Example #12
0
        public static Snap.Position MapAcsToWcs(Snap.Position absCoords)
        {
            UFSession uFSession = Globals.UFSession;
            int       num       = 3;
            int       num2      = 1;

            double[] numArray = new double[3];
            uFSession.Csys.MapPoint(num2, absCoords.Array, num, numArray);
            return(new Snap.Position(numArray));
        }
Example #13
0
        public static List <ProbeData.AB> OrderProbeDataAB(List <ProbeData.AB> abs, Snap.Position p, Snap.Vector pV)
        {
            var axisZ = Snap.Orientation.Identity.AxisZ;
            Func <ProbeData.AB, double> getAngleAction = (ab) => {
                var angle = Snap.Vector.Angle(pV, axisZ.Copy(GetTrans(p, ab)));
                return(angle);
            };
            var result = abs.OrderBy(u => getAngleAction(u)).ToList();

            return(result);
        }
Example #14
0
        internal static Snap.NX.CoordinateSystem CreateCoordinateSystem(Snap.Position origin, Snap.NX.Matrix matrix)
        {
            Tag       tag2;
            UFSession uFSession = Globals.UFSession;

            double[] array     = origin.Array;
            Tag      nXOpenTag = matrix.NXOpenTag;

            uFSession.Csys.CreateCsys(array, nXOpenTag, out tag2);
            return((NXOpen.CoordinateSystem)Snap.NX.NXObject.GetObjectFromTag(tag2));
        }
Example #15
0
        private static void GetSurfaceData(Snap.NX.Face face, out int surfaceType, out Snap.Position axisPoint, out Vector axisVector, out double radius1, out double radius2, out int normalFlip)
        {
            UFSession uFSession = Globals.UFSession;

            double[] point = new double[3];
            double[] dir   = new double[3];
            double[] box   = new double[6];
            uFSession.Modl.AskFaceData(face.NXOpenTag, out surfaceType, point, dir, box, out radius1, out radius2, out normalFlip);
            axisPoint  = new Snap.Position(point);
            axisVector = new Vector(dir);
        }
Example #16
0
        /// <summary>
        /// 获取点到面边的最小距离
        /// </summary>
        public static double GetPointToEdgeMinDistance(Snap.Position pos, List <Snap.NX.Curve> curves)
        {
            var result = double.MaxValue;

            foreach (var item in curves)
            {
                var d = Compute.Distance(pos, item);
                result = System.Math.Min(d, result);
            }
            return(result);
        }
Example #17
0
        public static Transform CreateScale(Snap.Position basePoint, double[] scaleFactors)
        {
            int       num;
            UFSession uFSession = Globals.UFSession;

            double[] matrix = new double[12];
            int      type   = 2;

            uFSession.Trns.CreateScalingMatrix(ref type, scaleFactors, basePoint.Array, matrix, out num);
            return(new Transform(matrix));
        }
Example #18
0
 /// <summary>
 /// 是否是边上的点
 /// </summary>
 static bool IsPointOnEdge(Snap.NX.Face face, Snap.Position p)
 {
     foreach (var item in face.EdgeCurves)
     {
         var d = Compute.Distance(p, item);
         if (d < _tolerance)
         {
             return(true);
         }
     }
     return(false);
 }
Example #19
0
 /// <summary>
 /// 是否小于探针半径
 /// </summary>
 static bool IsLessthanProbeR(List <Snap.NX.Curve> curves, Snap.Position p, ProbeData probe)
 {
     foreach (var item in curves)
     {
         var d = Compute.Distance(p, item);
         if (d <= probe.SphereRadius)
         {
             return(true);
         }
     }
     return(false);
 }
Example #20
0
        internal static void GetEdgeData(Snap.NX.Edge edge, out Snap.Position startPoint, out Snap.Position endPoint)
        {
            IntPtr ptr;

            UFEval.Line line;
            UFSession   uFSession = Globals.UFSession;

            uFSession.Eval.Initialize2(edge.NXOpenTag, out ptr);
            uFSession.Eval.AskLine(ptr, out line);
            startPoint = new Snap.Position(line.start);
            endPoint   = new Snap.Position(line.end);
        }
Example #21
0
 internal static Snap.NX.DatumAxis CreateDatumAxis(Snap.Position startPoint, Snap.Position endPoint)
 {
     NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
     NXOpen.Features.DatumAxisBuilder featureBuilder = workPart.Features.CreateDatumAxisBuilder(null);
     featureBuilder.Type           = NXOpen.Features.DatumAxisBuilder.Types.TwoPoints;
     featureBuilder.IsAssociative  = true;
     featureBuilder.IsAxisReversed = false;
     featureBuilder.Point1         = workPart.Points.CreatePoint((Point3d)startPoint);
     featureBuilder.Point2         = workPart.Points.CreatePoint((Point3d)endPoint);
     NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder);
     featureBuilder.Destroy();
     return(new Snap.NX.DatumAxis((DatumAxisFeature)feature));
 }
Example #22
0
        internal static Snap.NX.Ellipse CreateEllipse(Snap.Position center, Vector axisX, Vector axisY, double rotationAngle, double a, double b, double angle1, double angle2)
        {
            NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
            double      num      = 0.017453292519943295;

            angle1        *= num;
            angle2        *= num;
            rotationAngle *= num;
            Vector axisZ = Vector.UnitCross(axisX, axisY);

            Snap.NX.Matrix matrix = Snap.NX.Matrix.CreateMatrix(axisX, axisY, axisZ);
            return(new Snap.NX.Ellipse(workPart.Curves.CreateEllipse((Point3d)center, a, b, angle1, angle2, rotationAngle, (NXMatrix)matrix)));
        }
Example #23
0
        /// <summary>
        /// 检测是否有干涉
        /// </summary>
        PointData IsIntervene(Snap.Position p, Snap.Vector vector, ProbeData probeData)
        {
            PointData result   = null;
            var       probe    = probeData.Body;
            var       axisFace = probe.Faces.FirstOrDefault(u => u.Name == SnapEx.ConstString.CMM_INSPECTION_AXISPOINT);

            if (axisFace != null)
            {
                foreach (var ab in probeData.ABList)
                {
                    var mark          = Globals.SetUndoMark(Globals.MarkVisibility.Visible, "IsIntervene");
                    var tempAxisPoint = axisFace.Position((axisFace.BoxUV.MinU + axisFace.BoxUV.MaxU) / 2, (axisFace.BoxUV.MinV + axisFace.BoxUV.MaxV) / 2);
                    var origin        = new Snap.Position((probe.Box.MinX + probe.Box.MaxX) / 2, (probe.Box.MinY + probe.Box.MaxY) / 2, probe.Box.MaxZ);
                    var axisPoint     = origin;
                    if (SnapEx.Helper.Equals(tempAxisPoint, origin, _tolerance))
                    {
                        origin.Z    = probe.Box.MinZ + probeData.SphereRadius;
                        axisPoint.Z = probe.Box.MaxZ;
                    }
                    else
                    {
                        axisPoint.Z = probe.Box.MinZ;
                        origin.Z    = probe.Box.MaxZ - probeData.SphereRadius;
                    }
                    //A角
                    origin.Move(Snap.Geom.Transform.CreateRotation(axisPoint, _orientation.AxisX, ab.A));
                    probe.Move(Snap.Geom.Transform.CreateRotation(axisPoint, _orientation.AxisX, ab.A));
                    //B角
                    origin.Move(Snap.Geom.Transform.CreateRotation(axisPoint, _orientation.AxisZ, ab.B));
                    probe.Move(Snap.Geom.Transform.CreateRotation(axisPoint, _orientation.AxisZ, ab.B));

                    var tempP = p + (probeData.SphereRadius * vector);
                    probe.Move(Snap.Geom.Transform.CreateTranslation(tempP - origin));

                    var r = SnapEx.Create.SimpleInterference(probe, _body);
                    Globals.UndoToMark(mark, null);
                    if (r == NXOpen.GeometricAnalysis.SimpleInterference.Result.OnlyEdgesOrFacesInterfere)
                    {
                        result = new PointData()
                        {
                            Vector = vector, Position = p, A = ab.A, B = ab.B, Arrow = probeData.ProbeName
                        };
                        break;
                    }
                }
            }



            return(result);
        }
Example #24
0
        public double[] Parameters(Snap.Position point)
        {
            IntPtr   ptr;
            UFEvalsf evalsf = Globals.UFSession.Evalsf;

            evalsf.Initialize2(base.NXOpenTag, out ptr);
            double[]      array = point.Array;
            UFEvalsf.Pos3 pos   = new UFEvalsf.Pos3();
            evalsf.FindClosestPoint(ptr, array, out pos);
            double[] uv = pos.uv;
            uv[0] = this.FactorU * uv[0];
            uv[1] = this.FactorV * uv[1];
            return(uv);
        }
Example #25
0
 internal static Snap.NX.DatumAxis CreateDatumAxis(Snap.Position origin, Vector direction)
 {
     NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
     NXOpen.Features.DatumAxisBuilder featureBuilder = workPart.Features.CreateDatumAxisBuilder(null);
     featureBuilder.Type = NXOpen.Features.DatumAxisBuilder.Types.PointAndDir;
     NXOpen.Direction direction2 = workPart.Directions.CreateDirection((Point3d)origin, (Vector3d)direction, SmartObject.UpdateOption.WithinModeling);
     featureBuilder.IsAssociative  = true;
     featureBuilder.IsAxisReversed = false;
     featureBuilder.Vector         = direction2;
     featureBuilder.Point          = workPart.Points.CreatePoint((Point3d)origin);
     NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder);
     featureBuilder.Destroy();
     return(new Snap.NX.DatumAxis((DatumAxisFeature)feature));
 }
Example #26
0
        public static bool AskPointContainment(Snap.Position position, Snap.NX.Face face)
        {
            return(Snap.Compute.Distance(position, face) <= SnapEx.Helper.Tolerance);

            var ufSession = NXOpen.UF.UFSession.GetUFSession();
            int pt_status = 0;

            ufSession.Modl.AskPointContainment(position.Array, face.NXOpenTag, out pt_status);
            if (0x1 == pt_status || 0x3 == pt_status)
            {
                return(true);
            }
            return(false);
        }
Example #27
0
        public static Snap.Position MapCsysToCsys(Snap.Position inputCoords, Snap.NX.CoordinateSystem inputCsys, Snap.NX.CoordinateSystem outputCsys)
        {
            Snap.Position origin = inputCsys.Origin;
            Vector        axisX  = inputCsys.AxisX;
            Vector        axisY  = inputCsys.AxisY;
            Vector        axisZ  = inputCsys.AxisZ;

            Snap.Position position2 = (Snap.Position)(((origin + (inputCoords.X * axisX)) + (inputCoords.Y * axisY)) + (inputCoords.Z * axisZ));
            Vector        vector4   = (Vector)(position2 - outputCsys.Origin);
            double        x         = (double)(vector4 * outputCsys.AxisX);
            double        y         = (double)(vector4 * outputCsys.AxisY);

            return(new Snap.Position(x, y, (double)(vector4 * outputCsys.AxisZ)));
        }
Example #28
0
        /// <summary>
        /// 创建箭头
        /// </summary>
        public static Snap.NX.Body CreateArrows(Snap.Position origin, Snap.Vector vector)
        {
            return(Snap.Create.DatumAxis(origin, vector).Body);
            //var cylinder = Snap.Create.Cylinder(origin, vector, 40, 0.5);
            //origin = origin + (40 * vector);

            //var baseDiameter = 2.5;
            //var topDiameter = 0.0;
            //var cone = Snap.Create.Cone(origin, vector, new Number[] { baseDiameter, topDiameter }, 5);
            //var body = cone.Body;
            //var unite = Snap.Create.Unite(body, cylinder.Body);
            //unite.Orphan();
            //body.Color = System.Drawing.Color.Black;
            //return body;
        }
Example #29
0
        public double Parameter(Snap.Position point)
        {
            double    num4;
            UFSession uFSession = Globals.UFSession;
            Tag       nXOpenTag = this.NXOpenTag;

            double[] array     = point.Array;
            int      direction = 1;
            double   offset    = 0.0;
            double   tolerance = 0.0001;

            double[] numArray2 = new double[3];
            uFSession.Modl.AskPointAlongCurve2(array, nXOpenTag, offset, direction, tolerance, numArray2, out num4);
            return(((1.0 - num4) * this.MinU) + (num4 * this.MaxU));
        }
Example #30
0
        /// <summary>
        /// 移动对象
        /// </summary>
        public static void MoveObject(NXOpen.NXObject obj, Snap.Position point, Snap.Vector normal, double distance)
        {
            Session theSession  = Session.GetSession();
            Part    workPart    = theSession.Parts.Work;
            Part    displayPart = theSession.Parts.Display;

            NXOpen.Features.MoveObjectBuilder moveObjectBuilder1;
            moveObjectBuilder1 = workPart.BaseFeatures.CreateMoveObjectBuilder(null);
            moveObjectBuilder1.ObjectToMoveObject.Add(obj);
            moveObjectBuilder1.TransformMotion.DistanceVector      = workPart.Directions.CreateDirection(point, normal, SmartObject.UpdateOption.WithinModeling);
            moveObjectBuilder1.TransformMotion.DistanceValue.Value = distance;
            moveObjectBuilder1.MoveObjectResult       = NXOpen.Features.MoveObjectBuilder.MoveObjectResultOptions.MoveOriginal;
            moveObjectBuilder1.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.Distance;
            moveObjectBuilder1.Commit();
            moveObjectBuilder1.Destroy();
        }