示例#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
        public Inventor.Face GetBiggestFace(Inventor.SurfaceBody mSurfaceBody)
        {
            double Max          = mSurfaceBody.Faces[1].Evaluator.Area * 100;
            double currentValue = 0;

            Inventor.Face TargetFace = null;
            foreach (Inventor.Face Face in mSurfaceBody.Faces)
            {
                currentValue = Face.Evaluator.Area * 100;

                if (currentValue > Max)
                {
                    Max        = Face.Evaluator.Area * 100;
                    TargetFace = Face;
                }
            }

            if (TargetFace != null)
            {
                return(TargetFace);
            }
            else
            {
                return(null);
            }
        }
示例#3
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);
            }
        }
示例#4
0
        private void SetViewDirection(Inventor.Face FaceView)
        {
            Inventor.Camera Camera = mInvApplication.ActiveView.Camera;
            Inventor.Point  Pnt;
            Inventor.View   PlaneView = mInvApplication.ActiveView;
            //  ' Set Eye or Target
            if (FaceView.IsParamReversed)
            {
                Pnt = Camera.Eye.Copy();
                Pnt.TranslateBy(GetMidPointAtFaceNormal(ref FaceView).AsVector());
                Camera.Target = Pnt;
            }
            else
            {
                Pnt = Camera.Target.Copy();
                Pnt.TranslateBy(GetMidPointAtFaceNormal(ref FaceView).AsVector());
                Camera.Eye = Pnt;
            }

            Camera.UpVector = GetLargestEdgeUnitVector(ref FaceView);
            Camera.Fit();
            Camera.Apply();
            PlaneView.SetCurrentAsTop();
            PlaneView.SetCurrentAsHome(true);
            PlaneView.Update();
        }
示例#5
0
        private void SetViewDirectionByRange(Inventor.Face FaceView)
        {
            Inventor.SurfaceBody mSurfaceBody;
            mSurfaceBody = FaceView.SurfaceBody;
            Inventor.Box mRangeBox;
            double       Length;
            double       Width;
            double       Thickness;

            double[] SortArray = new double[3];
            mRangeBox = mSurfaceBody.RangeBox;
            mRangeBox.Extend(mSurfaceBody.RangeBox.MinPoint);
            mRangeBox.Extend(mSurfaceBody.RangeBox.MaxPoint);
            GetFaceSize(mSurfaceBody);
            //  works only if alained to ucs
            if (mRangeBox != null)
            {
                Length       = mRangeBox.MaxPoint.X - mRangeBox.MinPoint.X;
                SortArray[0] = Length;
                Width        = mRangeBox.MaxPoint.Y - mRangeBox.MinPoint.Y;
                SortArray[1] = Width;
                Thickness    = mRangeBox.MaxPoint.Z - mRangeBox.MinPoint.Z;
                SortArray[2] = Thickness;
            }
        }
示例#6
0
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        // Developing `

        private Inventor.UnitVector GetFaceNormalAtPoint(ref Inventor.Face ViewFace, Inventor.Point point)
        {
            Inventor.TransientGeometry TransientGeometry = mInvApplication.TransientGeometry;
            double[] Pnt = new double[0];
            double[] n   = new double[3];
            Pnt[0] = point.X; Pnt[1] = point.X; Pnt[2] = point.X;
            ViewFace.Evaluator.GetNormalAtPoint(ref Pnt, ref n);
            return(TransientGeometry.CreateUnitVector(n[0], n[1], n[2]));
        }
示例#7
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;
            }
        }
示例#8
0
        private Inventor.UnitVector GetMidPointAtFaceNormal(ref Inventor.Face Face)
        {
            Inventor.SurfaceEvaluator SurfaceEvaluator;
            SurfaceEvaluator = Face.Evaluator;
            double[] CenterPoint = new double[2];
            CenterPoint[0] = (SurfaceEvaluator.ParamRangeRect.MinPoint.X + SurfaceEvaluator.ParamRangeRect.MaxPoint.X) / 2;
            CenterPoint[1] = (SurfaceEvaluator.ParamRangeRect.MinPoint.Y + SurfaceEvaluator.ParamRangeRect.MaxPoint.Y) / 2;

            double[] normal = new double[2];
            SurfaceEvaluator.GetNormal(ref CenterPoint, ref normal);

            return(mInvApplication.TransientGeometry.CreateUnitVector(normal[0], normal[1], normal[2]));
        }
示例#9
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);
        }
示例#10
0
        private Inventor.UnitVector GetFaceNormal(ref Inventor.Face Face, ref Inventor.Point Point)
        {
            Inventor.UnitVector       UnitVector;
            Inventor.SurfaceEvaluator SurfaceEvaluator = Face.Evaluator;
            double[] Points        = new double[3];
            double[] GuessParams   = new double[2];
            double[] MaxDeviations = new double[2];
            double[] Params        = new double[2];
            double[] normal        = new double[2];
            Inventor.SolutionNatureEnum[] NatureEnum = new Inventor.SolutionNatureEnum[2];

            Points[0] = Point.X; Points[1] = Point.Y; Points[2] = Point.Z;
            SurfaceEvaluator.GetParamAtPoint(ref Points, ref GuessParams, ref MaxDeviations, ref Params, ref NatureEnum);
            SurfaceEvaluator.GetNormal(ref Params, ref normal);
            UnitVector = mInvApplication.TransientGeometry.CreateUnitVector(normal[0], normal[1], normal[2]);
            return(UnitVector);
        }
示例#11
0
        private void GetFaceToView(Inventor.SurfaceBody mSurfaceBody, ref Inventor.PartDocument PartDocument, ref Inventor.Camera Camera)
        {
            double Max          = mSurfaceBody.Faces[1].Evaluator.Area * 100;
            double currentValue = 0;

            GetExtents(mSurfaceBody);

            Inventor.Face TargetFace = null;
            foreach (Inventor.Face Face in mSurfaceBody.Faces)
            {
                currentValue = Face.Evaluator.Area * 100;

                if (currentValue >= Max)
                {
                    Max        = Face.Evaluator.Area * 100;
                    TargetFace = Face;
                }
            }
            SetDrawingView(mSurfaceBody, ref Camera, TargetFace);
        }
示例#12
0
        private void DoCommandExportDXF(Inventor.PartDocument mPartDocument)
        {
            Inventor.Face Face = null;

            Face = FaceViews.GetBiggestFace(mPartDocument.ComponentDefinition.SurfaceBodies[1]);

            if (Face != null)
            {
                Inventor.ControlDefinition Definition;
                Inventor.CommandManager    CmdManager = mInvApplication.CommandManager;
                CmdManager.PostPrivateEvent(Inventor.PrivateEventTypeEnum.kFileNameEvent, FileSaveUrl + ".dxf");
                mPartDocument.SelectSet.Clear();
                mPartDocument.SelectSet.Select(Face);

                Definition = CmdManager.ControlDefinitions["GeomToDXFCommand"];
                Definition.Execute2(true);

                CmdManager.ClearPrivateEvents();
                mPartDocument.SelectSet.Clear();
            }
        }
示例#13
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);
        }
示例#14
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();
                        }
                    }
                }
            }
        }
示例#15
0
 private void SetCameraView(Inventor.Camera Camera, Inventor.Face Face)
 {
 }