Esempio n. 1
0
        public void CreateOrdinateDimensions()
        {
            // Set a reference to the drawing document.
            // This assumes a drawing document is active.
            Inventor.DrawingDocument oDrawDoc = (Inventor.DrawingDocument)mInvApplication.ActiveDocument;

            // Set a reference to the active sheet.
            Inventor.Sheet oActiveSheet = (Inventor.Sheet)oDrawDoc.ActiveSheet;

            // Set a reference to the drawing curve segment.
            // This assumes that a linear drawing curve is selected.
            Inventor.DrawingCurveSegment oDrawingCurveSegment = (Inventor.DrawingCurveSegment)oDrawDoc.SelectSet[1];


            // Set a reference to the drawing curve.
            Inventor.DrawingCurve oDrawingCurve = default(Inventor.DrawingCurve);
            oDrawingCurve = oDrawingCurveSegment.Parent;

            if (!(oDrawingCurve.CurveType == Inventor.CurveTypeEnum.kLineSegmentCurve))
            {
                //MessageBox.Show("A linear curve should be selected for this sample.");
                return;
            }

            // Create point intents to anchor the dimension to.
            Inventor.GeometryIntent oDimIntent1 = default(Inventor.GeometryIntent);
            oDimIntent1 = oActiveSheet.CreateGeometryIntent(oDrawingCurve, Inventor.PointIntentEnum.kStartPointIntent);

            Inventor.GeometryIntent oDimIntent2 = default(Inventor.GeometryIntent);
            oDimIntent2 = oActiveSheet.CreateGeometryIntent(oDrawingCurve, Inventor.PointIntentEnum.kEndPointIntent);

            // Set a reference to the view to which the curve belongs.
            Inventor.DrawingView oDrawingView = default(Inventor.DrawingView);
            oDrawingView = oDrawingCurve.Parent;

            // If origin indicator has not been already created, create it first.
            if (!oDrawingView.HasOriginIndicator)
            {
                // The indicator will be located at the start point of the selected curve.
                oDrawingView.CreateOriginIndicator(oDimIntent1);
            }

            // Set a reference to the ordinate dimensions collection.
            Inventor.OrdinateDimensions oOrdinateDimensions = default(Inventor.OrdinateDimensions);
            oOrdinateDimensions = oActiveSheet.DrawingDimensions.OrdinateDimensions;

            // Create the x-axis vector
            Inventor.Vector2d oXAxis = default(Inventor.Vector2d);
            oXAxis = mInvApplication.TransientGeometry.CreateVector2d(1, 0);

            Inventor.Vector2d oCurveVector = default(Inventor.Vector2d);
            oCurveVector = oDrawingCurve.StartPoint.VectorTo(oDrawingCurve.EndPoint);

            Inventor.Point2d           oTextOrigin1 = default(Inventor.Point2d);
            Inventor.Point2d           oTextOrigin2 = default(Inventor.Point2d);
            Inventor.DimensionTypeEnum DimType      = default(Inventor.DimensionTypeEnum);

            if (oCurveVector.IsParallelTo(oXAxis))
            {
                // Selected curve is horizontal
                DimType = Inventor.DimensionTypeEnum.kVerticalDimensionType;

                // Set the text points for the 2 dimensions.
                oTextOrigin1 = mInvApplication.TransientGeometry.CreatePoint2d(oDrawingCurve.StartPoint.X, oDrawingView.Top + 5);
                oTextOrigin2 = mInvApplication.TransientGeometry.CreatePoint2d(oDrawingCurve.EndPoint.X, oDrawingView.Top + 5);
            }
            else
            {
                // Selected curve is vertical or at an angle.
                DimType = Inventor.DimensionTypeEnum.kHorizontalDimensionType;

                // Set the text points for the 2 dimensions.
                oTextOrigin1 = mInvApplication.TransientGeometry.CreatePoint2d(oDrawingView.Left - 5, oDrawingCurve.StartPoint.Y);
                oTextOrigin2 = mInvApplication.TransientGeometry.CreatePoint2d(oDrawingView.Left - 5, oDrawingCurve.EndPoint.Y);
            }

            // Create the first ordinate dimension.
            Inventor.OrdinateDimension oOrdinateDimension1 = default(Inventor.OrdinateDimension);
            oOrdinateDimension1 = oOrdinateDimensions.Add(oDimIntent1, oTextOrigin1, DimType);

            // Create the second ordinate dimension.
            Inventor.OrdinateDimension oOrdinateDimension2 = default(Inventor.OrdinateDimension);
            oOrdinateDimension2 = oOrdinateDimensions.Add(oDimIntent2, oTextOrigin2, DimType);
        }
Esempio n. 2
0
        //    Add detail drawing view API Sample
        //Description
        //This sample demonstrates the creation of a detail drawing view with an attach point.
        //Before running this sample, select a drawing view in the active drawing.
        public void CreateDetailView()
        {
            // Set a reference to the drawing document.
            // This assumes a drawing document is active.
            Inventor.DrawingDocument oDrawDoc = (Inventor.DrawingDocument)mInvApplication.ActiveDocument;

            //Set a reference to the active sheet.
            Inventor.Sheet oSheet = (Inventor.Sheet)oDrawDoc.ActiveSheet;

            Inventor.DrawingView oDrawingView = default(Inventor.DrawingView);
            // Check to make sure a drawing view is selected.
            try
            {
                // Set a reference to the selected drawing. This assumes
                // that the selected view is not a draft view.
                oDrawingView = (Inventor.DrawingView)oDrawDoc.SelectSet[1];
            }
            catch
            {
                //MessageBox.Show("A drawing view must be selected.");
                return;
            }


            // Set a reference to the center of the base view.
            Inventor.Point2d oPoint = (Inventor.Point2d)oDrawingView.Center;

            // Translate point by a distance = 2 * width of the view
            // This will be the placement point of the detail view.
            oPoint.X = oPoint.X + 2 * oDrawingView.Width;

            // Set corner one of rectangular fence as
            // the left-bottom corner of the base view.
            Inventor.Point2d oCornerOne = (Inventor.Point2d)oDrawingView.Center;


            oCornerOne.X = oCornerOne.X - oDrawingView.Width / 2;
            oCornerOne.Y = oCornerOne.Y - oDrawingView.Height / 2;

            // Set corner two of rectangular fence as
            // the center of the base view.
            Inventor.Point2d oCornerTwo = (Inventor.Point2d)oDrawingView.Center;

            // Get any linear curve from the base view
            Inventor.DrawingCurve oCurveToUse = null;
            foreach (Inventor.DrawingCurve oCurve in oDrawingView.DrawingCurves)
            {
                if (oCurve.CurveType == Inventor.CurveTypeEnum.kLineSegmentCurve)
                {
                    oCurveToUse = oCurve;
                    break;
                }
            }

            // Create an intent object
            Inventor.GeometryIntent oAttachPoint = (Inventor.GeometryIntent)oSheet.
                                                   CreateGeometryIntent(oCurveToUse, Inventor.PointIntentEnum.kStartPointIntent);

            // Create the detail view
            Inventor.DetailDrawingView oDetailView = (Inventor.DetailDrawingView)oSheet.DrawingViews.
                                                     AddDetailView(oDrawingView, oPoint, Inventor.DrawingViewStyleEnum.kFromBaseDrawingViewStyle,
                                                                   false, oCornerOne, oCornerTwo, oAttachPoint, 2);
        }