Example #1
0
        /// <summary>
        ///  creating leader text on a sheet.
        /// Before running this sample, open a drawing document and select a linear drawing edge.
        /// </summary>
        /// <remarks></remarks>
        public void AddLeaderNote()
        {
            // 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 curve segment.
            // This assumes that a drawing curve is selected.
            DrawingCurveSegment oDrawingCurveSegment = oDrawDoc.SelectSet[1];

            // Set a reference to the drawing curve.
            DrawingCurve oDrawingCurve = oDrawingCurveSegment.Parent;

            // Get the mid point of the selected curve
            // assuming that the selected curve is linear
            Point2d oMidPoint = oDrawingCurve.MidPoint;

            // Set a reference to the TransientGeometry object.
            TransientGeometry oTG = _InvApplication.TransientGeometry;

            ObjectCollection oLeaderPoints = _InvApplication.TransientObjects.CreateObjectCollection();

            // Create a few leader points.
            oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 10));
            oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 5));

            // Create an intent and add to the leader points collection.
            // This is the geometry that the leader text will attach to.
            GeometryIntent oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve);

            oLeaderPoints.Add(oGeometryIntent);

            // Create text with simple string as input. Since this doesn't use
            // any text overrides, it will default to the active text style.
            string sText = null;

            sText = "API Leader Note";

            LeaderNote oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText);

            // Insert a node.
            LeaderNode oFirstNode = oLeaderNote.Leader.RootNode.ChildNodes[1];

            LeaderNode oSecondNode = oFirstNode.ChildNodes[1];

            oFirstNode.InsertNode(oSecondNode, oTG.CreatePoint2d(oMidPoint.X + 5, oMidPoint.Y + 5));
        }
Example #2
0
        private GeometryIntent attach(Point2d ptPoz)
        {
            ObjectsEnumerator obj = sh.FindUsingPoint(ptPoz);

            if (obj.Count != 0)
            {
                if (obj[1] is DrawingCurveSegment)
                {
                    DrawingCurveSegment dcs = obj[1] as DrawingCurveSegment;
                    GeometryIntent      gi  = sh.CreateGeometryIntent(dcs.Parent, ptPoz);
                    return(gi);
                }
            }
            return(null);
        }
Example #3
0
        /// <summary>
        /// creation of a balloon. Select a linear drawing curve and run the sample
        /// </summary>
        /// <remarks></remarks>
        public void CreateBalloon()
        {
            // 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 curve segment.
            // This assumes that a drwaing curve is selected.
            DrawingCurveSegment oDrawingCurveSegment = oDrawDoc.SelectSet[1];

            // Set a reference to the drawing curve.
            DrawingCurve oDrawingCurve = oDrawingCurveSegment.Parent;

            // Get the mid point of the selected curve
            // assuming that the selection curve is linear
            Point2d oMidPoint = oDrawingCurve.MidPoint;

            // Set a reference to the TransientGeometry object.
            TransientGeometry oTG = _InvApplication.TransientGeometry;

            ObjectCollection oLeaderPoints = _InvApplication.TransientObjects.CreateObjectCollection();

            // Create a couple of leader points.
            oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 10));
            oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 5));

            // Add the GeometryIntent to the leader points collection.
            // This is the geometry that the balloon will attach to.
            GeometryIntent oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve);

            oLeaderPoints.Add(oGeometryIntent);

            // Set a reference to the parent drawing view of the selected curve
            DrawingView oDrawingView = oDrawingCurve.Parent;

            // Set a reference to the referenced model document
            Document oModelDoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument;

            // Check if a partslist or a balloon has already been created for this model
            bool IsDrawingBOMDefined = false;

            IsDrawingBOMDefined = oDrawDoc.DrawingBOMs.IsDrawingBOMDefined(oModelDoc.FullFileName);

            Balloon oBalloon = null;


            if (IsDrawingBOMDefined)
            {
                // Just create the balloon with the leader points
                // All other arguments can be ignored
                oBalloon = oDrawDoc.ActiveSheet.Balloons.Add(oLeaderPoints);
            }
            else
            {
                // First check if the 'structured' BOM view has been enabled in the model

                // Set a reference to the model's BOM object
                AssemblyDocument            oAssDoc = (AssemblyDocument)oModelDoc;
                AssemblyComponentDefinition oComDef = oAssDoc.ComponentDefinition;
                BOM oBOM = oComDef.BOM;


                if (oBOM.StructuredViewEnabled)
                {
                    // Level needs to be specified
                    // Numbering options have already been defined
                    // Get the Level ('All levels' or 'First level only')
                    // from the model BOM view - must use the same here
                    PartsListLevelEnum Level = default(PartsListLevelEnum);
                    if (oBOM.StructuredViewFirstLevelOnly)
                    {
                        Level = PartsListLevelEnum.kStructured;
                    }
                    else
                    {
                        Level = PartsListLevelEnum.kStructuredAllLevels;
                    }

                    // Create the balloon by specifying just the level
                    oBalloon = oActiveSheet.Balloons.Add(oLeaderPoints, null, Level);
                }
                else
                {
                    // Level and numbering options must be specified
                    // The corresponding model BOM view will automatically be enabled
                    NameValueMap oNumberingScheme = _InvApplication.TransientObjects.CreateNameValueMap();

                    // Add the option for a comma delimiter
                    oNumberingScheme.Add("Delimiter", ",");

                    // Create the balloon by specifying the level and numbering scheme
                    oBalloon = oActiveSheet.Balloons.Add(oLeaderPoints, null, PartsListLevelEnum.kStructuredAllLevels, oNumberingScheme);
                }
            }
        }
Example #4
0
        private static void wip_kDrawingCurveSegmentObject()
        {
            Inventor.Application oApp  = ApplicationShim.CurrentInstance();
            SelectSet            oSSet = oApp.ActiveDocument.SelectSet;

            if (oSSet.Count == 0)
            {
                return;
            }

            Inventor.Document returnDocument = null;

            dynamic obj = oSSet[2];

            switch (obj.type)
            {
            case 117478144:     //kDrawingCurveSegmentObject
                                //try to set the drawing curve object to point at the containingOccurrence object.
                                //Edge Objects and Edge Proxy Objects

                DrawingCurveSegment drawingCurveSegment = (DrawingCurveSegment)obj;
                DrawingCurve        drawingCurve        = drawingCurveSegment.Parent;


                dynamic modelGeometry;
                try
                {
                    modelGeometry = drawingCurve.ModelGeometry;
                }
                catch
                {
                    Console.WriteLine("Are you sure the object can be found?  The ModelGeometry cannot be located. exiting...");
                    Console.ReadLine();
                    return;
                }

                ComponentOccurrence componentOccurrence;

                try     //for a selected DrawingCurveSegment belonging to an assembly component
                {
                    componentOccurrence = modelGeometry.ContainingOccurrence;
                    returnDocument      = (Document)componentOccurrence.Definition.Document;
                    break;
                }
                catch { }

                try     //for a selected DrawingCurveSegment belonging to a part
                {
                    returnDocument = (Document)modelGeometry.Parent.ComponentDefinition.Document;
                    break;
                }
                catch { }
                break;
            }

            if (returnDocument == null)
            {
                Console.WriteLine("The document could not be found!");
            }
            else
            {
                Console.WriteLine("Document Type: " + returnDocument.DocumentSubType);
                Console.WriteLine(returnDocument.FullFileName);
            }

            Console.ReadLine();
        }
Example #5
0
        /// <summary>
        /// Tries to get an Inventor.Document object from a supplied object within a drawing.
        /// If one is found it will be returned; if not, null is returned.
        /// </summary>
        /// <param name="obj">Object</param>
        /// <param name="document">Inventor.DrawingDocument</param>
        /// <returns></returns>
        private static Document GetDocumentFromObjectInDrawing(dynamic obj, DrawingDocument document)
        {
            Document returnDocument = null;

            switch (obj.type)
            {
            //Drawing View, Section View, Detail View
            case 117441536:     //kDrawingViewObject:
            case 117463296:     //kSectionDrawingViewObject
            case 117474304:     //kDetailDrawingViewObject
                return(obj.ReferencedFile.ReferencedDocument);

            case 2130706445:     //kGenericObject:
                dynamic returnObject = null;
                try {
                    //try to get single document from selected part
                    document.ProcessViewSelection((GenericObject)obj, out _, out returnObject);
                } catch { break; }

                if (returnObject == null)
                {
                    break;
                }

                switch (returnObject)
                {
                case Document doc:
                    returnDocument = doc;
                    break;

                case ComponentOccurrence componentOccurrence:
                    //if this doesn't work, try to get the component occurrence instead, and then get the document from that
                    returnDocument = (Document)componentOccurrence.Definition.Document;
                    break;
                }
                break;
            //There was an error at 'Set oCCdef = oCompOcc.Definition.Document'

            case 117478144:     //kDrawingCurveSegmentObject
                //Edge Objects and Edge Proxy Objects
                DrawingCurveSegment drawingCurveSegment = (DrawingCurveSegment)obj;
                DrawingCurve        drawingCurve        = drawingCurveSegment.Parent;

                //get the modelGeometry, if it cannot be accessed, the file is likely unreferenced...
                dynamic modelGeometry = null;
                try { modelGeometry = drawingCurve.ModelGeometry; }
                catch
                {
                    returnDocument = null;
                    break;
                }

                try     //for a selected DrawingCurveSegment belonging to an assembly component
                {
                    returnDocument = (Document)modelGeometry.ContainingOccurrence.Definition.Document;
                    break;
                } catch { }

                try     //for a selected DrawingCurveSegment belonging to a part
                {
                    returnDocument = (Document)modelGeometry.Parent.ComponentDefinition.Document;
                    break;
                } catch { }
                break;

            case 117444096:     //kPartsListObject:
                returnDocument = obj.ReferencedFile.ReferencedDocument;
                break;

            case 117445120:     //kPartsListRowObject:
                returnDocument = obj.ReferencedFiles.Item(1).ReferencedDocument;
                break;

            case 100674816:     //kBOMRowObject:
                returnDocument = obj.ComponentDefinitions(1).Document;
                break;

            default:
                return(null);
            }

            return(returnDocument ?? null);
        }
        /// <summary>
        /// TODO Implement
        /// </summary>
        /// <param name="curveSegment"></param>
        public InventorDrawingCurve(DrawingCurveSegment curveSegment)
        {
            _curve = curveSegment.Parent;

            FindOccurence(_curve.ModelGeometry);
        }
Example #7
0
        private static void GetDrawingDimension()
        {
            try
            {
                inventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
                Console.WriteLine("查找到可用的实例");
            }
            catch { Console.WriteLine("未打开Inventor"); return; }
            DrawingDocument drawingDocument = (DrawingDocument)inventorApp.ActiveDocument;

            //在Inventor当前正在显示的工程图不一样的时候,ActiveSheet也会发生变化
            Console.WriteLine("打开的图纸:" + drawingDocument.ActiveSheet.Name + " " + drawingDocument.FullFileName);
            DrawingView drawingView = drawingDocument.ActiveSheet.DrawingViews[1];

            //特别注明:该类及其方法仅针对模型和草图文件
            GeneralDimensionsEnumerator generalDimensionsEnumerator =
                drawingDocument.ActiveSheet.DrawingDimensions.GeneralDimensions.Retrieve(drawingView);

            Console.WriteLine("generalDimensionsEnumerator.Count = " + generalDimensionsEnumerator.Count);
            if (generalDimensionsEnumerator.Count != 0)
            {
                for (int i = 1; i <= generalDimensionsEnumerator.Count; i++)
                {
                    Console.WriteLine(generalDimensionsEnumerator[i].Text);
                }
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            BaselineDimensionSets baselineDimensionSets = drawingDocument.ActiveSheet.DrawingDimensions.BaselineDimensionSets;

            Console.WriteLine("baselineDimensionSets.Count = " + baselineDimensionSets.Count);
            if (baselineDimensionSets.Count != 0)
            {
                for (int i = 1; i <= baselineDimensionSets.Count; i++)
                {
                    BaselineDimensionSet baselineDimensionSet = baselineDimensionSets[i];
                    Console.WriteLine("baselineDimensionSet.Members = " + baselineDimensionSet.Members);
                    Console.WriteLine("baselineDimensionSet.DimensionType" + baselineDimensionSet.DimensionType);
                }
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            Balloons ballons = drawingDocument.ActiveSheet.Balloons;

            Console.WriteLine("ballons.Count = " + ballons.Count);
            Balloon balloon = null;

            if (ballons.Count != 0)
            {
                for (int i = 1; i <= ballons.Count; i++)
                {
                    Console.WriteLine("\n------------------------ballons[" + i + "]------------------------");
                    balloon = ballons[i];
                    //Console.WriteLine("balloon.Leader.RootNode = " + balloon.Leader.RootNode);  //打印出 System.__ComObject
                    //Console.WriteLine("balloon.Position = " + balloon.Position);  //打印出 System.__ComObject
                    AttributeSets attributeSets = balloon.AttributeSets;
                    Console.WriteLine("attributeSets.Count = " + attributeSets.Count);
                    for (int j = 1; j <= attributeSets.Count; j++)
                    {
                        AttributeSet attributeSet = attributeSets[j];
                        Console.WriteLine("attributeSet.Name = " + attributeSet.Name);
                    }

                    BalloonValueSets balloonValueSets = balloon.BalloonValueSets;
                    for (int j = 1; j <= balloonValueSets.Count; j++)
                    {
                        BalloonValueSet balloonValueSet = balloonValueSets[j];
                        Console.WriteLine("balloonValueSet.ItemNumber = " + balloonValueSet.ItemNumber);
                        Console.WriteLine("balloonValueSet.Value = " + balloonValueSet.Value);
                        Console.WriteLine("balloonValueSet.OverrideValue = " + balloonValueSet.OverrideValue);
                        //Console.WriteLine("balloonValueSet.ReferencedFiles = " + balloonValueSet.ReferencedFiles);
                        Console.WriteLine("balloonValueSet.Type = " + balloonValueSet.Type);
                    }

                    Leader leader = balloon.Leader;
                    Console.WriteLine("leader.ArrowheadType = " + leader.ArrowheadType);
                    Console.WriteLine("leader.Type = " + leader.Type);
                    AttributeSets attributeSets_leader = leader.AttributeSets;
                    Console.WriteLine("attributeSets_leader.Count = " + attributeSets_leader.Count);
                    for (int j = 0; j < attributeSets_leader.Count; j++)
                    {
                        AttributeSet attributeSet = attributeSets[j];
                        Console.WriteLine("attributeSet_leader.Name = " + attributeSet.Name);
                    }

                    Console.WriteLine("END------------------------ballons[" + i + "]------------------------\n");
                }
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            //DrawingViews views = drawingDocument.ActiveSheet.DrawingViews;
            //Console.WriteLine("views.count = " + views.Count);

            Console.WriteLine("drawingDocument.SelectSet.Count = " + drawingDocument.SelectSet.Count);
            SelectSet           selectSet           = null;
            DrawingCurveSegment drawingCurveSegment = null;

            if (drawingDocument.SelectSet.Count == 0)
            {
                Console.WriteLine("Select a drawing view");
                DrawingView view = inventorApp.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view");
                //selectSet = inventorApp.CommandManager.Pick(SelectionFilterEnum.kDrawingSheetFilter, "Select drawing sheet!");
                drawingCurveSegment = inventorApp.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select drawing segment filter");
            }
            else
            {
                selectSet = drawingDocument.SelectSet;
            }

            //DrawingCurveSegment drawingCurveSegment = selectSet[1];//drawingDocument.SelectSet[1];
            DrawingCurve drawingCurve = drawingCurveSegment.Parent;

            //Get the mid point of the selected curve assuming that the selection curve is linear
            Point2d MidPoint = drawingCurve.MidPoint;

            //Set a reference to the TransientGeometry object.
            TransientGeometry TG = inventorApp.TransientGeometry;

            Console.WriteLine("TG : " + (TG == null));
            ObjectCollection LeaderPoints = inventorApp.TransientObjects.CreateObjectCollection();

            Console.WriteLine("LeaderPoints : " + (LeaderPoints == null));

            LeaderPoints.Add(TG.CreatePoint2d(MidPoint.X + 10, MidPoint.Y + 10));
            LeaderPoints.Add(TG.CreatePoint2d(MidPoint.X + 10, MidPoint.Y + 5));

            //Add the GeometryIntent to the leader points collection.
            //This is the geometry that the balloon will attach to.
            GeometryIntent geometryIntent = drawingDocument.ActiveSheet.CreateGeometryIntent(drawingCurve);

            LeaderPoints.Add(geometryIntent);

            //Set a reference to the parent drawing view of the selected curve
            //DrawingView
            drawingView = drawingCurve.Parent;

            //Set a reference to the referenced model document
            Document ModelDoc = drawingView.ReferencedDocumentDescriptor.ReferencedDocument;

            Console.WriteLine(ModelDoc.Type);
            //PartDocument ModelDoc = drawingView.ReferencedDocumentDescriptor.ReferencedDocument;
            //AssemblyDocument ModelDoc = drawingView.ReferencedDocumentDescriptor.ReferencedDocument;

            //Check if a partslist or a balloon has already been created for thie model
            Boolean IsDrawingBOMDefined = drawingDocument.DrawingBOMs.IsDrawingBOMDefined(ModelDoc.FullFileName);

            // Balloon balloon;

            if (IsDrawingBOMDefined)

            {   //当DrawingBOM已经被定义了
                //Just create the balloon with the leader points. All other arguments can be ignored
                Console.WriteLine("当DrawingBOM已经被定义了\n创建气泡标注");
                balloon = drawingDocument.ActiveSheet.Balloons.Add(LeaderPoints);
            }
            else
            {
                //当DrawingBOM没有被定义
                AssemblyDocument            assemblyDocument            = (AssemblyDocument)ModelDoc;
                AssemblyComponentDefinition assemblyComponentDefinition = assemblyDocument.ComponentDefinition;

                ///*
                //First check if the 'structured' BOM view has been enabled in the model
                //Set a reference to the model's BOM object
                //BOM bom = ModelDoc.ComponentDefinition.BOM;
                BOM bom = assemblyComponentDefinition.BOM;

                if (bom.StructuredViewEnabled)
                {
                    //Level needs to be specifieed. Numbering options jave already been defined.
                    //Get the Level('All levels' of 'First level only') from the model BOM view - must use the same here
                    PartsListLevelEnum Level;
                    if (bom.StructuredViewFirstLevelOnly)
                    {
                        Level = PartsListLevelEnum.kStructured;
                    }
                    else
                    {
                        Level = PartsListLevelEnum.kStructuredAllLevels;
                    }
                }
                else
                {
                    //Level and numbering options must be specifieed.
                    //The corresponding model BOM view will automatically be enabled
                    NameValueMap NumberingScheme = inventorApp.TransientObjects.CreateNameValueMap();
                    //Add the option for a comma delimiter
                    NumberingScheme.Add("Delimeter", ",");
                    //Create the balloon by specifying the level and numbering scheme
                    balloon = drawingDocument.ActiveSheet.Balloons.Add(LeaderPoints, PartsListLevelEnum.kStructuredAllLevels, NumberingScheme);
                }
                //*/
            }
        }