示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        private void DrawDocument(Inventor._Document Document, string TypeOfPart)
        {
            Inventor.ViewOrientationTypeEnum Orientation = Inventor.ViewOrientationTypeEnum.kDefaultViewOrientation;
            Inventor.DrawingDocument         DrawingDocument;
            Inventor.Sheet Sheet;

            Inventor.DrawingView       DrawingView;
            Inventor.TransientGeometry oTG = mInvApplication.TransientGeometry;
            CreateDrawingDocument(out DrawingDocument, out Sheet);
            //Inventor.DrawingStandardStyle DrawingStandardStyle;
            //DrawingStandardStyle = DrawingDocument.StylesManager.ActiveStandardStyle;
            if (TypeOfPart == "SheetMetal")
            {
                Inventor.NameValueMap BaseViewOptions = (Inventor.NameValueMap)mInvApplication.TransientObjects.CreateNameValueMap();
                BaseViewOptions.Add("SheetMetalFoldedModel", false);
                DrawingView = AddDocumentBaseView(Document, Sheet, oTG, BaseViewOptions);
            }
            else if (TypeOfPart == "Plate")
            {
                CDrawingView    CView  = new CDrawingView();
                Inventor.Camera Camera = null;
                Camera      = CView.GetDocument(ref Document, ref mInvApplication);
                DrawingView = AddDocumentBaseView(Document, Sheet, oTG, Camera);
            }
            else
            {
                ViewOrientation(ref Orientation);
                DrawingView = AddDocumentBaseView(Document, Sheet, oTG, Orientation);
            }


            try
            {
                Inventor.DrawingCurve SelectedCurve = null;

                foreach (Inventor.DrawingCurve CurveLine in DrawingView.get_DrawingCurves(null))
                {
                    //Skip Circles
                    if (CurveLine.StartPoint != null && CurveLine.EndPoint != null)
                    {
                        if (WithinTol(CurveLine.StartPoint.Y, CurveLine.EndPoint.Y, 0.001))
                        {
                            if (SelectedCurve == null)
                            {
                                //This is the first horizontal curve found.
                                SelectedCurve = CurveLine;
                            }
                            else
                            {
                                //Check to see if this curve is higher (smaller x value) than the current selected
                                if (CurveLine.MidPoint.Y < SelectedCurve.MidPoint.X)
                                {
                                    SelectedCurve = CurveLine;
                                }
                            }
                        }
                    }
                }
                //Create geometry intents point for the curve.
                Inventor.GeometryIntent oGeomIntent1 = Sheet.CreateGeometryIntent(SelectedCurve, Inventor.PointIntentEnum.kStartPointIntent);
                Inventor.GeometryIntent oGeomIntent2 = Sheet.CreateGeometryIntent(SelectedCurve, Inventor.PointIntentEnum.kEndPointIntent);
                Inventor.Point2d        oDimPos      = oTG.CreatePoint2d(SelectedCurve.MidPoint.X - 2, SelectedCurve.MidPoint.Y);

                Inventor.GeneralDimensions      oGeneralDimensions = Sheet.DrawingDimensions.GeneralDimensions;
                Inventor.LinearGeneralDimension oLinearDim;
                oLinearDim = oGeneralDimensions.AddLinear(oDimPos, oGeomIntent1, oGeomIntent2, Inventor.DimensionTypeEnum.kAlignedDimensionType, true);
            }
            catch (Exception)
            {
            }
            mInvApplication.SilentOperation = true;
            string partURL       = Document.FullFileName;
            int    NameLength    = Document.FullFileName.Length;
            string partURLTrimed = partURL.Remove(NameLength - 4);

            //DrawingDocument.Save();
            DrawingDocument.SaveAs(partURLTrimed + ".idw", false);
            DrawingDocument.Close(true);
            Document.Close(false);
            mInvApplication.SilentOperation = false;


            //Sheet.RevisionTables.Add(oTG.CreatePoint2d(Sheet.Width, Sheet.Height));  //1mm div 10//1 row = 4
            //Inventor.DimensionStyle dimstyle = DrawingDocument.StylesManager.DimensionStyles[cmbDimStyles.Text];
            //Inventor.Layer layer = DrawingDocument.StylesManager.Layers[cmbLayers.Text];
        }