private void AddPartNameNote(DrawingView drawingView)
        {
            var partName = drawingView.ReferencedDocumentDescriptor.DisplayName.RemoveExtension();
            var rowItemNumber = GetRowItemNumber(partName);

            if (string.IsNullOrEmpty(rowItemNumber) == false)
                partName = $"{rowItemNumber} : {partName}";

            drawingView.AddPartName(partName, drawingDistance: 0.5);
        }
        //////////////////////////////////////////////////////////////////////////////////////
        // Use: AdnGraphicsData constructor for DrawingView graphics 
        //
        //////////////////////////////////////////////////////////////////////////////////////
        public AdnGraphics(DrawingView view, string clientId, bool transacting)
        {
            _clientId = clientId + (transacting ? "-Tx" : "-NonTx");

            _graphicsData = null;
            _graphics = null;

            try
            {
                _graphicsData = view.GraphicsDataSetsCollection[_clientId];
            }
            catch
            {          
                if (transacting)
                {
                    _graphicsData = view.GraphicsDataSetsCollection.Add(_clientId);
                }
                else
                {
                    _graphicsData = view.GraphicsDataSetsCollection.AddNonTransacting(_clientId);
                }
            }

            try
            {
                _graphics = view.ClientGraphicsCollection[_clientId];
            }
            catch
            {
                if (transacting)
                {
                    _graphics = view.ClientGraphicsCollection.Add(_clientId);
                }
                else
                {
                    _graphics = view.ClientGraphicsCollection.AddNonTransacting(_clientId);
                }
            }
        }
        public void DeleteGraphics(DrawingView drawingView, bool deleteData)
        {
            AdnGraphics dataTx = new AdnGraphics(drawingView, _clientId, true);
            dataTx.Delete(deleteData);

            AdnGraphics dataNonTx = new AdnGraphics(drawingView, _clientId, false);
            dataNonTx.Delete(deleteData);
        }
        public void SetGraphicsSource(DrawingView drawingView)
        {
            _workingView = drawingView;

            _mode = AdnGraphicModeEnum.kDrawingViewGraphics;
        }
        public void SetGraphicsSource(DrawingView drawingView)
        {
            _workingView = drawingView;

            _mode = AdnGraphicModeEnum.kDrawingViewGraphics;
        }
Пример #6
0
 /// <summary>
 /// Raises the <see cref="DrawingView"/> event.
 /// </summary>
 /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param>
 /// <param name="spriteBatch">The <see cref="SpriteBatch"/> with which the panel is being drawn.</param>
 protected virtual void OnDrawingView(UltravioletTime time, SpriteBatch spriteBatch) =>
 DrawingView?.Invoke(this, time, spriteBatch);
Пример #7
0
        private void DrawPartDoc(string filename)
        {
            DrawingDocument oDoc;
            Sheet           oSheet;

            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            SetupNewDrawingDocument(out oDoc, out oSheet);
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //Open the part document, invisibly.
            PartDocument      oBlockPart = mApp.Documents.Open(filename, false) as PartDocument;
            TransientGeometry oTG        = mApp.TransientGeometry;

            //0.1 = 1:10 or 0.2 = 1:5 1:20=0.02   X-> Y ^
            DrawingView oBaseView = oSheet.DrawingViews.AddBaseView(oBlockPart as _Document,
                                                                    oTG.CreatePoint2d(28.7, 21), 0.1,
                                                                    ViewOrientationTypeEnum.kFrontViewOrientation,
                                                                    DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "", null, null);
            //59.4 x 42.0   29.7 X 21.0
            DrawingView oTopView = oSheet.DrawingViews.AddProjectedView(oBaseView,
                                                                        oTG.CreatePoint2d(28.7, 29),
                                                                        DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null);

            //Projected views
            DrawingView oRightView = oSheet.DrawingViews.AddProjectedView(oBaseView,
                                                                          oTG.CreatePoint2d(45, 21),
                                                                          DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null);

            //look through the curves in view finds top horiz curve. Find an edge
            oSheet.RevisionTables.Add(oTG.CreatePoint2d(48.4, 23.5));      //1mm div 10//1 row = 4

            DrawingCurve oSelectedCurve = null;

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

            //set up Dim
            GeneralDimensions oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions;

            //Styles sty = oDoc.StylesManager.Styles   ;
            // DimensionStyle dimstyle = oDoc.StylesManager.DimensionStyles["Drax Dim Above"];
            //MessageBox.Show(cmbDimStyles.Text);
            DimensionStyle dimstyle = oDoc.StylesManager.DimensionStyles[cmbDimStyles.Text];

            //Set Layer
            //Layer layer = oDoc.StylesManager.Layers["D"];
            //MessageBox.Show(cmbLayers.Text);
            Layer layer = oDoc.StylesManager.Layers[cmbLayers.Text];

            //Create the dimension.
            LinearGeneralDimension oLinearDim;

            oLinearDim = oGeneralDimensions.AddLinear(oDimPos, oGeomIntent1, oGeomIntent2,
                                                      DimensionTypeEnum.kAlignedDimensionType, true,
                                                      dimstyle,
                                                      layer);


            string newfilename;
            string swapfilename;

            newfilename  = "";
            swapfilename = "";
            //Build New Filname
            Inventor.PropertySet InvPropertySet = oBlockPart.PropertySets["{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"];
            swapfilename = oBlockPart.FullFileName.Substring(0, oBlockPart.FullFileName.LastIndexOf("\\") + 1);
            //MessageBox.Show(swapfilename);
            newfilename = swapfilename + InvPropertySet["FULLFILENAME"].Value + ".idw";
            oBlockPart.Close(true);
            oDoc.SaveAs(newfilename, true);
            oDoc.Close(true);
        }
Пример #8
0
        private void Button3_Click(object sender, EventArgs e)
        {
            //Create a new drawing document.
            DrawingDocument oDoc = mApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,
                                                      mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject,
                                                                                       SystemOfMeasureEnum.kDefaultSystemOfMeasure,
                                                                                       DraftingStandardEnum.kDefault_DraftingStandard,
                                                                                       null),
                                                      true) as DrawingDocument;

            //Create a new B size sheet.
            Sheet oSheet = oDoc.Sheets.Add(DrawingSheetSizeEnum.kBDrawingSheetSize,
                                           PageOrientationTypeEnum.kDefaultPageOrientation,
                                           "A Size", 0, 0);

            //Add the default border.
            oSheet.AddDefaultBorder(null, null, null, null, null, null, null, null, null, null, null, null, null, null);

            //Add ANSI A TitleBlock
            TitleBlock oTitleBlock = oSheet.AddTitleBlock(oDoc.TitleBlockDefinitions["ANSI A"], null, null);

            //Open the part document, invisibly.
            PartDocument oBlockPart = mApp.Documents.Open(@"C:\Temp\TestPart.ipt", false) as PartDocument;

            TransientGeometry oTG = mApp.TransientGeometry;

            //Create base drawing view
            DrawingView oBaseView = oSheet.DrawingViews.AddBaseView(oBlockPart as _Document,
                                                                    oTG.CreatePoint2d(10, 10), 1,
                                                                    ViewOrientationTypeEnum.kFrontViewOrientation,
                                                                    DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, "", null, null);

            //Create Projected views
            DrawingView oRightView = oSheet.DrawingViews.AddProjectedView(oBaseView,
                                                                          oTG.CreatePoint2d(20, 18),
                                                                          DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null);

            DrawingView oIsoView = oSheet.DrawingViews.AddProjectedView(oBaseView,
                                                                        oTG.CreatePoint2d(10, 20),
                                                                        DrawingViewStyleEnum.kFromBaseDrawingViewStyle, null);


            //Find an edge in the part to dimension.  Any method can be used, (attributes, B-Rep query, selection, etc.).  This
            //looks through the curves in the drawing view and finds the top horizontal curve.

            DrawingCurve oSelectedCurve = null;

            foreach (DrawingCurve oCurve in oBaseView.get_DrawingCurves(null))
            {
                //Skip Circles
                if (oCurve.StartPoint != null && oCurve.EndPoint != null)
                {
                    if (WithinTol(oCurve.StartPoint.X, oCurve.EndPoint.X, 0.001))
                    {
                        if (oSelectedCurve == null)
                        {
                            //This is the first horizontal curve found.
                            oSelectedCurve = oCurve;
                        }
                        else
                        {
                            //Check to see if this curve is higher (smaller x value) than the current selected
                            if (oCurve.MidPoint.X < oSelectedCurve.MidPoint.X)
                            {
                                oSelectedCurve = oCurve;
                            }
                        }
                    }
                }
            }

            if (oSelectedCurve == null)
            {
                System.Windows.Forms.MessageBox.Show("no curve is selected!");
                return;
            }
            //Create geometry intents point for the curve.
            GeometryIntent oGeomIntent1 = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kStartPointIntent);
            GeometryIntent oGeomIntent2 = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kEndPointIntent);

            GeneralDimensions oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions;

            Point2d oDimPos = oTG.CreatePoint2d(oSelectedCurve.MidPoint.X - 2, oSelectedCurve.MidPoint.Y);

            DimensionStyle dimstyle = oDoc.StylesManager.DimensionStyles["Default (ANSI)"];

            Layer layer = oDoc.StylesManager.Layers["Dimension (ANSI)"];

            //Create the dimension.
            LinearGeneralDimension oLinearDim;

            oLinearDim = oGeneralDimensions.AddLinear(oDimPos, oGeomIntent1, oGeomIntent2,
                                                      DimensionTypeEnum.kAlignedDimensionType, true,
                                                      dimstyle,
                                                      layer);
        }
        void DrawImage(List <Line> lines)
        {
            var stream = DrawingView.GetImageStream(lines, new Size(GestureImage.Width, GestureImage.Height), Color.Gray);

            GestureImage.Source = ImageSource.FromStream(() => stream);
        }
Пример #10
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);
                }
                //*/
            }
        }
Пример #11
0
 /// <summary>
 /// Returns a list of sheet metal part documents that are referenced by the drawing view.
 /// </summary>
 /// <param name="drawingView">
 /// The <see cref="DrawingView"/> instance that this extension method affects.</param>
 /// <exception cref="ArgumentNullException"><paramref name="drawingView"/> is <c>null</c>.</exception>
 public static List <PartDocument> GetReferencedSheetMetalDocuments(this DrawingView drawingView)
 {
     return(drawingView.GetReferencedDocuments <PartDocument>().Where(x => x.IsSheetMetal()).ToList());
 }