Ejemplo n.º 1
0
        /// <summary>
        /// Inserts a member (part/Subassembly or 3D model) in assembly and returns the created occurance
        /// </summary>
        /// <param name="assy"></param>
        /// <param name="inventor">inventor assembly</param>
        /// <param name="member">any of the supported <see cref="Document"/> types to insert into assembly</param>
        /// <param name="position">position of the member relative to assembly's origin</param>
        /// <param name="rotation">rotation about the X and Y and Z axis</param>
        /// <returns><see cref="ComponentOccurrence"/> that is created inside the assembly</returns>
        /// <remarks>remeber that Inventors internal units for length are centimeters</remarks>
        public static ComponentOccurrence AddMemeber(this AssemblyDocument assy, Application inventor, Document member, double[] position, double[] rotation)
        {
            if (member.DocumentType == DocumentTypeEnum.kDrawingDocumentObject ||
                member.DocumentType == DocumentTypeEnum.kNoDocument ||
                member.DocumentType == DocumentTypeEnum.kPresentationDocumentObject ||
                member.DocumentType == DocumentTypeEnum.kUnknownDocumentObject)
            {
                throw new ArgumentException("documnet type is not supported", nameof(member));
            }

            if (member.FullFileName == "")
            {
                throw new Exception("FullFileName of the part object was null, you need to save the part before passing to this method");
            }

            if (position.Length > 3 || rotation.Length > 3)
            {
                throw new ArgumentOutOfRangeException("position or rotaion array cannot have more than three memebers");
            }

            // Set a reference to the assembly component definition.
            AssemblyComponentDefinition oAsmCompDef = assy.ComponentDefinition;

            // Set a reference to the transient geometry object.
            TransientGeometry oTG = inventor.TransientGeometry;

            // Create a matrix.  A new matrix is initialized with an identity matrix.
            Matrix tempMatrix  = oTG.CreateMatrix();
            Matrix transMatrix = oTG.CreateMatrix();

            //for all rotational directions . . .
            for (int i = 0; i < rotation.Length; i++)
            {
                var index = new List <int>(new[] { 0, 0, 0 });
                index[i] = 1;
                var origin = oTG.CreatePoint(0, 0, 0);

                //rotate about an axis that goeas through origin point and is along the rotaional direction
                tempMatrix.SetToRotation(MathHelper.ToRadian(rotation[i]), oTG.CreateVector(index[0], index[1], index[2]), origin);
                transMatrix.TransformBy(tempMatrix);
                tempMatrix.SetToIdentity();
            }

            //move the object to the position
            transMatrix.SetTranslation(oTG.CreateVector(position[0], position[1], position[2]));

            // Add the occurrence.
            return(oAsmCompDef.Occurrences.Add(member.FullFileName, transMatrix));
        }
Ejemplo n.º 2
0
        private void textBoxX_TextChanged(object sender, EventArgs e)
        {
            double XTranform = 0;

            try
            {
                XTranform = Convert.ToDouble(textBoxX.Text);
            }
            catch (Exception)
            {
                if (textBoxX.Text.Length > 0 && !textBoxX.Text.Equals("-"))
                {
                    MessageBox.Show("warning, incorrect input");
                }
            }
            oTranslationMatrix.SetTranslation(oTG.CreateVector(XTranform, UCS.Transformation.Translation.Y, UCS.Transformation.Translation.Z));
            UCS.Definition.Transformation = oTranslationMatrix;
        }
Ejemplo n.º 3
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Set position of a GraphicsNode
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        void SetNodePosition(GraphicsNode node, Point position)
        {
            Matrix transfo = node.Transformation;

            Vector Tx = _Tg.CreateVector(
                position.X, position.Y, position.Z);

            transfo.SetTranslation(Tx, false);

            node.Transformation = transfo;
        }
Ejemplo n.º 4
0
 static public Vector CV(double x = 0, double y = 0, double z = 0)
 {
     return(tg.CreateVector(x, y, z));
 }
Ejemplo n.º 5
0
        public void RunWithArguments(Document doc, NameValueMap map)
        {
            LogTrace("Initialiting");
            PartDocument oPartDoc = (PartDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true);

            LogTrace("Part template opened");
            TransientGeometry       oTG         = inventorApplication.TransientGeometry;
            PartComponentDefinition oPartComDef = oPartDoc.ComponentDefinition;
            UserParameters          oParams     = oPartComDef.Parameters.UserParameters;

            XmlDocument xmlDoc     = new XmlDocument();
            string      currentDir = System.IO.Directory.GetCurrentDirectory();
            string      projectDir = Directory.GetParent(currentDir).Parent.FullName;

            LogTrace("Reading XML input file from " + projectDir);
            xmlDoc.Load(System.IO.Path.Combine(projectDir, "react-test-output.xml"));
            //xmlDoc.Load("react-test-output.xml");
            //xmlDoc.Load("C:\\webapps\\IpartCreator\\React-BIM-output.xml");
            XmlNodeList FloorList      = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor");
            XmlNodeList FloorPointList = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point");
            XmlNodeList ComponentName  = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/ComponentName");
            XmlNodeList PointX         = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point/X");
            XmlNodeList PointY         = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point/Y");
            XmlNodeList PointZ         = xmlDoc.DocumentElement.SelectNodes("/Building/Floors/Floor/BoundaryPoints/Point/Z");



            for (int i = 0; i < FloorList.Count; i++)
            {
                //oParams.AddByExpression("ComponentName" + i, ComponentName[i].InnerText, UnitsTypeEnum.kUnitlessUnits);


                int numPoint = FloorPointList.Count / FloorList.Count;

                Point2d[]     oPoints  = new Point2d[numPoint];
                SketchPoint[] osPoints = new SketchPoint[numPoint];

                for (int j = 0; j < numPoint; j++)
                {
                    oParams.AddByExpression("PointX" + j, PointX[j].InnerText, UnitsTypeEnum.kMillimeterLengthUnits);
                    oParams.AddByExpression("PointY" + j, PointY[j].InnerText, UnitsTypeEnum.kMillimeterLengthUnits);
                    oParams.AddByExpression("PointZ" + j, PointZ[j].InnerText, UnitsTypeEnum.kMillimeterLengthUnits);

                    oPoints[j] = oTG.CreatePoint2d(oPartComDef.Parameters.GetValueFromExpression("PointX" + j, UnitsTypeEnum.kMillimeterLengthUnits), oPartComDef.Parameters.GetValueFromExpression("PointY" + j, UnitsTypeEnum.kMillimeterLengthUnits));
                }

                SketchLine[] oLines  = new SketchLine[numPoint];
                PlanarSketch oSketch = oPartComDef.Sketches.Add(oPartComDef.WorkPlanes[2]);
                osPoints[0] = oSketch.SketchPoints.Add(oPoints[0]);
                osPoints[1] = oSketch.SketchPoints.Add(oPoints[1]);
                osPoints[2] = oSketch.SketchPoints.Add(oPoints[2]);
                osPoints[3] = oSketch.SketchPoints.Add(oPoints[3]);

                oLines[0] = oSketch.SketchLines.AddByTwoPoints(osPoints[0], osPoints[1]);
                oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, osPoints[2]);
                oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, osPoints[3]);
                oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oLines[0].StartSketchPoint);

                oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[0], osPoints[1], DimensionOrientationEnum.kAlignedDim, oPoints[1]); //d0//
                oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[1], osPoints[2], DimensionOrientationEnum.kAlignedDim, oPoints[3]); //d1//

                Profile           oProfile    = oSketch.Profiles.AddForSolid();
                ExtrudeDefinition oExtrudeDef = oPartComDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation);
                oExtrudeDef.SetDistanceExtent(oPartComDef.Parameters.UserParameters.AddByExpression("length", "8", UnitsTypeEnum.kMillimeterLengthUnits), PartFeatureExtentDirectionEnum.kPositiveExtentDirection);
                ExtrudeFeature oExtrude = oPartComDef.Features.ExtrudeFeatures.Add(oExtrudeDef);

                string PartPath = projectDir + "/results/" + ComponentName[i].InnerText + i + ".ipt";
                //string PartPath = ComponentName[i].InnerText + i + ".ipt";
                oPartDoc.SaveAs(PartPath, false);

                oExtrude.Delete();
            }

            oPartDoc.Close(false);

            AssemblyDocument            oAssyDoc      = (AssemblyDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kAssemblyDocumentObject), true);
            AssemblyComponentDefinition oAssyComDef   = oAssyDoc.ComponentDefinition;
            ComponentOccurrences        oAssyCompOccs = oAssyComDef.Occurrences;
            Matrix oPos  = oTG.CreateMatrix();
            int    oStep = 0;
            int    icomp;
            int    numite = FloorPointList.Count / FloorList.Count;

            for (icomp = 0; icomp <= numite; icomp++)
            {
                oStep = oStep + 150;
                oPos.SetTranslation(oTG.CreateVector(oStep, oStep, 0), false);
                string PartPath = projectDir + "/results/" + ComponentName[icomp].InnerText + icomp + ".ipt";
                //string PartPath = ComponentName[icomp].InnerText + icomp + ".ipt";
                ComponentOccurrence oOcc = oAssyCompOccs.Add(PartPath, oPos);
            }

            oAssyDoc.SaveAs(projectDir + "/results/result.iam", false);
            //oAssyDoc.SaveAs("result.iam", false);
            oAssyDoc.Close();
            ZipFile.CreateFromDirectory(projectDir + "/results", projectDir + "/forgeResult.zip");
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
        public void RunWithArguments(Document doc, NameValueMap map)
        {
            //LogTrace("Processing " + doc.FullFileName);

            //try
            //{
            //    if (doc.DocumentType == DocumentTypeEnum.kPartDocumentObject)
            //    {
            //        using (new HeartBeat())
            //        {
            //            // TODO: handle the Inventor part here
            //        }
            //    }
            //    else if (doc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) // Assembly.
            //    {
            //        using (new HeartBeat())
            //        {
            //            // TODO: handle the Inventor assembly here
            //        }
            //    }
            //}
            //catch (Exception e)
            //{
            //    LogError("Processing failed. " + e.ToString());
            //}
            LogTrace("Initialiting");
            PartDocument oPartDoc = (PartDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true);

            LogTrace("Part template opened");
            TransientGeometry       oTG         = inventorApplication.TransientGeometry;
            PartComponentDefinition oPartComDef = oPartDoc.ComponentDefinition;
            UserParameters          oParams     = oPartComDef.Parameters.UserParameters;

            oParams.AddByExpression("width", "50", UnitsTypeEnum.kMillimeterLengthUnits);
            oParams.AddByExpression("height", "10", UnitsTypeEnum.kMillimeterLengthUnits);
            oParams.AddByExpression("length", "10", UnitsTypeEnum.kMillimeterLengthUnits);
            LogTrace("Standard parameters created");


            Point2d[] oPoints = new Point2d[4];


            oPoints[0] = oTG.CreatePoint2d(0, 0);
            oPoints[1] = oTG.CreatePoint2d(0, oPartComDef.Parameters.GetValueFromExpression("width", UnitsTypeEnum.kMillimeterLengthUnits));
            oPoints[2] = oTG.CreatePoint2d(oPartComDef.Parameters.GetValueFromExpression("height", UnitsTypeEnum.kMillimeterLengthUnits), 0);
            oPoints[3] = oTG.CreatePoint2d(oPartComDef.Parameters.GetValueFromExpression("height", UnitsTypeEnum.kMillimeterLengthUnits), oPartComDef.Parameters.GetValueFromExpression("width", UnitsTypeEnum.kMillimeterLengthUnits));
            LogTrace("Inventor points created");
            LogTrace("Initiating sketch creation...");
            PlanarSketch oSketch = oPartComDef.Sketches.Add(oPartComDef.WorkPlanes[1]);

            SketchPoint[] osPoints = new SketchPoint[4];
            SketchLine[]  oLines   = new SketchLine[4];

            osPoints[0] = oSketch.SketchPoints.Add(oPoints[0]);
            osPoints[1] = oSketch.SketchPoints.Add(oPoints[1]);
            osPoints[2] = oSketch.SketchPoints.Add(oPoints[2]);
            osPoints[3] = oSketch.SketchPoints.Add(oPoints[3]);

            oLines[0] = oSketch.SketchLines.AddByTwoPoints(osPoints[0], osPoints[1]);
            oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, osPoints[3]);
            oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, osPoints[2]);
            oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oLines[0].StartSketchPoint);
            LogTrace("Sketch created, adding dimensions");
            oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[0], osPoints[1], DimensionOrientationEnum.kAlignedDim, oPoints[1]); //d0//
            oSketch.DimensionConstraints.AddTwoPointDistance(osPoints[1], osPoints[3], DimensionOrientationEnum.kAlignedDim, oPoints[3]); //d1//
            LogTrace("Dimensions added to the sketch, changing standard values for User parameter values");

            var inventorMParams = oPartComDef.Parameters.ModelParameters;

            foreach (ModelParameter mParam in inventorMParams)
            {
                if (mParam.Name.Contains("d0"))
                {
                    mParam.Expression = "width";
                }
                else if (mParam.Name.Contains("d1"))
                {
                    mParam.Expression = "height";
                }
            }

            LogTrace("Dimensions with user parameter values created, starting extrude operation");

            //oSketch.DimensionConstraints.AddTwoPointDistance(oPoints[0], oPoints[1], DimensionOrientationEnum.kAlignedDim, "width", true);
            Profile oProfile = oSketch.Profiles.AddForSolid();

            ExtrudeDefinition oExtrudeDef = oPartComDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation);

            oExtrudeDef.SetDistanceExtent(oPartComDef.Parameters.UserParameters.AddByExpression("length", "length", UnitsTypeEnum.kMillimeterLengthUnits), PartFeatureExtentDirectionEnum.kPositiveExtentDirection);

            ExtrudeFeature oExtrude = oPartComDef.Features.ExtrudeFeatures.Add(oExtrudeDef);

            //oExtrude.FeatureDimensions[1].Parameter.Name = "length";
            LogTrace("Extrude operation finished");
            XmlDocument xmlDoc     = new XmlDocument();
            string      currentDir = System.IO.Directory.GetCurrentDirectory();
            string      projectDir = Directory.GetParent(currentDir).Parent.FullName;

            LogTrace("Reading XML input file from " + projectDir);
            xmlDoc.Load(System.IO.Path.Combine(projectDir, "React-BIM-output.xml"));
            //xmlDoc.Load("C:\\webapps\\IpartCreator\\React-BIM-output.xml");
            XmlNodeList memberNodeList     = xmlDoc.GetElementsByTagName("Member");
            XmlNodeList partNumberNodeList = xmlDoc.GetElementsByTagName("PartNumber");
            XmlNodeList widthNodeList      = xmlDoc.GetElementsByTagName("width");
            XmlNodeList heightNodeList     = xmlDoc.GetElementsByTagName("height");
            XmlNodeList lengthNodeList     = xmlDoc.GetElementsByTagName("length");

            LogTrace("XML tag values imported");
            LogTrace("Creating iPart");
            iPartFactory oFactory = oPartComDef.CreateFactory();
            Worksheet    oWS      = oFactory.ExcelWorkSheet;
            Workbook     oWB      = (Workbook)oWS.Parent;

            LogTrace("Generating Excel file for iPart");
            oWS.Cells[1, 1] = "Member<defaultRow>1</defaultRow><filename></filename>";
            oWS.Cells[1, 2] = "Part Number [Project]";
            oWS.Cells[1, 3] = "width";
            oWS.Cells[1, 4] = "height";
            oWS.Cells[1, 5] = "length";

            for (int i = 0; i < memberNodeList.Count; i++)
            {
                oWS.Cells[(i + 2), 1] = memberNodeList[i].InnerText;
                oWS.Cells[(i + 2), 2] = partNumberNodeList[i].InnerText;
                oWS.Cells[(i + 2), 3] = widthNodeList[i].InnerText;
                oWS.Cells[(i + 2), 4] = heightNodeList[i].InnerText;
                oWS.Cells[(i + 2), 5] = lengthNodeList[i].InnerText;
            }



            oWB.Save();
            oWB.Close();
            LogTrace("Excel created");
            oPartDoc.Update();
            string iPartPath = projectDir + "/results/bimipart.ipt";
            int    iNumRows  = oFactory.TableRows.Count;

            LogTrace("Saving iPart to " + iPartPath);
            oPartDoc.SaveAs(iPartPath, false);

            LogTrace("Opening new assembly template");
            AssemblyDocument            oAssyDoc      = (AssemblyDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kAssemblyDocumentObject), true);
            AssemblyComponentDefinition oAssyComDef   = oAssyDoc.ComponentDefinition;
            ComponentOccurrences        oAssyCompOccs = oAssyComDef.Occurrences;

            LogTrace("Creating Matrix");
            Matrix oPos  = oTG.CreateMatrix();
            int    oStep = 0;
            int    iRow;

            LogTrace("Placing iPart members to assembly");
            for (iRow = 1; iRow <= iNumRows; iRow++)
            {
                oStep = oStep + 150;

                oPos.SetTranslation(oTG.CreateVector(oStep, oStep, 0), false);
                ComponentOccurrence oOcc = oAssyCompOccs.AddiPartMember(iPartPath, oPos, iRow);
            }
            string assyPath = projectDir + "/results/bimassy.iam";

            LogTrace("Saving Assembly file to " + assyPath);
            oAssyDoc.SaveAs(assyPath, false);
        }