public EditCoordinate() { InitializeComponent(); oTG = StandardAddInServer.m_inventorApplication.TransientGeometry; oTranslationMatrix = oTG.CreateMatrix(); oMatrix = oTG.CreateMatrix(); }
/// <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)); }
} //Main form closing private void assemble() { try { path = var_es._Doc.FullFileName.Remove(var_es._Doc.FullFileName.Length - 4); //создаём новый AssemblyDocument assemb_doc = (AssemblyDocument)var_es.InventorApp.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, var_es.InventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kAssemblyDocumentObject), false); AssemblyComponentDefinition assemb_doc_Comp = assemb_doc.ComponentDefinition; //сохраняем созданий AssemblyDocument assemb_doc.SaveAs(path + @"/Shaft.iam", true); //Создаём матрицу TransientGeometry TG = var_es.InventorApp.TransientGeometry; Matrix matrix = TG.CreateMatrix(); //привязываем наш AssemblyDocument в браузере к AssemblyDocument, который открыл пользователь var_es.part_doc = (PartDocument)var_es.InventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, var_es.InventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true); PartComponentDefinition doc_def = var_es.part_doc.ComponentDefinition; } catch (Exception e3) { MessageBox.Show(e3.ToString()); } }
public void ChangeView(double gyroY, double gyroX, double gyroZ, bool apply) { Inventor.Vector screenX = null; Inventor.Vector screenY = null; Inventor.Vector screenZ = null; screenZ = oCamera.Target.VectorTo(oCamera.Eye); screenZ.Normalize(); screenY = oCamera.UpVector.AsVector(); screenX = screenY.CrossProduct(screenZ); Inventor.Matrix rotX = oTG.CreateMatrix(); rotX.SetToRotation(gyroX, screenX, oCamera.Target); Inventor.Matrix rotY = oTG.CreateMatrix(); rotY.SetToRotation(gyroY, screenY, oCamera.Target); Inventor.Matrix rotZ = oTG.CreateMatrix(); rotZ.SetToRotation(gyroZ, screenZ, oCamera.Target); Inventor.Matrix rot = oTG.CreateMatrix(); rot = rotX; rot.PostMultiplyBy(rotY); rot.PostMultiplyBy(rotZ); Inventor.Point newEye = oCamera.Eye; newEye.TransformBy(rot); Inventor.UnitVector newUp = oCamera.UpVector; newUp.TransformBy(rot); oCamera.Eye = newEye; oCamera.UpVector = newUp; if (apply) { oCamera.Apply(); } else { oCamera.ApplyWithoutTransition(); } }
//Main form Buttons #region Buttons //ok button private void button2_Click(object sender, EventArgs e) { try { var_es.part_doc.SaveAs(path + @"/Shaft.ipt", true); TransientGeometry TG = var_es.InventorApp.TransientGeometry; Matrix matrix = TG.CreateMatrix(); ComponentOccurrence Shaft1 = var_es._Doc.ComponentDefinition.Occurrences.Add(path + @"/Shaft.ipt", matrix); //ComponentOccurrence Shaft = var_es._Doc.ComponentDefinition.Occurrences.Add(path + @"/Shaft.iam", matrix); var_es.part_doc.Close(true); Close(); } catch { } }
public void AddiAssemblyOccurrence() { AssemblyDocument oDoc = (AssemblyDocument)_InvApplication.ActiveDocument; AssemblyComponentDefinition oDef = oDoc.ComponentDefinition; ComponentOccurrences oOccurrences = oDef.Occurrences; TransientGeometry oTG = _InvApplication.TransientGeometry; Matrix oPos = default(Matrix); oPos = oTG.CreateMatrix(); ComponentOccurrence oNewOcc; //Row specified either by a Long (row index), String (MemberName), or iAssemblyTableRow. oNewOcc = oOccurrences.AddiAssemblyMember("C:\\MyiAsm.iam", oPos, 1); oNewOcc = oOccurrences.AddiAssemblyMember("C:\\MyiAsm.iam", oPos, "MemberName"); }
private void ButtonAssemble_Click(object sender, EventArgs e) { AssemblyDocument AssDoc = (AssemblyDocument)ThisApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kAssemblyDocumentObject)); AssemblyComponentDefinition oAssCompDef = AssDoc.ComponentDefinition; AssDoc.DisplayName = "Сборка"; TransientGeometry aTransGeom = ThisApplication.TransientGeometry; Matrix oPositionMatrix = aTransGeom.CreateMatrix(); ComponentOccurrence IN_Ring; ComponentOccurrence Av_Ring; try { Savers("Первая деталь"); IN_Ring = AssDoc.ComponentDefinition.Occurrences.Add(FileName["Первая деталь"], oPositionMatrix); Savers("Вторая деталь"); Av_Ring = AssDoc.ComponentDefinition.Occurrences.Add(FileName["Вторая деталь"], oPositionMatrix); } catch { return; } //Переменные для выбранных поверхностей Face oFace1, oFace2; //Вставка изменения программного кода oFace1 = IN_Ring.SurfaceBodies[1].Faces[10]; oFace2 = Av_Ring.SurfaceBodies[1].Faces[12]; //Конец вставки изменения программного кода //Переменные для сопряжений MateConstraint Поверхность; //Сопряжение поверхностей Поверхность = oAssCompDef.Constraints.AddMateConstraint(oFace1, oFace2, 0, InferredTypeEnum.kNoInference, InferredTypeEnum.kNoInference); AssemblyDocName = AssDoc; }
public void RunWithArguments(Document doc, NameValueMap map) { // map["_1"] contains absolute path to configuration json // map["_2"] contains absolute path to folder with module STEP (or other types of) files // map["_3"] (optional) contains relative path to assembly to open /* Sample json structure * [ * { "path": "some\\path\\to\\enclosure.iam", * "xform": [ * 1, 0, 0, 10, * 0, 1, 0, 0, * 0, 0, 1, 0, * 0, 0, 0, 1 * ] * }, * { "path": "some\\path\\to\\part.ipt", * "xform": [ * 1, 0, 0, 10, * 0, 1, 0, 20, * 0, 0, 1, 30, * 0, 0, 0, 1 * ] * } * ] */ try { using (new HeartBeat(30000)) { string currentDir = System.IO.Directory.GetCurrentDirectory(); LogTrace("Parsing configuration"); string json = System.IO.File.ReadAllText((string)map.Value["_1"]); List <ConfigEntry> config = JsonConvert.DeserializeObject <List <ConfigEntry> >(json); string modulesDir = (string)map.Value["_2"]; LogTrace("Assembling modules"); doc = inventorApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, "", false); // Let's save it (and provide file name for it) befroe doing anything else with it // If we tried to do it in the end with 2022 engine, we'd get an error var assemblyPath = System.IO.Path.Combine(modulesDir, "template.iam"); doc.SaveAs(assemblyPath, false); AssemblyDocument asmDoc = doc as AssemblyDocument; // Add Design View representation in case we need it DesignViewRepresentation dvr = asmDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add("Default"); dvr.Activate(); AssemblyComponentDefinition compDef = asmDoc.ComponentDefinition; TransientGeometry geom = inventorApplication.TransientGeometry; Matrix matrix; var moduleOccurrences = new Dictionary <string, ComponentOccurrence>(); foreach (var entry in config) { LogTrace("Module {0} ({1})", entry.Path, String.Join(", ", entry.Xform)); try { matrix = geom.CreateMatrix(); matrix.PutMatrixData(entry.Xform); ComponentOccurrence compOcc = null; if (moduleOccurrences.ContainsKey(entry.Path)) { compOcc = compDef.Occurrences.AddByComponentDefinition(moduleOccurrences[entry.Path].Definition, matrix); } else { var modulePath = System.IO.Path.Combine(modulesDir, entry.Path); if (IsInventorDocument(modulePath)) { string dvRep = null; string lodRep = null; if (IsAssemblyDocument(modulePath)) { dvRep = inventorApplication.FileManager.GetLastActiveDesignViewRepresentation(modulePath); lodRep = inventorApplication.FileManager.GetLastActiveLevelOfDetailRepresentation(modulePath); } compOcc = compDef.Occurrences.Add(modulePath, matrix); if (dvRep != null) { compOcc.SetDesignViewRepresentation(dvRep); } if (lodRep != null) { compOcc.SetLevelOfDetailRepresentation(lodRep); } } else { // Create the ImportedGenericComponentDefinition bases on an Alias file LogTrace("Path of module: {0}", modulePath); dynamic oImportedGenericCompDef = compDef.ImportedComponents.CreateDefinition(modulePath); // Set the ReferenceModel to associatively import the Alias file oImportedGenericCompDef.ReferenceModel = true; // Import the Solidworks to assembly var oImportedComp = compDef.ImportedComponents.Add(oImportedGenericCompDef); // Not doing an Update afetr adding a SolidWorks assembly can cause problems asmDoc.Update2(); compOcc = compDef.Occurrences[compDef.Occurrences.Count]; compOcc.Transformation = matrix; } moduleOccurrences.Add(entry.Path, compOcc); } // Debugging dynamic defDoc = compOcc.Definition.Document; var occurrencePath = defDoc.FullFileName; LogTrace("Path of added occurrence: {0}", occurrencePath); } catch (Exception e) { LogTrace("Cannot add file {0}: {1}", entry.Path, e.Message); } } LogTrace("Finishing assembly"); doc.Update(); LogTrace("Saving assembly"); doc.Save2(); var rfaPath = System.IO.Path.Combine(currentDir, "output.rfa"); ExportRFA(doc, rfaPath); /* * LogTrace("Copying referenced documents to working folder"); * foreach(dynamic rf in doc.File.AllReferencedFiles) * { * var oldPath = rf.FullFileName; * var docName = System.IO.Path.GetFileName(oldPath); * var newPath = System.IO.Path.Combine(documentDir, docName); * System.IO.File.Copy(oldPath, newPath, true); * } */ LogTrace("Compressing output"); using (var archive = ZipFile.Open("output.zip", ZipArchiveMode.Create)) { archive.CreateEntryFromFile(assemblyPath, System.IO.Path.GetFileName(assemblyPath)); foreach (dynamic rf in doc.File.AllReferencedFiles) { string fileName = rf.FullFileName; archive.CreateEntryFromFile(fileName, System.IO.Path.GetFileName(fileName)); } } LogTrace("Closing assembly"); doc.Close(true); /* * LogTrace("Compressing output"); * using (var archive = ZipFile.Open(System.IO.Path.Combine(documentDir, "output.zip"), ZipArchiveMode.Create)) * { * foreach (var entry in System.IO.Directory.EnumerateFiles(documentDir)) * { * if (entry.EndsWith(".ipt") || entry.EndsWith(".iam")) * { * archive.CreateEntryFromFile(entry, System.IO.Path.GetFileName(entry)); * } * } * } */ } } catch (Exception e) { LogError("Processing failed. " + e.ToString()); } }
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"); }
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); }