コード例 #1
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();
        }