Example #1
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Creates ClientFeature that holds our dimension graphics
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        void CreateClientFeature(Point point1, Point point2, Point dimText, Vector normal)
        {
            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            Document document = InvApp.ActiveDocument;

            ComponentDefinition compDef =
                AdnInventorUtilities.GetCompDefinition(document);

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

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

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

            ClientFeature clientFeature =
                clientFeatures.Add(cfDef, AdnInventorUtilities.AddInGuid);

            cfDef = clientFeature.Definition;

            cfDef.HighlightClientGraphicsWithFeature = true;

            NativeBrowserNodeDefinition nodeDef =
                clientFeature.BrowserNode.BrowserNodeDefinition as NativeBrowserNodeDefinition;

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

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

            nodeDef.OverrideIcon = res;

            _clientGraphicsMng.SetGraphicsSource(clientFeature);

            DrawDimension(point1, point2, dimText, normal);

            _clientGraphicsMng.UpdateView();
        }
Example #2
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();
        }
Example #3
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Example using the AdnClientGraphicsManager
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        public static void DemoMng()
        {
            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, AdnInventorUtilities.AddInGuid);

            cfDef = clientFeature.Definition;

            cfDef.HighlightClientGraphicsWithFeature = true;

            NativeBrowserNodeDefinition nodeDef =
                clientFeature.BrowserNode.BrowserNodeDefinition as NativeBrowserNodeDefinition;

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

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

            nodeDef.OverrideIcon = res;

            AdnClientGraphicsManager clientGraphicsMng = new AdnClientGraphicsManager(
                InvApp,
                AdnInventorUtilities.AddInGuid);

            clientGraphicsMng.SetGraphicsSource(clientFeature);

            Random rd = new Random();

            TriangleGraphics graphics = clientGraphicsMng.DrawTriangle(
                new double[] { rd.Next(0, 10), rd.Next(0, 10), rd.Next(0, 10) },
                new double[] { rd.Next(0, 10), rd.Next(0, 10), rd.Next(0, 10) },
                new double[] { rd.Next(0, 10), rd.Next(0, 10), rd.Next(0, 10) },
                null);

            int id = clientGraphicsMng.WorkingGraphics.GetDataSetFreeId();

            GraphicsColorSet colorSet =
                clientGraphicsMng.WorkingGraphics.GraphicsDataSets.CreateColorSet(id);

            colorSet.Add(1, (byte)rd.Next(0, 255), (byte)rd.Next(0, 255), (byte)rd.Next(0, 255));

            graphics.ColorSet = colorSet;

            clientGraphicsMng.UpdateView();
        }