Esempio n. 1
0
        //-----------------------------------------------------------------------------
        //----------------- MoveCmd implement ----------------------------------------
        //-----------------------------------------------------------------------------
        public void InitializePreviewGraphics()
        {
            m_interactionEvents = m_inventorApplication.CommandManager.CreateInteractionEvents();

            InteractionGraphics interactionGraphics = m_interactionEvents.InteractionGraphics;

            ClientGraphics previewClientGraphics = interactionGraphics.PreviewClientGraphics;

            m_previewClientGraphicsNode = previewClientGraphics.AddNode(1);

            m_pointGraphics = m_previewClientGraphicsNode.AddPointGraphics();

            GraphicsDataSets graphicsDateSets = interactionGraphics.GraphicsDataSets;

            m_graphicsCoordinateSet = graphicsDateSets.CreateCoordinateSet(1);

            m_graphicsColorSet = graphicsDateSets.CreateColorSet(1);

            m_graphicsColorSet.Add(1, 255, 0, 0);

            m_graphicsColorIndexSet = graphicsDateSets.CreateIndexSet(1);

            m_pointGraphics.CoordinateSet = m_graphicsCoordinateSet;
            m_pointGraphics.BurnThrough   = true;
        }
Esempio n. 2
0
        /// <summary>
        /// When the appropriate rectangle button is clicked the button's OnExecute event handler
        /// calls this method to hook up the mouse click event which will wait for the user to select
        /// a point from which to start the drawing of the rectangle
        /// </summary>
        public virtual void StartRectangleInteraction()
        {
            _interactionEvents = _inventorApplication.CommandManager.CreateInteractionEvents();

            _rectangleInteractionGraphics = _interactionEvents.InteractionGraphics;
            _rectangleClientGraphics      = _rectangleInteractionGraphics.OverlayClientGraphics;
            _rectangleLineNode            = _rectangleClientGraphics.AddNode(1);
            _rectangleGraphicsDataSets    = _rectangleInteractionGraphics.GraphicsDataSets;
            _rectangleCoordSet            = _rectangleGraphicsDataSets.CreateCoordinateSet(1);
            _rectangleIndexSet            = _rectangleGraphicsDataSets.CreateIndexSet(1);

            _onTerminate_Delegate           = new InteractionEventsSink_OnTerminateEventHandler(StopInteraction);
            _interactionEvents.OnTerminate += _onTerminate_Delegate;

            _userInputEvents = _inventorApplication.CommandManager.UserInputEvents;
            _userInputEvents_OnContextMenuDelegate = new UserInputEventsSink_OnContextMenuEventHandler(UserInputEvents_OnContextMenu);
            _userInputEvents.OnContextMenu        += _userInputEvents_OnContextMenuDelegate;

            _mouseEvents = _interactionEvents.MouseEvents;
            _mouseEvents.PointInferenceEnabled = true;
            _onMouseClick_Delegate             = new MouseEventsSink_OnMouseClickEventHandler(OnMouseClick_CreateRectangle);
            _mouseEvents.OnMouseClick         += _onMouseClick_Delegate;

            _interactionEvents.StatusBarText = "Select a Point from which to start the rectangle";

            _interactionEvents.AllowCommandAliases = true;

            _interactionEvents.Start();
        }
Esempio n. 3
0
        private Box GetSceneBox()
        {
            if (null == mSceneBox)
            {
                PartDocument partDoc = mInventorApp.ActiveDocument as PartDocument;
                if (null != partDoc)
                {
                    ClientGraphics clientGraphics = null;
                    try
                    {
                        clientGraphics = partDoc.ComponentDefinition.ClientGraphicsCollection["rubikcubeid"];
                    }
                    catch (Exception)
                    {
                    }

                    if (null != clientGraphics)
                    {
                        mSceneBox = mInventorApp.TransientGeometry.CreateBox();
                        foreach (GraphicsNode node in clientGraphics)
                        {
                            mSceneBox.Extend(node.RangeBox.MinPoint);
                            mSceneBox.Extend(node.RangeBox.MaxPoint);
                        }
                    }
                }
            }

            return(mSceneBox);
        }
Esempio n. 4
0
        public void InitializePreviewGraphics()
        {
            m_interactionEvents = m_inventorApplication.CommandManager.CreateInteractionEvents();

            InteractionGraphics interactionGraphics = m_interactionEvents.InteractionGraphics;

            ClientGraphics previewClientGraphics = interactionGraphics.PreviewClientGraphics;

            m_previewClientGraphicsNode = previewClientGraphics.AddNode(1);

            m_triangleStripGraphics = m_previewClientGraphicsNode.AddTriangleStripGraphics();

            GraphicsDataSets graphicsDataSets = interactionGraphics.GraphicsDataSets;

            m_graphicsCoordinateSet = graphicsDataSets.CreateCoordinateSet(1);

            m_graphicsColorSet = graphicsDataSets.CreateColorSet(1);

            m_graphicsColorSet.Add(1, 100, 100, 200);
            m_graphicsColorSet.Add(2, 150, 150, 250);

            m_graphicsColorIndexSet = graphicsDataSets.CreateIndexSet(1);

            m_triangleStripGraphics.CoordinateSet = m_graphicsCoordinateSet;
            m_triangleStripGraphics.ColorSet      = m_graphicsColorSet;
            m_triangleStripGraphics.ColorIndexSet = m_graphicsColorIndexSet;

            m_triangleStripGraphics.ColorBinding = ColorBindingEnum.kPerItemColors;
            m_triangleStripGraphics.BurnThrough  = true;
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Displays PointGraphics with various RenderStyles
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void PointGraphicsRenderDemo()
        {
            PartDocument doc =
                AdnInventorUtilities.InvApplication.ActiveDocument
                as PartDocument;

            string clientId = "{Add-in Guid}";

            ClientGraphics   graphics = null;
            GraphicsDataSets dataSets = null;

            try
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId];
                dataSets = doc.GraphicsDataSetsCollection[clientId];
            }
            catch
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId);
                dataSets = doc.GraphicsDataSetsCollection.Add(clientId);
            }

            TransientGeometry Tg = AdnInventorUtilities.InvApplication.TransientGeometry;


            GraphicsNode node = graphics.AddNode(graphics.Count + 1);

            PointGraphics[] pointGraphics = new PointGraphics[4];

            pointGraphics[0] = node.AddPointGraphics();
            pointGraphics[1] = node.AddPointGraphics();
            pointGraphics[2] = node.AddPointGraphics();
            pointGraphics[3] = node.AddPointGraphics();

            pointGraphics[0].PointRenderStyle = PointRenderStyleEnum.kCirclePointStyle;
            pointGraphics[0].CoordinateSet    = dataSets.CreateCoordinateSet(dataSets.Count + 1);
            pointGraphics[0].CoordinateSet.Add(1, Tg.CreatePoint(5, 5, 0));

            pointGraphics[1].PointRenderStyle = PointRenderStyleEnum.kCrossPointStyle;
            pointGraphics[1].CoordinateSet    = dataSets.CreateCoordinateSet(dataSets.Count + 1);
            pointGraphics[1].CoordinateSet.Add(1, Tg.CreatePoint(10, 0, 0));

            pointGraphics[2].PointRenderStyle = PointRenderStyleEnum.kXPointStyle;
            pointGraphics[2].CoordinateSet    = dataSets.CreateCoordinateSet(dataSets.Count + 1);
            pointGraphics[2].CoordinateSet.Add(1, Tg.CreatePoint(5, -5, 0));

            pointGraphics[3].PointRenderStyle = PointRenderStyleEnum.kFilledCircleSelectPointStyle;
            pointGraphics[3].CoordinateSet    = dataSets.CreateCoordinateSet(dataSets.Count + 1);
            pointGraphics[3].CoordinateSet.Add(1, Tg.CreatePoint(0, 0, 0));

            doc.Views[1].Update();
        }
        //////////////////////////////////////////////////////////////////////////////////////
        // Use: AdnGraphicsData constructor for ComponentDefinition graphics
        //
        //////////////////////////////////////////////////////////////////////////////////////
        public AdnGraphics(
            Document document,
            string clientId,
            bool transacting,
            bool createIfNotExist)
        {
            _clientId = clientId + (transacting ? "-Tx" : "-NonTx");

            _graphicsData = null;
            _graphics     = null;

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

            ComponentDefinition compDef = GetCompDefinition(document);

            try
            {
                _graphics = compDef.ClientGraphicsCollection[_clientId];
            }
            catch
            {
                if (createIfNotExist)
                {
                    if (transacting)
                    {
                        _graphics = compDef.ClientGraphicsCollection.Add(_clientId);
                    }
                    else
                    {
                        _graphics = compDef.ClientGraphicsCollection.AddNonTransacting(_clientId);
                    }
                }
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Displays a LineGraphics between points [0, 0, 0] and [1, 1, 1].
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void LineGraphicsDemo()
        {
            PartDocument doc =
                AdnInventorUtilities.InvApplication.ActiveDocument
                as PartDocument;

            // ClientId, can be any string
            // Typically use instead current add-in GUID
            string clientId = "{Add-in Guid}";

            // Add a new graphics group.
            // This will fail if a group with same name already exists
            ClientGraphics graphics =
                doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId);

            // Add a new graphic node, with Id=1.
            // Id needs to be unique within graphics group
            GraphicsNode node = graphics.AddNode(1);

            // Add new data set
            GraphicsDataSets dataSets =
                doc.GraphicsDataSetsCollection.Add(clientId);

            // Add new coordinate set
            // Id needs to be unique within data set
            GraphicsCoordinateSet coordSet = dataSets.CreateCoordinateSet(1);

            // Fill up coordinates
            // Point1: [0.0, 0.0, 0.0]
            // Point2: [1.0, 1.0, 1.0]
            double[] coords = new double[]
            {
                0.0, 0.0, 0.0,
                1.0, 1.0, 1.0
            };

            coordSet.PutCoordinates(ref coords);

            // Create new GraphicsPrimitive
            LineGraphics lineGraphPrimitive = node.AddLineGraphics();

            lineGraphPrimitive.LineWeight = 5.0;

            // Set coordinates
            lineGraphPrimitive.CoordinateSet = coordSet;

            // Update the current view, so we see the graphics
            doc.Views[1].Update();
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Displays a PointGraphics using custom bitmap image.
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void PointGraphicsDemo()
        {
            PartDocument doc =
                AdnInventorUtilities.InvApplication.ActiveDocument
                as PartDocument;

            string clientId = "{Add-in Guid}";

            ClientGraphics   graphics = null;
            GraphicsDataSets dataSets = null;

            try
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId];
                dataSets = doc.GraphicsDataSetsCollection[clientId];
            }
            catch
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId);
                dataSets = doc.GraphicsDataSetsCollection.Add(clientId);
            }

            GraphicsNode node = graphics.AddNode(graphics.Count + 1);

            GraphicsCoordinateSet coordSet = dataSets.CreateCoordinateSet(dataSets.Count + 1);

            double[] coords = new double[]
            {
                5.0, 0.0, 0.0
            };

            coordSet.PutCoordinates(ref coords);

            GraphicsImageSet imageSet = dataSets.CreateImageSet(dataSets.Count + 1);

            stdole.IPictureDisp image =
                PictureDispConverter.ToIPictureDisp(Resources.PointImage);

            imageSet.Add(1, image, null, -1, -1);

            PointGraphics pointGraphPrimitive = node.AddPointGraphics();

            pointGraphPrimitive.CoordinateSet = coordSet;
            pointGraphPrimitive.SetCustomImage(imageSet, 1);

            doc.Views[1].Update();
        }
Esempio n. 9
0
        /// <summary>
        /// GraphicsData constructor for Interaction graphics
        /// </summary>
        /// <returns>CGraphics</returns>
        public CGraphics(InteractionEvents InteractionEvents, IntActionGraphicsModeEnum mode)
        {
            _graphicsData = InteractionEvents.InteractionGraphics.GraphicsDataSets;

            switch (mode)
            {
            case IntActionGraphicsModeEnum.kOverlayGraphics:
                _graphics = InteractionEvents.InteractionGraphics.OverlayClientGraphics;
                break;

            case IntActionGraphicsModeEnum.kPreviewGraphics:
                _graphics = InteractionEvents.InteractionGraphics.PreviewClientGraphics;
                break;

            default:
                break;
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////
        // Use: AdnGraphicsData constructor for FlatPattern graphics
        //
        //////////////////////////////////////////////////////////////////////////////////////
        public AdnGraphics(FlatPattern flat, string clientId, bool transacting)
        {
            _clientId = clientId + (transacting ? "-Tx" : "-NonTx");

            _graphicsData = null;
            _graphics     = null;

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

            try
            {
                _graphics = flat.ClientGraphicsCollection[_clientId];
            }
            catch
            {
                if (transacting)
                {
                    _graphics = flat.ClientGraphicsCollection.Add(_clientId);
                }
                else
                {
                    _graphics = flat.ClientGraphicsCollection.AddNonTransacting(_clientId);
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// GraphicsData constructor for Sheet graphics
        /// </summary>
        /// <returns>CGraphics</returns>
        public CGraphics(Sheet sheet, string clientId, bool transacting)
        {
            _clientId = clientId + (transacting ? "-Tx" : "-NonTx");

            _graphicsData = null;
            _graphics     = null;

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

            try
            {
                _graphics = sheet.ClientGraphicsCollection[_clientId];
            }
            catch
            {
                if (transacting)
                {
                    _graphics = sheet.ClientGraphicsCollection.Add(_clientId);
                }
                else
                {
                    _graphics = sheet.ClientGraphicsCollection.AddNonTransacting(_clientId);
                }
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////
        // 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);
                }
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////
        // Use: AdnGraphicsData constructor for ClientFeature graphics
        //
        //////////////////////////////////////////////////////////////////////////////////////
        public AdnGraphics(ClientFeature feature, string clientId, bool saveWithDoc)
        {
            _clientId = clientId;

            ClientFeatureDefinition cfDef = feature.Definition;

            try
            {
                _graphicsData = cfDef.GraphicsDataSetsCollection[_clientId];
            }
            catch
            {
                _graphicsData = cfDef.GraphicsDataSetsCollection.Add2(_clientId, saveWithDoc);
            }

            try
            {
                _graphics = cfDef.ClientGraphicsCollection[_clientId];
            }
            catch
            {
                _graphics = cfDef.ClientGraphicsCollection.Add(_clientId);
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////
        // 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);
                }
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////
        // Use: AdnGraphicsData constructor for ComponentDefinition graphics 
        //
        //////////////////////////////////////////////////////////////////////////////////////
        public AdnGraphics(
            Document document, 
            string clientId, 
            bool transacting, 
            bool createIfNotExist)
        {
            _clientId = clientId + (transacting ? "-Tx" : "-NonTx");

            _graphicsData = null;
            _graphics = null;

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

            ComponentDefinition compDef = GetCompDefinition(document);

            try
            {
                _graphics = compDef.ClientGraphicsCollection[_clientId];
            }
            catch
            {
                if (createIfNotExist)
                {
                    if (transacting)
                    {
                        _graphics = compDef.ClientGraphicsCollection.Add(_clientId);
                    }
                    else
                    {
                        _graphics = compDef.ClientGraphicsCollection.AddNonTransacting(_clientId);
                    }
                }
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////
        // Use: AdnGraphicsData constructor for ClientFeature graphics 
        //
        //////////////////////////////////////////////////////////////////////////////////////
        public AdnGraphics(ClientFeature feature, string clientId, bool saveWithDoc)
        {
            _clientId = clientId;

            ClientFeatureDefinition cfDef = feature.Definition;

            try
            {
                _graphicsData = cfDef.GraphicsDataSetsCollection[_clientId];
            }
            catch
            {
                _graphicsData = cfDef.GraphicsDataSetsCollection.Add2(_clientId, saveWithDoc);
            }

            try
            {
                _graphics = cfDef.ClientGraphicsCollection[_clientId];
            }
            catch
            {
                _graphics = cfDef.ClientGraphicsCollection.Add(_clientId);
            }
        }
Esempio n. 17
0
        public void Draw3D(Part Bauteil, string Name)
        {
            foreach (var mmface in Bauteil.Faces)
            {
                foreach (var point in mmface.VertexCoords)
                {
                    mVertices.Add((double)point.X);
                    mVertices.Add((double)point.Y);
                    mVertices.Add((double)point.Z);
                }

                var N = mmface.VertexIndices.Count; //  Nomber of Indices
                foreach (var indice in mmface.VertexIndices)
                {
                    var i0 = indice;
                    var i1 = i0 + N;

                    var t0 = i0;
                    var t1 = i1;

                    // NOTE: The extra +1 on each line is because Inventor expects 1 - based indices.

                    mIndices.Add(t1 + 1 + 1);
                    mIndices.Add(t0 + 1);



                    mIndices.Add(t0 + 1 + 1);
                    //  mIndices.Add(t1 + 1 + 1);
                    //  mIndices.Add(t0 + 1);

                    mIndices.Add(t1 + 1);
                }
                foreach (var Norm in mmface.Normals)
                {
                    mNormals.Add((double)Norm.X);
                    mNormals.Add((double)Norm.Y);
                    mNormals.Add((double)Norm.Z);
                }
            }



            if (null != mGraphicsDataSets)
            {
                mGraphicsDataSets.Delete();
                mGraphicsDataSets = null;

                mGraphicsNode.Delete();
                mGraphicsNode = null;

                Addin3DPdf.TrAddInServer.MApp.ActiveView.Update();
                return;
            }

            PartDocument
                doc = Addin3DPdf.TrAddInServer.MApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject,
                                                                  Addin3DPdf.TrAddInServer.MApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject),
                                                                  true) as PartDocument;

            //    PartDocument doc = Addin3DPdf.TransAddInServer.MApp.ActiveDocument as PartDocument;
            if (null == mClientGraphics)
            {
                mClientGraphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(Name);
            }

            mGraphicsDataSets = doc.GraphicsDataSetsCollection.Add(Name);



            double[] A_Verties = mVertices.ToArray();
            int[]    A_Indices = mIndices.ToArray();
            double[] A_Normals = mNormals.ToArray();
            try
            {
                var gcs = mGraphicsDataSets.CreateCoordinateSet(1) as GraphicsCoordinateSet;
                gcs.PutCoordinates(A_Verties);



                var gis = mGraphicsDataSets.CreateIndexSet(2) as GraphicsIndexSet;
                gis.PutIndices(A_Indices);



                var gns = mGraphicsDataSets.CreateNormalSet(3) as GraphicsNormalSet;
                gns.PutNormals(A_Normals);


                mGraphicsNode = mClientGraphics.AddNode(1) as GraphicsNode;
                var triangles = mGraphicsNode.AddTriangleGraphics() as TriangleGraphics;

                triangles.CoordinateSet      = gcs;
                triangles.CoordinateIndexSet = gis;
                triangles.NormalSet          = gns;
                triangles.NormalBinding      = NormalBindingEnum.kPerItemNormals;
                triangles.NormalIndexSet     = gis;



                bool inActiveDocument;
                var  brassAsset = GetAsset("Silver", out inActiveDocument);
                if (null != brassAsset)
                {
                    if (!inActiveDocument)
                    {
                        brassAsset = brassAsset.CopyTo(doc);
                    }
                    mGraphicsNode.Appearance = brassAsset;
                }
            }
            catch (Exception e)
            {
            }
            doc.SaveAs(Name, false);

            Addin3DPdf.TrAddInServer.MApp.ActiveView.Update();
        }
Esempio n. 18
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Simple example using Inventor API directly
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        public static void ClientFeatureDemo()
        {
            string clientId = AdnInventorUtilities.AddInGuid;

            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            Document document = InvApp.ActiveDocument;

            // We will use late binding to retrieve ClientFeatures collection,
            // so we dont need to write specific code for PartDocument and
            // AssemblyDocument
            ComponentDefinition compDef =
                AdnInventorUtilities.GetCompDefinition(document);

            object features =
                AdnInventorUtilities.GetProperty(compDef, "Features");

            ClientFeatures clientFeatures =
                AdnInventorUtilities.GetProperty(features, "ClientFeatures")
                as ClientFeatures;

            ClientFeatureDefinition cfDef =
                clientFeatures.CreateDefinition("Graphics Feature", null, null, null);

            ClientFeature clientFeature =
                clientFeatures.Add(cfDef, clientId);

            NativeBrowserNodeDefinition nodeDef =
                clientFeature.BrowserNode.BrowserNodeDefinition as NativeBrowserNodeDefinition;

            stdole.IPictureDisp pic =
                PictureDispConverter.ToIPictureDisp(Resources.PointImage);

            ClientNodeResource res =
                document.BrowserPanes.ClientNodeResources.Add(
                    clientId,
                    document.BrowserPanes.ClientNodeResources.Count + 1,
                    pic);

            nodeDef.OverrideIcon = res;

            cfDef = clientFeature.Definition;

            cfDef.HighlightClientGraphicsWithFeature = true;

            GraphicsDataSets sets =
                cfDef.GraphicsDataSetsCollection.Add2(clientId, true);

            GraphicsCoordinateSet coordSet = sets.CreateCoordinateSet(1);

            double[] coords = new double[]
            {
                0.0, 0.0, 0.0,
                5.0, 0.0, 0.0,
                2.5, 5.0, 0.0
            };

            coordSet.PutCoordinates(ref coords);

            ClientGraphics cg =
                cfDef.ClientGraphicsCollection.Add(clientId);

            GraphicsNode node = cg.AddNode(1);

            node.RenderStyle = document.RenderStyles["Green (Flat)"];

            TriangleGraphics primitive = node.AddTriangleGraphics();

            primitive.CoordinateSet = coordSet;

            InvApp.ActiveView.Update();
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Displays a LineGraphics using Index and Color Sets.
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void IndexSetDemo()
        {
            PartDocument doc =
                AdnInventorUtilities.InvApplication.ActiveDocument
                as PartDocument;

            string clientId = "{Add-in Guid}";

            ClientGraphics   graphics = null;
            GraphicsDataSets dataSets = null;

            // Add some error handling in case
            // graphics collection and data already exist
            try
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId];
                dataSets = doc.GraphicsDataSetsCollection[clientId];
            }
            catch
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId);
                dataSets = doc.GraphicsDataSetsCollection.Add(clientId);
            }

            // Add new node and coord set
            // Id generation by increment - bad because previous nodes/sets
            // may have been deleted previously, hence making count invalid

            GraphicsNode node =
                graphics.AddNode(graphics.Count + 1);

            GraphicsCoordinateSet coordSet =
                dataSets.CreateCoordinateSet(dataSets.Count + 1);

            double[] coords = new double[]
            {
                0.0, 0.0, 0.0, //point 1
                1.0, 1.0, 0.0, //point 2
                0.0, 1.0, 0.0, //point 3
                1.0, 0.0, 0.0  //point 4
            };

            coordSet.PutCoordinates(ref coords);

            LineGraphics lineGraphPrimitive = node.AddLineGraphics();

            lineGraphPrimitive.LineWeight = 5.0;

            //Create Coordinate Index Set
            GraphicsIndexSet indexSetCoords = dataSets.CreateIndexSet(dataSets.Count + 1);

            indexSetCoords.Add(1, 1); //from point 1
            indexSetCoords.Add(2, 3); //connect to point 3
            indexSetCoords.Add(3, 3); //from point 3
            indexSetCoords.Add(4, 2); //connect to point 2
            indexSetCoords.Add(5, 2); //from point 2
            indexSetCoords.Add(6, 4); //connect to point 4

            lineGraphPrimitive.CoordinateSet      = coordSet;
            lineGraphPrimitive.CoordinateIndexSet = indexSetCoords;


            //Create the color set with two colors
            GraphicsColorSet colorSet = dataSets.CreateColorSet(dataSets.Count + 1);

            colorSet.Add(1, 221, 0, 0);
            colorSet.Add(2, 255, 170, 0);
            colorSet.Add(3, 119, 187, 17);

            //Create the index set for color
            GraphicsIndexSet indexSetColors = dataSets.CreateIndexSet(dataSets.Count + 1);

            indexSetColors.Add(1, 3); //line 1 uses color 3
            indexSetColors.Add(2, 1); //line 2 uses color 1
            indexSetColors.Add(3, 2); //line 3 uses color 2

            lineGraphPrimitive.ColorSet      = colorSet;
            lineGraphPrimitive.ColorIndexSet = indexSetColors;

            lineGraphPrimitive.ColorBinding = ColorBindingEnum.kPerItemColors;

            doc.Views[1].Update();
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Displays a TriangleFan Graphics.
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void TriangleFanGraphicsDemo()
        {
            PartDocument doc =
                AdnInventorUtilities.InvApplication.ActiveDocument
                as PartDocument;

            string clientId = "{Add-in Guid}";

            ClientGraphics   graphics = null;
            GraphicsDataSets dataSets = null;

            try
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId];
                dataSets = doc.GraphicsDataSetsCollection[clientId];
            }
            catch
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId);
                dataSets = doc.GraphicsDataSetsCollection.Add(clientId);
            }

            GraphicsNode node = graphics.AddNode(graphics.Count + 1);

            GraphicsCoordinateSet coordSet = dataSets.CreateCoordinateSet(dataSets.Count + 1);

            double[] coords = new double[]
            {
                0.0, 0.0, 0.0, //point 1
                1.0, 1.0, 0.0, //point 2
                2.0, 0.0, 0.0, //point 3
                3.0, 1.0, 0.0, //point 4
                4.0, 0.0, 0.0, //point 5
                5.0, 1.0, 0.0, //point 6
                6.0, 0.0, 0.0, //point 7
            };

            coordSet.PutCoordinates(ref coords);

            TriangleFanGraphics triFanPrimitive = node.AddTriangleFanGraphics();

            int[] strips = new int[]
            {
                3, //points 1,2,3 for strip 1
                4  //points 4,5,6,7 for strip 2
            };

            triFanPrimitive.PutStripLengths(ref strips);

            //Create the color set with 3 colors
            GraphicsColorSet colorSet = dataSets.CreateColorSet(dataSets.Count + 1);

            colorSet.Add(1, 221, 0, 0);
            colorSet.Add(2, 119, 187, 17);
            colorSet.Add(3, 119, 187, 17);

            //Create the index set for color
            GraphicsIndexSet indexSetColors = dataSets.CreateIndexSet(dataSets.Count + 1);

            indexSetColors.Add(1, 2); //strip 1 uses color 1
            indexSetColors.Add(2, 1); //strip 2 uses color 2

            triFanPrimitive.CoordinateSet = coordSet;
            triFanPrimitive.ColorIndexSet = indexSetColors;
            triFanPrimitive.ColorSet      = colorSet;
            triFanPrimitive.ColorBinding  = ColorBindingEnum.kPerStripColors;

            doc.Views[1].Update();
        }
Esempio n. 21
0
        static public void StandartTest()
        {
            // Set Inventor Application and "activate it"
            TrAddInServer.MApp = null;
            inventordoc        = null;
            // Enable error handling.


            TransientBRep oTransBRep = TrAddInServer.MApp.TransientBRep;


            SurfaceBodyDefinition oSurfaceBodyDef = oTransBRep.CreateSurfaceBodyDefinition();

            TransientGeometry oTG = TrAddInServer.MApp.TransientGeometry;


            LumpDefinition oLumpDef = oSurfaceBodyDef.LumpDefinitions.Add();


            FaceShellDefinition oShell = oLumpDef.FaceShellDefinitions.Add();



            // Define the six planes of the box.
            Plane oPosX;
            Plane oNegX;
            Plane oPosY;
            Plane oNegY;
            Plane oPosZ;
            Plane oNegZ;

            oPosX = oTG.CreatePlane(oTG.CreatePoint(1, 0, 0), oTG.CreateVector(1, 0, 0));
            oNegX = oTG.CreatePlane(oTG.CreatePoint(-1, 0, 0), oTG.CreateVector(-1, 0, 0));
            oPosY = oTG.CreatePlane(oTG.CreatePoint(0, 1, 0), oTG.CreateVector(0, 1, 0));
            oNegY = oTG.CreatePlane(oTG.CreatePoint(0, -1, 0), oTG.CreateVector(0, -1, 0));
            oPosZ = oTG.CreatePlane(oTG.CreatePoint(0, 0, 1), oTG.CreateVector(0, 0, 1));
            oNegZ = oTG.CreatePlane(oTG.CreatePoint(0, 0, -1), oTG.CreateVector(0, 0, -1));

            // Create the six faces.
            FaceDefinition oFaceDefPosX;
            FaceDefinition oFaceDefNegX;
            FaceDefinition oFaceDefPosY;
            FaceDefinition oFaceDefNegY;
            FaceDefinition oFaceDefPosZ;
            FaceDefinition oFaceDefNegZ;

            oFaceDefPosX = oShell.FaceDefinitions.Add(oPosX, false);
            oFaceDefNegX = oShell.FaceDefinitions.Add(oNegX, false);
            oFaceDefPosY = oShell.FaceDefinitions.Add(oPosY, false);
            oFaceDefNegY = oShell.FaceDefinitions.Add(oNegY, false);
            oFaceDefPosZ = oShell.FaceDefinitions.Add(oPosZ, false);
            oFaceDefNegZ = oShell.FaceDefinitions.Add(oNegZ, false);

            // Create the vertices.
            VertexDefinition oVertex1;
            VertexDefinition oVertex2;
            VertexDefinition oVertex3;
            VertexDefinition oVertex4;
            VertexDefinition oVertex5;
            VertexDefinition oVertex6;
            VertexDefinition oVertex7;
            VertexDefinition oVertex8;

            oVertex1 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(1, 1, 1));
            oVertex2 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(1, 1, -1));
            oVertex3 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(-1, 1, -1));
            oVertex4 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(-1, 1, 1));
            oVertex5 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(1, -1, 1));
            oVertex6 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(1, -1, -1));
            oVertex7 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(-1, -1, -1));
            oVertex8 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(-1, -1, 1));

            // Define the edges at intersections of the defined planes.
            EdgeDefinition oEdgeDefPosXPosY;
            EdgeDefinition oEdgeDefPosXNegZ;
            EdgeDefinition oEdgeDefPosXNegY;
            EdgeDefinition oEdgeDefPosXPosZ;
            EdgeDefinition oEdgeDefNegXPosY;
            EdgeDefinition oEdgeDefNegXNegZ;
            EdgeDefinition oEdgeDefNegXNegY;
            EdgeDefinition oEdgeDefNegXPosZ;
            EdgeDefinition oEdgeDefPosYNegZ;
            EdgeDefinition oEdgeDefPosYPosZ;
            EdgeDefinition oEdgeDefNegYNegZ;
            EdgeDefinition oEdgeDefNegYPosZ;

            oEdgeDefPosXPosY = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex1, oVertex2, oTG.CreateLineSegment(oVertex1.Position, oVertex2.Position));
            oEdgeDefPosXNegZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex2, oVertex6, oTG.CreateLineSegment(oVertex2.Position, oVertex6.Position));
            oEdgeDefPosXNegY = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex6, oVertex5, oTG.CreateLineSegment(oVertex6.Position, oVertex5.Position));
            oEdgeDefPosXPosZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex5, oVertex1, oTG.CreateLineSegment(oVertex5.Position, oVertex1.Position));
            oEdgeDefNegXPosY = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex4, oVertex3, oTG.CreateLineSegment(oVertex4.Position, oVertex3.Position));
            oEdgeDefNegXNegZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex3, oVertex7, oTG.CreateLineSegment(oVertex3.Position, oVertex7.Position));
            oEdgeDefNegXNegY = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex7, oVertex8, oTG.CreateLineSegment(oVertex7.Position, oVertex8.Position));
            oEdgeDefNegXPosZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex8, oVertex4, oTG.CreateLineSegment(oVertex8.Position, oVertex4.Position));
            oEdgeDefPosYNegZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex2, oVertex3, oTG.CreateLineSegment(oVertex2.Position, oVertex3.Position));
            oEdgeDefPosYPosZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex4, oVertex1, oTG.CreateLineSegment(oVertex4.Position, oVertex1.Position));
            oEdgeDefNegYNegZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex7, oVertex6, oTG.CreateLineSegment(oVertex7.Position, oVertex6.Position));
            oEdgeDefNegYPosZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex5, oVertex8, oTG.CreateLineSegment(oVertex5.Position, oVertex8.Position));

            // Define the loops on the faces.

            EdgeLoopDefinition oPosXLoop = oFaceDefPosX.EdgeLoopDefinitions.Add();

            oPosXLoop.EdgeUseDefinitions.Add(oEdgeDefPosXPosY, true);
            oPosXLoop.EdgeUseDefinitions.Add(oEdgeDefPosXNegZ, true);
            oPosXLoop.EdgeUseDefinitions.Add(oEdgeDefPosXNegY, true);
            oPosXLoop.EdgeUseDefinitions.Add(oEdgeDefPosXPosZ, true);


            EdgeLoopDefinition oNegXLoop = oFaceDefNegX.EdgeLoopDefinitions.Add();

            oNegXLoop.EdgeUseDefinitions.Add(oEdgeDefNegXPosY, false);
            oNegXLoop.EdgeUseDefinitions.Add(oEdgeDefNegXNegZ, false);
            oNegXLoop.EdgeUseDefinitions.Add(oEdgeDefNegXNegY, false);
            oNegXLoop.EdgeUseDefinitions.Add(oEdgeDefNegXPosZ, false);


            EdgeLoopDefinition oPosYLoop = oFaceDefPosY.EdgeLoopDefinitions.Add();

            oPosYLoop.EdgeUseDefinitions.Add(oEdgeDefPosXPosY, false);
            oPosYLoop.EdgeUseDefinitions.Add(oEdgeDefPosYNegZ, false);
            oPosYLoop.EdgeUseDefinitions.Add(oEdgeDefNegXPosY, true);
            oPosYLoop.EdgeUseDefinitions.Add(oEdgeDefPosYPosZ, false);


            EdgeLoopDefinition oNegYLoop = oFaceDefNegY.EdgeLoopDefinitions.Add();

            oNegYLoop.EdgeUseDefinitions.Add(oEdgeDefPosXNegY, false);
            oNegYLoop.EdgeUseDefinitions.Add(oEdgeDefNegYPosZ, false);
            oNegYLoop.EdgeUseDefinitions.Add(oEdgeDefNegXNegY, true);
            oNegYLoop.EdgeUseDefinitions.Add(oEdgeDefNegYNegZ, false);

            EdgeLoopDefinition oPosZLoop = oFaceDefPosZ.EdgeLoopDefinitions.Add();

            oPosZLoop.EdgeUseDefinitions.Add(oEdgeDefNegXPosZ, true);
            oPosZLoop.EdgeUseDefinitions.Add(oEdgeDefNegYPosZ, true);
            oPosZLoop.EdgeUseDefinitions.Add(oEdgeDefPosXPosZ, false);
            oPosZLoop.EdgeUseDefinitions.Add(oEdgeDefPosYPosZ, true);


            EdgeLoopDefinition oNegZLoop = oFaceDefNegZ.EdgeLoopDefinitions.Add();

            oNegZLoop.EdgeUseDefinitions.Add(oEdgeDefNegXNegZ, true);
            oNegZLoop.EdgeUseDefinitions.Add(oEdgeDefNegYNegZ, true);
            oNegZLoop.EdgeUseDefinitions.Add(oEdgeDefPosXNegZ, false);
            oNegZLoop.EdgeUseDefinitions.Add(oEdgeDefPosYNegZ, true);

            //Create a transient surface body.
            NameValueMap oErrors;

            SurfaceBody oNewBody = oSurfaceBodyDef.CreateTransientSurfaceBody(out oErrors);

            // Create client graphics to display the transient body.

            PartDocument oDoc = (PartDocument)TrAddInServer.MApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject);


            PartComponentDefinition oDef = oDoc.ComponentDefinition;


            ClientGraphics oClientGraphics = oDef.ClientGraphicsCollection.Add("Sample3DGraphicsID");

            // Create a new graphics node within the client graphics objects.
            GraphicsNode oSurfacesNode = oClientGraphics.AddNode(1);

            // Create client graphics based on the transient body
            SurfaceGraphics oSurfaceGraphics = oSurfacesNode.AddSurfaceGraphics(oNewBody);

            // Update the view.
            TrAddInServer.MApp.ActiveView.Update();
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Displays a TextGraphics with different styles and properties.
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void TextGraphicsDemo()
        {
            PartDocument doc =
                AdnInventorUtilities.InvApplication.ActiveDocument
                as PartDocument;

            string clientId = "{Add-in Guid}";

            ClientGraphics   graphics = null;
            GraphicsDataSets dataSets = null;

            try
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId];
                dataSets = doc.GraphicsDataSetsCollection[clientId];
            }
            catch
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId);
                dataSets = doc.GraphicsDataSetsCollection.Add(clientId);
            }

            TransientGeometry Tg = AdnInventorUtilities.InvApplication.TransientGeometry;

            GraphicsNode node = graphics.AddNode(graphics.Count + 1);

            //Create scalable text graphics
            TextGraphics scalableTxt = node.AddScalableTextGraphics();

            //Set the properties of the text
            scalableTxt.Text                = "Scalable Text";
            scalableTxt.Anchor              = Tg.CreatePoint(0, 20, 0);
            scalableTxt.Bold                = true;
            scalableTxt.Font                = "Arial";
            scalableTxt.FontSize            = 10;
            scalableTxt.HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft;
            scalableTxt.Italic              = true;
            scalableTxt.PutTextColor(119, 187, 17);
            scalableTxt.VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextMiddle;


            //Create anchored text graphics
            TextGraphics anchoredTxt = node.AddTextGraphics();

            //Set the properties of the text.
            anchoredTxt.Text     = "Anchored Text";
            anchoredTxt.Bold     = true;
            anchoredTxt.FontSize = 30;
            anchoredTxt.PutTextColor(255, 170, 0);

            Point anchorPoint = Tg.CreatePoint(1, 1, 1);

            //Set the text's anchor in model space.
            anchoredTxt.Anchor = anchorPoint;

            //Anchor the text graphics in the view.
            anchoredTxt.SetViewSpaceAnchor(
                anchorPoint,
                Tg.CreatePoint2d(30, 30),
                ViewLayoutEnum.kTopLeftViewCorner);


            TextGraphics symbolTxt1 = node.AddTextGraphics();

            symbolTxt1.Text = "n ";

            Point modelAnchorPoint = Tg.CreatePoint(50, 0, 0);

            //Because this text will have pixel scaling behavior these coordinates are in pixel space.
            symbolTxt1.Anchor              = Tg.CreatePoint(0, 0, 0);
            symbolTxt1.Font                = "AIGDT";
            symbolTxt1.FontSize            = 25;
            symbolTxt1.HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft;
            symbolTxt1.PutTextColor(221, 0, 0);
            symbolTxt1.VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextMiddle;
            symbolTxt1.SetTransformBehavior(
                modelAnchorPoint,
                DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling,
                1);

            Box box = symbolTxt1.RangeBox;

            //Draw the next section of the string relative to the first section.
            TextGraphics symbolTxt2 = node.AddTextGraphics();

            symbolTxt2.Text = "9.4 - 9.8";

            //The range of the previous character is used to determine where to position
            //the next string. The range is returned in pixels.
            symbolTxt2.Anchor = Tg.CreatePoint(box.MaxPoint.X, 0, 0);

            symbolTxt2.Font                = "Arial";
            symbolTxt2.FontSize            = 25;
            symbolTxt2.HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft;
            symbolTxt2.PutTextColor(221, 0, 0);
            symbolTxt2.VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextMiddle;
            symbolTxt2.SetTransformBehavior(
                modelAnchorPoint,
                DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling,
                1);

            doc.Views[1].Update();
        }
        public void CreateMesh(NameValueMap nv)
        {
            var N  = 512;
            var T0 = DateTime.Now;

            if (null != mGraphicsDataSets)
            {
                mGraphicsDataSets.Delete();
                mGraphicsDataSets = null;

                mGraphicsNode.Delete();
                mGraphicsNode = null;

                mApp.ActiveView.Update();
                return;
            }

            var doc = mApp.ActiveDocument as PartDocument;

            if (null == mClientGraphics)
            {
                mClientGraphics = doc.ComponentDefinition.ClientGraphicsCollection.Add("MyTest");
            }

            mGraphicsDataSets = doc.GraphicsDataSetsCollection.Add("MyTest");

            var setupTimeSeconds = (DateTime.Now - T0).TotalSeconds;

            T0 = DateTime.Now;

            var msg = string.Format("N = {0}, {1} triangles\n", N, mNumTriangles)
                      + string.Format("Inventor setup time: {0} sec\n", setupTimeSeconds);

            T0 = DateTime.Now;

            try
            {
                var dataSetsTimeSeconds = (DateTime.Now - T0).TotalSeconds;
                T0 = DateTime.Now;

                var gcs = mGraphicsDataSets.CreateCoordinateSet(1) as GraphicsCoordinateSet;
                gcs.PutCoordinates(mVertices);

                var coordSetSeconds = (DateTime.Now - T0).TotalSeconds;
                T0 = DateTime.Now;

                var gis = mGraphicsDataSets.CreateIndexSet(2) as GraphicsIndexSet;
                gis.PutIndices(mIndices);

                var indexSetSeconds = (DateTime.Now - T0).TotalSeconds;
                T0 = DateTime.Now;

                var gns = mGraphicsDataSets.CreateNormalSet(3) as GraphicsNormalSet;
                gns.PutNormals(mNormals);

                var normalSetSeconds = (DateTime.Now - T0).TotalSeconds;
                T0 = DateTime.Now;

                mGraphicsNode = mClientGraphics.AddNode(1) as GraphicsNode;
                var triangles = mGraphicsNode.AddTriangleGraphics() as TriangleGraphics;

                triangles.CoordinateSet      = gcs;
                triangles.CoordinateIndexSet = gis;
                triangles.NormalSet          = gns;
                triangles.NormalBinding      = NormalBindingEnum.kPerItemNormals;
                triangles.NormalIndexSet     = gis;

                var trianglesSeconds = (DateTime.Now - T0).TotalSeconds;

                bool inActiveDocument;
                var  brassAsset = GetAsset("Brass - Satin", out inActiveDocument);
                if (null != brassAsset)
                {
                    if (!inActiveDocument)
                    {
                        brassAsset = brassAsset.CopyTo(doc);
                    }
                    mGraphicsNode.Appearance = brassAsset;
                }

                msg = msg + string.Format("GraphicsDataSetsCollection.Add time: {0} sec\n", dataSetsTimeSeconds)
                      + string.Format("Coordinate set creation time: {0} sec\n", coordSetSeconds)
                      + string.Format("Index set creation time: {0} sec\n", indexSetSeconds)
                      + string.Format("Normal set creation time: {0} sec\n", normalSetSeconds)
                      + string.Format("Triangle node creation time: {0} sec\n", trianglesSeconds);
            }
            catch (Exception e)
            {
                msg += string.Format("Exception: {0}", e.ToString());
            }

            mApp.ActiveView.Update();

            System.Windows.MessageBox.Show(msg);
        }
        //////////////////////////////////////////////////////////////////////////////////////
        // Use: AdnGraphicsData constructor for FlatPattern graphics 
        //
        //////////////////////////////////////////////////////////////////////////////////////
        public AdnGraphics(FlatPattern flat, string clientId, bool transacting)
        {
            _clientId = clientId + (transacting ? "-Tx" : "-NonTx");

            _graphicsData = null;
            _graphics = null;

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

            try
            {
                _graphics = flat.ClientGraphicsCollection[_clientId];
            }
            catch
            {
                if (transacting)
                {
                    _graphics = flat.ClientGraphicsCollection.Add(_clientId);
                }
                else
                {
                    _graphics = flat.ClientGraphicsCollection.AddNonTransacting(_clientId);
                }
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Copies SurfaceBody 1 of current part and performs boolean operation
        //              to displays result as SurfaceGraphics.
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void SurfaceGraphicsDemo()
        {
            PartDocument doc =
                AdnInventorUtilities.InvApplication.ActiveDocument
                as PartDocument;

            string clientId = "{Add-in Guid}";

            ClientGraphics graphics = null;

            try
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId];
            }
            catch
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId);
            }

            // Store utility objects
            TransientGeometry geom = AdnInventorUtilities.InvApplication.TransientGeometry;
            TransientBRep     brep = AdnInventorUtilities.InvApplication.TransientBRep;

            GraphicsNode node = graphics.AddNode(graphics.Count + 1);

            // We will work on the first surface body in our document
            SurfaceBody nativeBody = doc.ComponentDefinition.SurfaceBodies[1];

            // Create a transient copy of the native body to work on it
            SurfaceBody body = brep.Copy(nativeBody);

            // Compute bottom/top points based on body bounding box
            Point bottom = geom.CreatePoint(
                (nativeBody.RangeBox.MinPoint.X + nativeBody.RangeBox.MaxPoint.X) / 2,
                (nativeBody.RangeBox.MinPoint.Y + nativeBody.RangeBox.MaxPoint.Y) / 2,
                nativeBody.RangeBox.MinPoint.Z);

            Point top = geom.CreatePoint(
                (nativeBody.RangeBox.MinPoint.X + nativeBody.RangeBox.MaxPoint.X) / 2,
                (nativeBody.RangeBox.MinPoint.Y + nativeBody.RangeBox.MaxPoint.Y) / 2,
                nativeBody.RangeBox.MaxPoint.Z);

            // Create transient cylinder tool body
            double radius = bottom.DistanceTo(top);

            SurfaceBody tool = brep.CreateSolidCylinderCone(bottom, top, radius, radius, radius, null);

            // Do boolean operation between transient bodies to remove cylinder
            brep.DoBoolean(body, tool, BooleanTypeEnum.kBooleanTypeDifference);

            // Add SurfaceGraphics primitive
            SurfaceGraphics surfGraphPrimitive = node.AddSurfaceGraphics(body);

            // Copy render style of native body if any
            StyleSourceTypeEnum source;
            RenderStyle         style = nativeBody.GetRenderStyle(out source);

            node.RenderStyle = style;

            // Hide native body
            nativeBody.Visible = false;

            doc.Views[1].Update();
        }
        //////////////////////////////////////////////////////////////////////////////////////
        // Use: AdnGraphicsData constructor for Interaction graphics 
        //
        //////////////////////////////////////////////////////////////////////////////////////
        public AdnGraphics(
            InteractionEvents InteractionEvents, 
            AdnInteractionGraphicsModeEnum mode)
        {
            _graphicsData = InteractionEvents.InteractionGraphics.GraphicsDataSets;

            switch(mode)
            {
                case AdnInteractionGraphicsModeEnum.kOverlayGraphics:
                    _graphics = InteractionEvents.InteractionGraphics.OverlayClientGraphics;
                    break;
                case AdnInteractionGraphicsModeEnum.kPreviewGraphics:
                    _graphics = InteractionEvents.InteractionGraphics.PreviewClientGraphics;
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// When the appropriate rectangle button is clicked the button's OnExecute event handler
        /// calls this method to hook up the mouse click event which will wait for the user to select 
        /// a point from which to start the drawing of the rectangle
        /// </summary>
        public virtual void StartRectangleInteraction()
        {
            _interactionEvents = _inventorApplication.CommandManager.CreateInteractionEvents();

            _rectangleInteractionGraphics = _interactionEvents.InteractionGraphics;
            _rectangleClientGraphics = _rectangleInteractionGraphics.OverlayClientGraphics;
            _rectangleLineNode = _rectangleClientGraphics.AddNode(1);
            _rectangleGraphicsDataSets = _rectangleInteractionGraphics.GraphicsDataSets;
            _rectangleCoordSet = _rectangleGraphicsDataSets.CreateCoordinateSet(1);
            _rectangleIndexSet = _rectangleGraphicsDataSets.CreateIndexSet(1);

            _onTerminate_Delegate = new InteractionEventsSink_OnTerminateEventHandler(StopInteraction);
            _interactionEvents.OnTerminate += _onTerminate_Delegate;

            _userInputEvents = _inventorApplication.CommandManager.UserInputEvents;
            _userInputEvents_OnContextMenuDelegate = new UserInputEventsSink_OnContextMenuEventHandler(UserInputEvents_OnContextMenu);
            _userInputEvents.OnContextMenu += _userInputEvents_OnContextMenuDelegate;

            _mouseEvents = _interactionEvents.MouseEvents;
            _mouseEvents.PointInferenceEnabled = true;
            _onMouseClick_Delegate = new MouseEventsSink_OnMouseClickEventHandler(OnMouseClick_CreateRectangle);
            _mouseEvents.OnMouseClick += _onMouseClick_Delegate;

            _interactionEvents.StatusBarText = "Select a Point from which to start the rectangle";

            _interactionEvents.AllowCommandAliases = true;

            _interactionEvents.Start();
        }