////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 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;
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Direct Simulation, no ClientGraphics involved only moving occurrences in assembly context
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void Run()
        {
            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;

            InvApp.UserInterfaceManager.UserInteractionDisabled = true;

            Transaction Tx = InvApp.TransactionManager.StartGlobalTransaction(doc as _Document, "Simulation");

            ObjectCollection colOccurrences = InvApp.TransientObjects.CreateObjectCollection(null);
            ObjectCollection colTransformations = InvApp.TransientObjects.CreateObjectCollection(null);

            foreach (ComponentOccurrence occurrence in compDef.Occurrences)
            {
                colOccurrences.Add(occurrence);
                colTransformations.Add(occurrence.Transformation);
            }

            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 = 1;

                foreach (RigidBody body in _mapOccurrencesToBodies.Values)
                {
                    body.GetWorldTransform(ref transfo);

                    Matrix matrix = colTransformations[idx] as Matrix;

                    matrix.PutMatrixData(ref transfo);

                    ++idx;
                }

			    compDef.TransformOccurrences(colOccurrences, colTransformations, true); 

			    view.Update();

                ComputeFrameRate(dT);
            }

            _dynamicsWorld.CleanUp();

            Tx.End();

            InvApp.UserInterfaceManager.UserInteractionDisabled = false;
        }