Esempio n. 1
0
        /// <summary>
        ///  creation of a parts list. The parts list is placed at the
        ///  top right corner of the border if one exists, else it is placed
        ///  at the top right corner of the sheet.
        /// To run this sample, have a drawing document open.
        /// The active sheet in the drawing should have at least
        /// one drawing view and the first drawing view on the sheet
        /// should not be a draft view.
        /// </summary>
        /// <remarks></remarks>

        public void CreatePartsList()
        {
            // Set a reference to the drawing document.
            // This assumes a drawing document is active.
            DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument;

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

            // Set a reference to the first drawing view on
            // the sheet. This assumes the first drawing
            // view on the sheet is not a draft view.
            DrawingView oDrawingView = oSheet.DrawingViews[1];

            // Set a reference to th sheet's border
            Inventor.Border oBorder = oSheet.Border;

            Point2d oPlacementPoint = null;

            if ((oBorder != null))
            {
                // A border exists. The placement point
                // is the top-right corner of the border.
                oPlacementPoint = oBorder.RangeBox.MaxPoint;
            }
            else
            {
                // There is no border. The placement point
                // is the top-right corner of the sheet.
                oPlacementPoint = _InvApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.Height);
            }

            // Create the parts list.
            PartsList oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint);
        }
Esempio n. 2
0
        /// <summary>
        ///  creation of hole tables in a drawing.
        /// Select a drawing view that contains holes and run the following sample
        /// </summary>
        /// <remarks></remarks>
        public void CreateHoleTables()
        {
            // Set a reference to the drawing document.
            // This assumes a drawing document is active.
            DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument;

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

            // Set a reference to the drawing view.
            // This assumes that a drawing view is selected.
            DrawingView oDrawingView = oDrawDoc.SelectSet[1];

            // Create origin indicator if it has not been already created.
            if (!oDrawingView.HasOriginIndicator)
            {
                // Create point intent to anchor the origin to.
                GeometryIntent oDimIntent   = null;
                Point2d        oPointIntent = null;

                // Get the first curve on the view
                DrawingCurve oCurve = oDrawingView.get_DrawingCurves()[1];

                // Check if it has a strt point
                oPointIntent = oCurve.StartPoint;

                if (oPointIntent == null)
                {
                    // Else use the center point
                    oPointIntent = oCurve.CenterPoint;
                }

                oDimIntent = oActiveSheet.CreateGeometryIntent(oCurve, oPointIntent);

                oDrawingView.CreateOriginIndicator(oDimIntent);
            }

            Point2d oPlacementPoint = null;

            // Set a reference to th sheet's border
            Inventor.Border oBorder = oActiveSheet.Border;

            if ((oBorder != null))
            {
                // A border exists. The placement point
                // is the top-left corner of the border.
                oPlacementPoint = _InvApplication.TransientGeometry.CreatePoint2d(oBorder.RangeBox.MinPoint.X, oBorder.RangeBox.MaxPoint.Y);
            }
            else
            {
                // There is no border. The placement point
                // is the top-left corner of the sheet.
                oPlacementPoint = _InvApplication.TransientGeometry.CreatePoint2d(0, oActiveSheet.Height);
            }

            // Create a 'view' hole table
            // This hole table includes all holes as specified by the active hole table style
            HoleTable oViewHoleTable = default(HoleTable);

            oViewHoleTable = oActiveSheet.HoleTables.Add(oDrawingView, oPlacementPoint);

            oPlacementPoint.X = oActiveSheet.Width / 2;

            // Create a 'feature type' hole table
            // This hole table includes specified hole types only
            HoleTable oFeatureHoleTable = oActiveSheet.HoleTables.AddByFeatureType(oDrawingView, oPlacementPoint, true, true, true, true, false, false, false);

            //add a new row

            // get the model document
            Document oModelDoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument;

            HoleFeature oHoleF = null;

            if (oModelDoc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
            {
                AssemblyDocument            oRefAssDoc = (AssemblyDocument)oModelDoc;
                AssemblyComponentDefinition oAssDef    = oRefAssDoc.ComponentDefinition;

                if (oAssDef.Features.HoleFeatures.Count > 0)
                {
                    //as a demo: get the first hole feature
                    oHoleF = oAssDef.Features.HoleFeatures[1];
                }
            }
            else if (oModelDoc.DocumentType == DocumentTypeEnum.kPartDocumentObject)
            {
                PartDocument            oRefPartDoc = (PartDocument)oModelDoc;
                PartComponentDefinition oPartDef    = oRefPartDoc.ComponentDefinition;

                if (oPartDef.Features.HoleFeatures.Count > 0)
                {
                    //as a demo: get the first hole feature
                    oHoleF = oPartDef.Features.HoleFeatures[1];
                }
            }


            // add a new row to the hole table
            if ((oHoleF != null))
            {
                DrawingCurvesEnumerator oHoleCurves = oDrawingView.get_DrawingCurves(oHoleF);
                if (oHoleCurves.Count > 0)
                {
                    oFeatureHoleTable.HoleTableRows.Add(oHoleCurves[1]);
                }
            }
        }