////////////////////////////////////////////////////////////////////////////////////////////// // The public static method to start the demo // ////////////////////////////////////////////////////////////////////////////////////////////// public static void Demo() { Inventor.Application InvApp = AdnInventorUtilities.InvApplication; object selection = InvApp.CommandManager.Pick( SelectionFilterEnum.kPartBodyFilter, "Select a SurfaceBody: "); if (selection == null) return; SurfaceBody body = selection as SurfaceBody; AdnClientGraphicsManager clientGraphicsMng = new AdnClientGraphicsManager( InvApp, AdnInventorUtilities.AddInGuid); GraphicsNode node = clientGraphicsMng.CreateNewGraphicsNode(); foreach (Edge edge in body.Edges) { CurveGraphics graphic = clientGraphicsMng.DrawCurve(edge.Geometry, node); graphic.LineWeight = 5.0; graphic.Parent.RenderStyle = InvApp.ActiveDocument.RenderStyles["Red"]; } clientGraphicsMng.UpdateView(); }
////////////////////////////////////////////////////////////////////////////////////////////// // The public static method to start the demo // ////////////////////////////////////////////////////////////////////////////////////////////// public static void Demo() { Inventor.Application InvApp = AdnInventorUtilities.InvApplication; object selection1 = InvApp.CommandManager.Pick( SelectionFilterEnum.kPartVertexFilter, "Select first vertex: "); if (selection1 == null) return; object selection2 = InvApp.CommandManager.Pick( SelectionFilterEnum.kPartVertexFilter, "Select second vertex: "); if (selection2 == null) return; object selection3 = InvApp.CommandManager.Pick( SelectionFilterEnum.kPartVertexFilter, "Select third vertex: "); if (selection3 == null) return; List<double> coords = new List<double>(); coords.AddRange(AdnInventorUtilities.ToArray(AdnInventorUtilities.GetPoint(selection1))); coords.AddRange(AdnInventorUtilities.ToArray(AdnInventorUtilities.GetPoint(selection2))); coords.AddRange(AdnInventorUtilities.ToArray(AdnInventorUtilities.GetPoint(selection3))); AdnClientGraphicsManager clientGraphicsMng = new AdnClientGraphicsManager( InvApp, AdnInventorUtilities.AddInGuid); LineStripGraphics lineStrip = clientGraphicsMng.DrawLineStrip(coords.ToArray()); lineStrip.LineWeight = 5.0; int id = clientGraphicsMng.WorkingGraphics.GetDataSetFreeId(); lineStrip.ColorSet = clientGraphicsMng.WorkingGraphics.GraphicsDataSets.CreateColorSet(id); lineStrip.ColorSet.Add(1, 119, 187, 17); clientGraphicsMng.UpdateView(); }
////////////////////////////////////////////////////////////////////////////////////////////// // Description: Displays a LineGraphics between points [0, 0, 0] and [1, 1, 1] // using AdnClientGraphicsManager ////////////////////////////////////////////////////////////////////////////////////////////// public static void Demo() { Inventor.Application InvApp = AdnInventorUtilities.InvApplication; double[] startPoint = new double[] {0.0, 0.0, 0.0}; double[] endPoint = new double[] {1.0, 1.0, 1.0}; // Create instance of AdnClientGraphicsManager AdnClientGraphicsManager clientGraphicsMng = new AdnClientGraphicsManager(InvApp, AdnInventorUtilities.AddInGuid); // Set document as current graphics source clientGraphicsMng.SetGraphicsSource(InvApp.ActiveDocument); // Create LineGraphics primitive LineGraphics lineGraph = clientGraphicsMng.DrawLine(startPoint, endPoint); lineGraph.LineWeight = 5.0; // Update view to see results clientGraphicsMng.UpdateView(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ClientGraphics simulation running within InteractionEvents using overlay or preview graphics // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void RunWithInteraction(bool overlay) { Initialize(); System.Windows.Forms.Application.AddMessageFilter(new MsgFilter()); Inventor.Application InvApp = AdnInventorUtilities.InvApplication; AssemblyDocument doc = InvApp.ActiveDocument as AssemblyDocument; AssemblyComponentDefinition compDef = doc.ComponentDefinition; Inventor.View view = InvApp.ActiveView; Matrix matrix = InvApp.TransientGeometry.CreateMatrix(); AdnInteractionManager interactionManager = new AdnInteractionManager(InvApp); interactionManager.Initialize(); AdnClientGraphicsManager clientGraphicsMng = new AdnClientGraphicsManager( InvApp, AdnInventorUtilities.AddInGuid); clientGraphicsMng.InteractionGraphicsMode = (overlay ? AdnInteractionGraphicsModeEnum.kOverlayGraphics : AdnInteractionGraphicsModeEnum.kPreviewGraphics); foreach (ComponentOccurrence occurrence in compDef.Occurrences) { occurrence.Visible = false; } interactionManager.Start("Simulation with InteractionEvents"); clientGraphicsMng.SetGraphicsSource(interactionManager.InteractionEvents); List<GraphicsNode> nodes = new List<GraphicsNode>(); foreach (ComponentOccurrence occurrence in compDef.Occurrences) { SurfaceBody body = occurrence.Definition.SurfaceBodies[1]; SurfaceGraphics surfGraph = clientGraphicsMng.DrawSurface(body, null); GraphicsNode node = surfGraph.Parent; if (occurrence.RenderStyle != null) node.RenderStyle = occurrence.RenderStyle; nodes.Add(node); } AdnTimer timer = new AdnTimer(); double[] transfo = new double[16]; _bActive = true; while (_bActive) { System.Windows.Forms.Application.DoEvents(); double dT = timer.ElapsedSeconds; _dynamicsWorld.StepSimulation(dT, 10); int idx = 0; foreach (RigidBody body in _mapOccurrencesToBodies.Values) { body.GetWorldTransform(ref transfo); matrix.PutMatrixData(ref transfo); nodes[idx].Transformation = matrix; ++idx; } clientGraphicsMng.UpdateView(); ComputeFrameRate(dT); } _dynamicsWorld.CleanUp(); interactionManager.Stop(); foreach (ComponentOccurrence occurrence in compDef.Occurrences) { occurrence.Visible = true; } }
////////////////////////////////////////////////////////////////////////////////////////////// // Deletes all graphics created by ClientGraphicsManager // ////////////////////////////////////////////////////////////////////////////////////////////// public static void DeleteManagerGraphics() { Inventor.Application InvApp = AdnInventorUtilities.InvApplication; Document document = InvApp.ActiveDocument; AdnClientGraphicsManager clientGraphicsMng = new AdnClientGraphicsManager( InvApp, AdnInventorUtilities.AddInGuid); switch (document.DocumentType) { case DocumentTypeEnum.kAssemblyDocumentObject: case DocumentTypeEnum.kPartDocumentObject: clientGraphicsMng.DeleteGraphics(document, true); break; case DocumentTypeEnum.kDrawingDocumentObject: DrawingDocument drawing = document as DrawingDocument; clientGraphicsMng.DeleteGraphics(drawing.ActiveSheet, true); break; default: break; } clientGraphicsMng.UpdateView(); }
////////////////////////////////////////////////////////////////////////////////////////////// // 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(); }