コード例 #1
0
        //    Create flat pattern drawing view API Sample
        //Description
        //This sample demonstrates the creation of a flat pattern base view in a drawing.
        //Open a drawing document and run the sample.
        public void AddFlatPatternDrawingView()
        {
            // 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;

            // Create a new NameValueMap object
            Inventor.NameValueMap oBaseViewOptions = (Inventor.NameValueMap)mInvApplication.TransientObjects.CreateNameValueMap();

            // Set the options to use when creating the base view.
            oBaseViewOptions.Add("SheetMetalFoldedModel", false);

            // Open the sheet metal document invisibly
            Inventor._Document oModel = (Inventor._Document)mInvApplication.Documents.Open(@"C:\temp\SheetMetal.ipt", false);

            // Create the placement point object.
            Inventor.Point2d oPoint = default(Inventor.Point2d);
            oPoint = mInvApplication.TransientGeometry.CreatePoint2d(25, 25);

            // Create a base view.
            Inventor.DrawingView oBaseView = (Inventor.DrawingView)oSheet.DrawingViews
                                             .AddBaseView(oModel, oPoint, 1, Inventor.ViewOrientationTypeEnum.kDefaultViewOrientation,
                                                          Inventor.DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, "", Type.Missing, oBaseViewOptions);

            // Release reference of the invisibly open model
            oModel.ReleaseReference();
        }
コード例 #2
0
        private static void SetViewScale(Inventor.Sheet CurrentSheet, ref Inventor.DrawingView DrawingView)
        {
            double DrawingTitelBlockHeight = 5;

            if (CurrentSheet.Size == Inventor.DrawingSheetSizeEnum.kA4DrawingSheetSize)
            {
                DrawingTitelBlockHeight = 5;
            }
            else if (CurrentSheet.Size == Inventor.DrawingSheetSizeEnum.kA3DrawingSheetSize)
            {
                DrawingTitelBlockHeight = 5;
            }
            double TargetViewGapWidth  = 2;
            double TargetViewGapHeight = 3;

            double TargetViewWidth  = CurrentSheet.Width - (2 * TargetViewGapWidth);
            double TargetViewHeight = CurrentSheet.Height - ((2 * TargetViewGapHeight) + DrawingTitelBlockHeight);

            double SheetWidth  = CurrentSheet.Width;
            double SheetHeight = CurrentSheet.Height;

            double[] ViewCenter = new double[2];

            string[]  DrawingScales;
            dynamic[] DynamScales;
            Inventor.DrawingDocument      DrawingDocument      = (Inventor.DrawingDocument)CurrentSheet.Parent;
            Inventor.DrawingStandardStyle DrawingStandardStyle = DrawingDocument.StylesManager.ActiveStandardStyle;

            DynamScales = DrawingStandardStyle.PresetScales;

            DrawingScales = new string[DynamScales.Length];

            DrawingScales = DrawingStandardStyle.PresetScales;
            DynamScales   = null;

            foreach (string ScaleString in DrawingScales)
            {
                double ScalingValue = 1;
                double ScalerValue  = 1;
                double Scale        = 0;
                if (ScaleString != null)
                {
                    int Delimitor = ScaleString.IndexOf(":");
                    ScalingValue = Convert.ToDouble(ScaleString.Substring(0, Delimitor));
                    ScalerValue  = Convert.ToDouble(ScaleString.Substring(Delimitor + 1, ScaleString.Length - (Delimitor + 1)));
                }
                Scale = ScalingValue / ScalerValue;
            }

            for (int i = 0; i < 50; i++)
            {
                DrawingView.Scale = TargetViewWidth / DrawingView.Width * DrawingView.Scale;
                if (DrawingView.Height > TargetViewHeight)
                {
                    DrawingView.Scale = TargetViewHeight / DrawingView.Height * DrawingView.Scale;
                }
            }
        }
コード例 #3
0
        private static Inventor.DrawingView AddDocumentBaseView(Inventor._Document Document, Inventor.Sheet Sheet, Inventor.TransientGeometry TransientGeometry, Inventor.NameValueMap BaseViewOptions)
        {
            double ViewWidth = 17;

            Inventor.DrawingView DrawingView = Sheet.DrawingViews.AddBaseView(Document as Inventor._Document, GetDrawingCenterPoint(Sheet, TransientGeometry), 0.2, Inventor.ViewOrientationTypeEnum.kDefaultViewOrientation, Inventor.DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, "", null, BaseViewOptions);

            DrawingView.Scale = ViewWidth / DrawingView.Width * DrawingView.Scale;

            return(DrawingView);
        }
コード例 #4
0
        private static Inventor.DrawingView AddDocumentBaseView(Inventor._Document Document, Inventor.Sheet Sheet, Inventor.TransientGeometry TransientGeometry, Inventor.Camera Camera)
        {
            double ViewWidth = 17;

            Inventor.DrawingView DrawingView = Sheet.DrawingViews.AddBaseView(Document as Inventor._Document, GetDrawingCenterPoint(Sheet, TransientGeometry), 0.2, Inventor.ViewOrientationTypeEnum.kArbitraryViewOrientation, Inventor.DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, "", Camera, null);

            DrawingView.Scale = ViewWidth / DrawingView.Width * DrawingView.Scale;

            SetViewScale(Sheet, ref DrawingView);

            return(DrawingView);
        }
コード例 #5
0
        //    Adding Representation views API Sample
        //Description
        //This sample demonstrates how to create a base view by specifying various representations.
        //Before running this sample, make sure that the file
        // C:\TempReps.iam exists (or change the path in the sample).
        //     The file must contain a level of detail representation named MyLODRep,
        //     a positional representation named MyPositionalRep and a design view representation named MyDesignViewRep.
        public void AddBaseViewWithRepresentations()
        {
            // 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;

            // Create a new NameValueMap object
            Inventor.NameValueMap oBaseViewOptions = (Inventor.NameValueMap)mInvApplication.TransientObjects.CreateNameValueMap();

            // Set the representations to use when creating the base view.
            oBaseViewOptions.Add("PositionalRepresentation", "MyPositionalRep");
            oBaseViewOptions.Add("DesignViewRepresentation", "MyDesignViewRep");
            oBaseViewOptions.Add("DesignViewAssociative", true);

            // Open the model document (corresponding to the "MyLODRep" representation).
            string strFullDocumentName = null;

            strFullDocumentName = mInvApplication.FileManager.GetFullDocumentName(@"C:\tempreps.iam", "MyLODRep");

            Inventor._Document oModel = (Inventor._Document)mInvApplication.Documents.Open(strFullDocumentName, false);

            // Create the placement point object.
            Inventor.Point2d oPoint = default(Inventor.Point2d);
            oPoint = mInvApplication.TransientGeometry.CreatePoint2d(25, 25);

            // Create a base view.
            Inventor.DrawingView oBaseView = (Inventor.DrawingView)oSheet.DrawingViews.
                                             AddBaseView(oModel, oPoint, 2, Inventor.ViewOrientationTypeEnum.kIsoTopLeftViewOrientation,
                                                         Inventor.DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, "", Type.Missing, oBaseViewOptions);

            // Release reference of the invisibly open model
            oModel.ReleaseReference();
        }
コード例 #6
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);
        }
コード例 #7
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);
        }