Example #1
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;
        }
        public TriangleStripGraphics DrawTriangleStrip(
            double[] coordinates,
            GraphicsNode node)
        {
            try
            {
                AdnGraphics graphicsData = WorkingGraphics;

                if (node == null)
                {
                    node = graphicsData.ClientGraphics.AddNode(
                        graphicsData.GetGraphicNodeFreeId());
                }

                TriangleStripGraphics graphic = node.AddTriangleStripGraphics();

                if (coordinates != null)
                {
                    GraphicsCoordinateSet coordSet =
                        graphicsData.GraphicsDataSets.CreateCoordinateSet(
                            graphicsData.GetDataSetFreeId());

                    coordSet.PutCoordinates(ref coordinates);

                    graphic.CoordinateSet = coordSet;
                }

                return(graphic);
            }
            catch
            {
                return(null);
            }
        }
        public TriangleStripGraphics DrawTriangleStrip(
           double[] coordinates,
           GraphicsNode node)
        {
            try
            {
                AdnGraphics graphicsData = WorkingGraphics;

                if (node == null)
                {
                    node = graphicsData.ClientGraphics.AddNode(
                        graphicsData.GetGraphicNodeFreeId());
                }

                TriangleStripGraphics graphic = node.AddTriangleStripGraphics();

                if (coordinates != null)
                {
                    GraphicsCoordinateSet coordSet =
                        graphicsData.GraphicsDataSets.CreateCoordinateSet(
                            graphicsData.GetDataSetFreeId());

                    coordSet.PutCoordinates(ref coordinates);

                    graphic.CoordinateSet = coordSet;
                }

                return graphic;
            }
            catch
            {
                return null;
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Displays a TriangleStrip Graphics.
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void TriangleStripGraphicsDemo()
        {
            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);

            TriangleStripGraphics triStripPrimitive = node.AddTriangleStripGraphics();

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

            triStripPrimitive.PutStripLengths(ref strips);


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

            colorSet.Add(1, 221, 0, 0);
            colorSet.Add(2, 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

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

            doc.Views[1].Update();
        }