Exemple #1
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();
        }