Пример #1
0
        private Inventor.LineSegment GetLargestEdge(ref Inventor.Face FaceView)
        {
            int    length      = FaceView.Edges.Count;
            double LengthParam = 0;

            Inventor.LineSegment Segment = null;
            // Inventor.Curve2dEvaluator Curve2dEvaluator;

            Inventor.Edge Edge = FaceView.Edges[1];
            Edge.Evaluator.GetParamExtents(out double MinParam, out double MaxParam);
            Edge.Evaluator.GetLengthAtParam(MinParam, MaxParam, out double Max);
            Inventor.UnitVector Uy = mInvApplication.TransientGeometry.CreateUnitVector(0, 1, 0);
            for (int i = 1; i <= length; i++)
            {
                Edge = FaceView.Edges[i];
                Edge.Evaluator.GetParamExtents(out MinParam, out MaxParam);
                Edge.Evaluator.GetLengthAtParam(MinParam, MaxParam, out LengthParam);

                if (LengthParam >= Max)
                {
                    if (Edge.GeometryType == Inventor.CurveTypeEnum.kLineSegmentCurve)
                    {
                        Segment = Edge.Geometry;
                        if (Segment.Direction.IsPerpendicularTo(Uy))
                        {
                            //  MessageBox.Show("");
                        }
                    }
                }
            }
            return(Segment);
        }
Пример #2
0
        //Used By DXF
        public Inventor.Face GetFaceLargestArea(Inventor.SurfaceBody mSurfaceBody)
        {
            Inventor.Face WorkFace                 = null;
            System.Collections.ArrayList Areas     = new ArrayList();
            Dictionary <double, object>  AreaValue = new Dictionary <double, object>();
            double Max          = mSurfaceBody.Faces[1].Evaluator.Area * 100;
            double currentValue = 0;

            WorkFace = mSurfaceBody.Faces[1];

            Inventor.UnitVector zVector = mInvApplication.TransientGeometry.CreateUnitVector(0, 0, 1);
            for (int i = 1; i < mSurfaceBody.Faces.Count + 1; i++)
            {
                currentValue = mSurfaceBody.Faces[i].Evaluator.Area * 100;

                AreaValue.Add(currentValue, mSurfaceBody.Faces[i]);
                if (currentValue > Max)
                {
                    Max      = mSurfaceBody.Faces[i].Evaluator.Area * 100;
                    WorkFace = mSurfaceBody.Faces[i];
                }
            }

            if (WorkFace != null)
            {
                return(WorkFace);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        private void GetFaceToSetView(Inventor.SurfaceBody mSurfaceBody, Inventor.PartDocument PartDocument)
        {
            Inventor.Face WorkFace = null;

            System.Collections.ArrayList Areas     = new ArrayList();
            Dictionary <double, object>  AreaValue = new Dictionary <double, object>();
            double Max          = mSurfaceBody.Faces[1].Evaluator.Area * 100;
            double currentValue = 0;

            WorkFace = mSurfaceBody.Faces[1];

            Inventor.UnitVector zVector    = mInvApplication.TransientGeometry.CreateUnitVector(0, 0, 1);
            ArrayList           SortArray  = new ArrayList();
            ArrayList           SortArray2 = new ArrayList();

            Inventor.Plane Plane;

            for (int i = 1; i < mSurfaceBody.Faces.Count + 1; i++)
            {
                currentValue = mSurfaceBody.Faces[i].Evaluator.Area * 100;

                //SortArray.Add(currentValue);
                if (!mSurfaceBody.Faces[i].IsParamReversed)
                {
                    if (currentValue >= Max)
                    {
                        Inventor.Face       fc   = mSurfaceBody.Faces[i];
                        Inventor.UnitVector vect = PartDocument.ComponentDefinition.WorkPlanes["XY Plane"].Plane.Normal;
                        if (fc.Geometry is Inventor.Plane)
                        {
                            Plane = fc.Geometry;
                            Inventor.UnitVector pVect = GetMidPointAtFaceNormal(ref fc);
                            Max = mSurfaceBody.Faces[i].Evaluator.Area * 100;

                            if (pVect.IsParallelTo(vect, 0.00001))
                            {
                                if (Plane.Normal.DotProduct(vect) > 0)
                                {
                                    SortArray2.Add(currentValue);
                                    WorkFace = mSurfaceBody.Faces[i];
                                }
                            }
                        }
                    }
                }
            }

            if (WorkFace != null)
            {
                SetViewDirection(WorkFace);
            }
            else
            {
                return;
            }
        }
Пример #4
0
        private Inventor.UnitVector GetLargestEdgeUnitVector(ref Inventor.Face FaceView)
        {
            int    length      = FaceView.Edges.Count;
            double LengthParam = 0;

            Inventor.LineSegment Segment = null;

            Inventor.Edge Edge = FaceView.Edges[1];
            Edge.Evaluator.GetParamExtents(out double MinParam, out double MaxParam);
            Edge.Evaluator.GetLengthAtParam(MinParam, MaxParam, out double Max);
            Inventor.UnitVector UnitVector  = mInvApplication.TransientGeometry.CreateUnitVector(0, 0, 0);
            Inventor.UnitVector UnitVectorY = mInvApplication.TransientGeometry.CreateUnitVector(0, 1, 0);
            Inventor.UnitVector UnitVectorX = mInvApplication.TransientGeometry.CreateUnitVector(1, 0, 0);

            for (int i = 1; i <= length; i++)
            {
                Edge = FaceView.Edges[i];
                if (Edge.GeometryType == Inventor.CurveTypeEnum.kLineSegmentCurve)
                {
                    Segment = Edge.Geometry;
                }
                if (Edge.GeometryType == Inventor.CurveTypeEnum.kLineSegmentCurve)
                {
                    Edge.Evaluator.GetParamExtents(out MinParam, out MaxParam);
                    Edge.Evaluator.GetLengthAtParam(MinParam, MaxParam, out LengthParam);

                    if (LengthParam > Max)
                    {
                        Segment = Edge.Geometry;
                        Max     = LengthParam;
                    }
                }
            }

            if (Segment != null)
            {
                if (Edge.GeometryType == Inventor.CurveTypeEnum.kLineSegmentCurve)
                {
                    if (Segment.Direction.IsParallelTo(UnitVectorY))
                    {
                        UnitVector = UnitVectorX;
                    }
                    else if (Segment.Direction.IsParallelTo(UnitVectorX))
                    {
                        UnitVector = UnitVectorY;
                    }
                    return(UnitVector);
                }
            }
            return(UnitVector);
        }
Пример #5
0
        private void GetFaceDirction(Inventor.SurfaceBody mSurfaceBody)
        {
            foreach (Inventor.Face face in mSurfaceBody.Faces)
            {
                if (face.SurfaceType == Inventor.SurfaceTypeEnum.kPlaneSurface)
                {
                    Inventor.UnitVector YDir;

                    Inventor.Point      FacePoint = face.PointOnFace;
                    Inventor.UnitVector normal    = GetFaceNormalPoint(face, FacePoint);
                    Inventor.UnitVector XDir      = GetXDir(face, FacePoint);
                    YDir = normal.CrossProduct(XDir);
                }
            }
        }
Пример #6
0
        private Inventor.UnitVector GetFaceNormalPoint(Inventor.Face ViewFace, Inventor.Point Point)
        {
            Inventor.SurfaceEvaluator SurfaceEvaluator;
            SurfaceEvaluator = ViewFace.Evaluator;
            Inventor.UnitVector UnitVector    = null;
            double[]            Points        = new double[3];
            double[]            GuessParam    = new double[2];
            double[]            maxDeviations = new double[2];
            double[]            Params        = new double[2];

            Inventor.SolutionNatureEnum[] NatureEnum = new Inventor.SolutionNatureEnum[1];

            Points[0] = Point.X;
            Points[1] = Point.Y;
            Points[2] = Point.Z;

            SurfaceEvaluator.GetParamAtPoint(Points, GuessParam, maxDeviations, Params, NatureEnum);

            double[] normal = new double[3];
            SurfaceEvaluator.GetNormal(ref Params, ref normal);
            UnitVector = mInvApplication.TransientGeometry.CreateUnitVector(normal[0], normal[1], normal[2]);
            return(UnitVector);
        }
Пример #7
0
        private Inventor.UnitVector GetXDir(ref Inventor.Face Face, ref Inventor.Point Point)
        {
            Inventor.SurfaceEvaluator SurfaceEvaluator;
            SurfaceEvaluator = Face.Evaluator;
            Inventor.UnitVector UnitVector    = null;
            double[]            Points        = new double[3];
            double[]            GuessParam    = new double[2];
            double[]            maxDeviations = new double[2];
            double[]            Params        = new double[2];
            double[]            uTangents     = new double[3];
            double[]            vTangents     = new double[3];

            Inventor.SolutionNatureEnum[] NatureEnum = new Inventor.SolutionNatureEnum[5];

            Points[0] = Point.X;
            Points[1] = Point.Y;
            Points[2] = Point.Z;

            SurfaceEvaluator.GetParamAtPoint(ref Points, ref GuessParam, ref maxDeviations, ref Params, ref NatureEnum);

            SurfaceEvaluator.GetTangents(ref Params, ref uTangents, ref vTangents);
            UnitVector = mInvApplication.TransientGeometry.CreateUnitVector(uTangents[0], uTangents[1], uTangents[2]);
            return(UnitVector);
        }
Пример #8
0
        private void SetDrawingView(Inventor.SurfaceBody mSurfaceBody, ref Inventor.Camera Camera, Inventor.Face TargetFace)
        {
            if (TargetFace != null)
            {
                if (!TargetFace.IsParamReversed)
                {
                    if (TargetFace.Geometry is Inventor.Plane)
                    {
                        //Inventor.Face TargetFace = Face;
                        Inventor.Point      FacePoint      = TargetFace.PointOnFace;
                        Inventor.UnitVector Normal         = GetFaceNormal(ref TargetFace, ref FacePoint);
                        Inventor.UnitVector UplDirection   = mInvApplication.TransientGeometry.CreateUnitVector(0, 1, 0);
                        Inventor.UnitVector Z_PosDirection = mInvApplication.TransientGeometry.CreateUnitVector(0, 0, 1);
                        Inventor.UnitVector Z_NegDirection = mInvApplication.TransientGeometry.CreateUnitVector(0, 0, -1);
                        Inventor.UnitVector X_PosDirection = mInvApplication.TransientGeometry.CreateUnitVector(1, 0, 0);
                        Inventor.UnitVector Y_PosDirection = mInvApplication.TransientGeometry.CreateUnitVector(0, 1, 0);
                        Inventor.UnitVector X_NegDirection = mInvApplication.TransientGeometry.CreateUnitVector(-1, 0, 0);
                        Inventor.UnitVector Y_NegDirection = mInvApplication.TransientGeometry.CreateUnitVector(0, -1, 0);
                        if (Z_PosDirection.IsEqualTo(Normal))
                        {
                            if (GetExtents(mSurfaceBody) == "X")
                            {
                                UplDirection = Y_NegDirection;
                            }
                            else if (GetExtents(mSurfaceBody) == "Y")
                            {
                                UplDirection = X_NegDirection;
                            }
                            else if (GetExtents(mSurfaceBody) == "Z")
                            {
                                UplDirection = GetXDir(ref TargetFace, ref FacePoint);
                            }
                            FacePoint = Camera.Eye.Copy();
                            FacePoint.TranslateBy(GetMidPointAtFaceNormal(ref TargetFace).AsVector());
                            Camera.Target = FacePoint;

                            Camera.UpVector = UplDirection;

                            Camera.Fit();
                            Camera.Apply();
                        }
                        else if (Z_NegDirection.IsEqualTo(Normal))
                        {
                            if (GetExtents(mSurfaceBody) == "X")
                            {
                                UplDirection = Y_PosDirection;
                            }
                            else if (GetExtents(mSurfaceBody) == "Y")
                            {
                                UplDirection = X_PosDirection;
                            }
                            else if (GetExtents(mSurfaceBody) == "Z")
                            {
                                UplDirection = GetXDir(ref TargetFace, ref FacePoint);
                            }

                            FacePoint = Camera.Eye.Copy();
                            FacePoint.TranslateBy(GetMidPointAtFaceNormal(ref TargetFace).AsVector());
                            Camera.Target = FacePoint;

                            Camera.UpVector = UplDirection;

                            Camera.Fit();
                            Camera.Apply();
                        }
                    }
                }
            }
        }