public SurfaceGraphics DrawSurface(
            object surface,
            GraphicsNode node)
        {
            try
            {
                AdnGraphics graphicsData = WorkingGraphics;

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

                SurfaceGraphics graphic = node.AddSurfaceGraphics(surface);

                return(graphic);
            }
            catch
            {
                return(null);
            }
        }
        public SurfaceGraphics DrawSurface(
            object surface,
            GraphicsNode node)
        {
            try
            {
                AdnGraphics graphicsData = WorkingGraphics;

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

                SurfaceGraphics graphic = node.AddSurfaceGraphics(surface);

                return graphic;
            }
            catch
            {
                return null;
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Copies SurfaceBody 1 of current part and performs boolean operation
        //              to displays result as SurfaceGraphics.
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void SurfaceGraphicsDemo()
        {
            PartDocument doc =
                AdnInventorUtilities.InvApplication.ActiveDocument
                as PartDocument;

            string clientId = "{Add-in Guid}";

            ClientGraphics graphics = null;

            try
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId];
            }
            catch
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId);
            }

            // Store utility objects
            TransientGeometry geom = AdnInventorUtilities.InvApplication.TransientGeometry;
            TransientBRep     brep = AdnInventorUtilities.InvApplication.TransientBRep;

            GraphicsNode node = graphics.AddNode(graphics.Count + 1);

            // We will work on the first surface body in our document
            SurfaceBody nativeBody = doc.ComponentDefinition.SurfaceBodies[1];

            // Create a transient copy of the native body to work on it
            SurfaceBody body = brep.Copy(nativeBody);

            // Compute bottom/top points based on body bounding box
            Point bottom = geom.CreatePoint(
                (nativeBody.RangeBox.MinPoint.X + nativeBody.RangeBox.MaxPoint.X) / 2,
                (nativeBody.RangeBox.MinPoint.Y + nativeBody.RangeBox.MaxPoint.Y) / 2,
                nativeBody.RangeBox.MinPoint.Z);

            Point top = geom.CreatePoint(
                (nativeBody.RangeBox.MinPoint.X + nativeBody.RangeBox.MaxPoint.X) / 2,
                (nativeBody.RangeBox.MinPoint.Y + nativeBody.RangeBox.MaxPoint.Y) / 2,
                nativeBody.RangeBox.MaxPoint.Z);

            // Create transient cylinder tool body
            double radius = bottom.DistanceTo(top);

            SurfaceBody tool = brep.CreateSolidCylinderCone(bottom, top, radius, radius, radius, null);

            // Do boolean operation between transient bodies to remove cylinder
            brep.DoBoolean(body, tool, BooleanTypeEnum.kBooleanTypeDifference);

            // Add SurfaceGraphics primitive
            SurfaceGraphics surfGraphPrimitive = node.AddSurfaceGraphics(body);

            // Copy render style of native body if any
            StyleSourceTypeEnum source;
            RenderStyle         style = nativeBody.GetRenderStyle(out source);

            node.RenderStyle = style;

            // Hide native body
            nativeBody.Visible = false;

            doc.Views[1].Update();
        }
Example #4
0
        private void DrawCubes()
        {
            try
            {
                var activeDoc = mInventorApp.ActiveDocument as PartDocument;

                var          rubikFile = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString() + @"\rubik_part.ipt";
                var          rubikDoc  = mInventorApp.Documents.Open(rubikFile, false);
                PartDocument partDoc   = rubikDoc as PartDocument;

                SurfaceBodies surfBodies = partDoc.ComponentDefinition.SurfaceBodies;

                mSurfaceBodies = new List <SurfaceBody>();
                for (int i = 1; i <= surfBodies.Count; i++)
                {
                    mSurfaceBodies.Add(mInventorApp.TransientBRep.Copy(surfBodies[i]));
                }

                // attach IDs to face
                //for (int i = 0; i < mSurfaceBodies.Count; i++)
                //    for (int j = 1; j <= mSurfaceBodies[i].Faces.Count; j++)
                //        mSurfaceBodies[i].Faces[j].AssociativeID = i * 10 + j;

                // iterate over assets and copy them if needed
                for (int i = 1; i <= surfBodies.Count; i++)
                {
                    SurfaceBody surfBody = surfBodies[i];
                    for (int j = 1; j <= surfBody.Faces.Count; j++)
                    {
                        string apperanceName = surfBody.Faces[j].Appearance.DisplayName;
                        try
                        {
                            Asset asset = activeDoc.Assets[apperanceName];
                        }
                        catch (Exception e)
                        {
                            AssetLibrary assetLib = mInventorApp.AssetLibraries["Inventor Material Library"];
                            Asset        asset    = assetLib.AppearanceAssets[apperanceName];
                            asset = asset.CopyTo(activeDoc);
                        }
                    }
                }

                // create the transient graphics of the cubes
                //mClientGraphics = mInventeractionEvents.InteractionGraphics.OverlayClientGraphics;
                mCubes = new List <GraphicsNode>();
                for (int i = 0; i < mSurfaceBodies.Count; i++)
                {
                    GraphicsNode            node         = mClientGraphics.AddNode(mClientGraphics.Count + 1);
                    SurfaceGraphics         surfGraphics = node.AddSurfaceGraphics(mSurfaceBodies[i]);
                    SurfaceGraphicsFaceList surfFaceList = surfGraphics.DisplayedFaces;
                    for (int j = 1; j <= surfFaceList.Count; j++)
                    {
                        string apperanceName = surfBodies[i + 1].Faces[j].Appearance.DisplayName;
                        if (apperanceName == "Default")
                        {
                            apperanceName = "Glossy - Black";
                        }

                        surfFaceList[j].Appearance = activeDoc.Assets[apperanceName];
                        surfFaceList[j].Selectable = true;
                    }

                    surfGraphics.ChildrenAreSelectable = true;
                    node.Selectable = true;
                    //node.AllowSlicing = true;
                    mCubes.Add(node);
                }

                SetLights();
                // set the active view to isometric view
                Camera camera = mInventorApp.ActiveView.Camera;
                camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopLeftViewOrientation;
                camera.Fit();
                camera.Apply();

                // close the document
                rubikDoc.ReleaseReference();
                rubikDoc.Close(true);
            }
            catch (Exception e)
            {
            }
        }
Example #5
0
        static public void StandartTest()
        {
            // Set Inventor Application and "activate it"
            TrAddInServer.MApp = null;
            inventordoc        = null;
            // Enable error handling.


            TransientBRep oTransBRep = TrAddInServer.MApp.TransientBRep;


            SurfaceBodyDefinition oSurfaceBodyDef = oTransBRep.CreateSurfaceBodyDefinition();

            TransientGeometry oTG = TrAddInServer.MApp.TransientGeometry;


            LumpDefinition oLumpDef = oSurfaceBodyDef.LumpDefinitions.Add();


            FaceShellDefinition oShell = oLumpDef.FaceShellDefinitions.Add();



            // Define the six planes of the box.
            Plane oPosX;
            Plane oNegX;
            Plane oPosY;
            Plane oNegY;
            Plane oPosZ;
            Plane oNegZ;

            oPosX = oTG.CreatePlane(oTG.CreatePoint(1, 0, 0), oTG.CreateVector(1, 0, 0));
            oNegX = oTG.CreatePlane(oTG.CreatePoint(-1, 0, 0), oTG.CreateVector(-1, 0, 0));
            oPosY = oTG.CreatePlane(oTG.CreatePoint(0, 1, 0), oTG.CreateVector(0, 1, 0));
            oNegY = oTG.CreatePlane(oTG.CreatePoint(0, -1, 0), oTG.CreateVector(0, -1, 0));
            oPosZ = oTG.CreatePlane(oTG.CreatePoint(0, 0, 1), oTG.CreateVector(0, 0, 1));
            oNegZ = oTG.CreatePlane(oTG.CreatePoint(0, 0, -1), oTG.CreateVector(0, 0, -1));

            // Create the six faces.
            FaceDefinition oFaceDefPosX;
            FaceDefinition oFaceDefNegX;
            FaceDefinition oFaceDefPosY;
            FaceDefinition oFaceDefNegY;
            FaceDefinition oFaceDefPosZ;
            FaceDefinition oFaceDefNegZ;

            oFaceDefPosX = oShell.FaceDefinitions.Add(oPosX, false);
            oFaceDefNegX = oShell.FaceDefinitions.Add(oNegX, false);
            oFaceDefPosY = oShell.FaceDefinitions.Add(oPosY, false);
            oFaceDefNegY = oShell.FaceDefinitions.Add(oNegY, false);
            oFaceDefPosZ = oShell.FaceDefinitions.Add(oPosZ, false);
            oFaceDefNegZ = oShell.FaceDefinitions.Add(oNegZ, false);

            // Create the vertices.
            VertexDefinition oVertex1;
            VertexDefinition oVertex2;
            VertexDefinition oVertex3;
            VertexDefinition oVertex4;
            VertexDefinition oVertex5;
            VertexDefinition oVertex6;
            VertexDefinition oVertex7;
            VertexDefinition oVertex8;

            oVertex1 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(1, 1, 1));
            oVertex2 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(1, 1, -1));
            oVertex3 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(-1, 1, -1));
            oVertex4 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(-1, 1, 1));
            oVertex5 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(1, -1, 1));
            oVertex6 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(1, -1, -1));
            oVertex7 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(-1, -1, -1));
            oVertex8 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(-1, -1, 1));

            // Define the edges at intersections of the defined planes.
            EdgeDefinition oEdgeDefPosXPosY;
            EdgeDefinition oEdgeDefPosXNegZ;
            EdgeDefinition oEdgeDefPosXNegY;
            EdgeDefinition oEdgeDefPosXPosZ;
            EdgeDefinition oEdgeDefNegXPosY;
            EdgeDefinition oEdgeDefNegXNegZ;
            EdgeDefinition oEdgeDefNegXNegY;
            EdgeDefinition oEdgeDefNegXPosZ;
            EdgeDefinition oEdgeDefPosYNegZ;
            EdgeDefinition oEdgeDefPosYPosZ;
            EdgeDefinition oEdgeDefNegYNegZ;
            EdgeDefinition oEdgeDefNegYPosZ;

            oEdgeDefPosXPosY = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex1, oVertex2, oTG.CreateLineSegment(oVertex1.Position, oVertex2.Position));
            oEdgeDefPosXNegZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex2, oVertex6, oTG.CreateLineSegment(oVertex2.Position, oVertex6.Position));
            oEdgeDefPosXNegY = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex6, oVertex5, oTG.CreateLineSegment(oVertex6.Position, oVertex5.Position));
            oEdgeDefPosXPosZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex5, oVertex1, oTG.CreateLineSegment(oVertex5.Position, oVertex1.Position));
            oEdgeDefNegXPosY = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex4, oVertex3, oTG.CreateLineSegment(oVertex4.Position, oVertex3.Position));
            oEdgeDefNegXNegZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex3, oVertex7, oTG.CreateLineSegment(oVertex3.Position, oVertex7.Position));
            oEdgeDefNegXNegY = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex7, oVertex8, oTG.CreateLineSegment(oVertex7.Position, oVertex8.Position));
            oEdgeDefNegXPosZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex8, oVertex4, oTG.CreateLineSegment(oVertex8.Position, oVertex4.Position));
            oEdgeDefPosYNegZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex2, oVertex3, oTG.CreateLineSegment(oVertex2.Position, oVertex3.Position));
            oEdgeDefPosYPosZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex4, oVertex1, oTG.CreateLineSegment(oVertex4.Position, oVertex1.Position));
            oEdgeDefNegYNegZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex7, oVertex6, oTG.CreateLineSegment(oVertex7.Position, oVertex6.Position));
            oEdgeDefNegYPosZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex5, oVertex8, oTG.CreateLineSegment(oVertex5.Position, oVertex8.Position));

            // Define the loops on the faces.

            EdgeLoopDefinition oPosXLoop = oFaceDefPosX.EdgeLoopDefinitions.Add();

            oPosXLoop.EdgeUseDefinitions.Add(oEdgeDefPosXPosY, true);
            oPosXLoop.EdgeUseDefinitions.Add(oEdgeDefPosXNegZ, true);
            oPosXLoop.EdgeUseDefinitions.Add(oEdgeDefPosXNegY, true);
            oPosXLoop.EdgeUseDefinitions.Add(oEdgeDefPosXPosZ, true);


            EdgeLoopDefinition oNegXLoop = oFaceDefNegX.EdgeLoopDefinitions.Add();

            oNegXLoop.EdgeUseDefinitions.Add(oEdgeDefNegXPosY, false);
            oNegXLoop.EdgeUseDefinitions.Add(oEdgeDefNegXNegZ, false);
            oNegXLoop.EdgeUseDefinitions.Add(oEdgeDefNegXNegY, false);
            oNegXLoop.EdgeUseDefinitions.Add(oEdgeDefNegXPosZ, false);


            EdgeLoopDefinition oPosYLoop = oFaceDefPosY.EdgeLoopDefinitions.Add();

            oPosYLoop.EdgeUseDefinitions.Add(oEdgeDefPosXPosY, false);
            oPosYLoop.EdgeUseDefinitions.Add(oEdgeDefPosYNegZ, false);
            oPosYLoop.EdgeUseDefinitions.Add(oEdgeDefNegXPosY, true);
            oPosYLoop.EdgeUseDefinitions.Add(oEdgeDefPosYPosZ, false);


            EdgeLoopDefinition oNegYLoop = oFaceDefNegY.EdgeLoopDefinitions.Add();

            oNegYLoop.EdgeUseDefinitions.Add(oEdgeDefPosXNegY, false);
            oNegYLoop.EdgeUseDefinitions.Add(oEdgeDefNegYPosZ, false);
            oNegYLoop.EdgeUseDefinitions.Add(oEdgeDefNegXNegY, true);
            oNegYLoop.EdgeUseDefinitions.Add(oEdgeDefNegYNegZ, false);

            EdgeLoopDefinition oPosZLoop = oFaceDefPosZ.EdgeLoopDefinitions.Add();

            oPosZLoop.EdgeUseDefinitions.Add(oEdgeDefNegXPosZ, true);
            oPosZLoop.EdgeUseDefinitions.Add(oEdgeDefNegYPosZ, true);
            oPosZLoop.EdgeUseDefinitions.Add(oEdgeDefPosXPosZ, false);
            oPosZLoop.EdgeUseDefinitions.Add(oEdgeDefPosYPosZ, true);


            EdgeLoopDefinition oNegZLoop = oFaceDefNegZ.EdgeLoopDefinitions.Add();

            oNegZLoop.EdgeUseDefinitions.Add(oEdgeDefNegXNegZ, true);
            oNegZLoop.EdgeUseDefinitions.Add(oEdgeDefNegYNegZ, true);
            oNegZLoop.EdgeUseDefinitions.Add(oEdgeDefPosXNegZ, false);
            oNegZLoop.EdgeUseDefinitions.Add(oEdgeDefPosYNegZ, true);

            //Create a transient surface body.
            NameValueMap oErrors;

            SurfaceBody oNewBody = oSurfaceBodyDef.CreateTransientSurfaceBody(out oErrors);

            // Create client graphics to display the transient body.

            PartDocument oDoc = (PartDocument)TrAddInServer.MApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject);


            PartComponentDefinition oDef = oDoc.ComponentDefinition;


            ClientGraphics oClientGraphics = oDef.ClientGraphicsCollection.Add("Sample3DGraphicsID");

            // Create a new graphics node within the client graphics objects.
            GraphicsNode oSurfacesNode = oClientGraphics.AddNode(1);

            // Create client graphics based on the transient body
            SurfaceGraphics oSurfaceGraphics = oSurfacesNode.AddSurfaceGraphics(oNewBody);

            // Update the view.
            TrAddInServer.MApp.ActiveView.Update();
        }