private void CreateInvLayout() { CreateLayoutPartFile(); Inventor.AssemblyComponentDefinition componentDefinition = InventorServices.Persistence.PersistenceManager.ActiveAssemblyDoc.ComponentDefinition; TransformationMatrix = InventorApplication.TransientGeometry.CreateMatrix(); ComponentOccurrence componentOccurrence = componentDefinition.Occurrences.Add(LayoutPartPath, TransformationMatrix); ComponentOccurrences occurrences = componentDefinition.Occurrences; //TODO This is janky. Don't need to assume that we are starting in an empty assembly file. ComponentOccurrence layoutOccurrence = occurrences[1]; PartComponentDefinition layoutComponentDefinition = (PartComponentDefinition)layoutOccurrence.Definition; for (int i = 0; i < ModulePoints.Count; i++) { WorkPoint workPoint = layoutComponentDefinition.WorkPoints.AddFixed(ModulePoints[i], false); workPoint.Grounded = true; workPoint.Visible = false; //Inventor's API documentation is so bad! object workPointProxyObject; layoutOccurrence.CreateGeometryProxy(workPoint, out workPointProxyObject); LayoutWorkPointProxies.Add((WorkPointProxy)workPointProxyObject); LayoutWorkPoints.Add(workPoint); } LayoutWorkPlane = layoutComponentDefinition.WorkPlanes.AddByThreePoints(layoutWorkPoints[0], layoutWorkPoints[1], layoutWorkPoints[2]); LayoutWorkPlane.Grounded = true; LayoutWorkPlane.Visible = false; object wPlaneProxyObject; layoutOccurrence.CreateGeometryProxy(LayoutWorkPlane, out wPlaneProxyObject); ModuleWorkPlaneProxyAssembly = (WorkPlaneProxy)wPlaneProxyObject; }
public OccurrenceList(AssemblyDocument assDoc) { templateAssemblyDoc = assDoc; ComponentOccurrences topLevelOccurrences = templateAssemblyDoc.ComponentDefinition.Occurrences; EvaluateOccurrences(topLevelOccurrences); }
/// <summary> /// list of occuraces that are not phantom nor are set as referenced in their document settings. /// </summary> /// <param name="targetDoc">the document that needs to be searched for</param> /// <returns>List<ComponentOccurrence></returns> public static List <ComponentOccurrence> AllNonPhantomNonReferencedOccurances(this AssemblyDocument assembly, object targetDoc) { ComponentOccurrences componentOccurrences = assembly.ComponentDefinition.Occurrences; CalculateAllNonPhantomNonReferencedOccurances(componentOccurrences, targetDoc); return(_list); }
private int GetOccurances(Document doc, ComponentOccurrences occurances) { int numOccurances = 0; foreach (ComponentOccurrence occurance in occurances) { string partName = occurance.Name; if (occurance.Name.Contains(':')) { partName = (occurance.Name).Substring(0, (occurance.Name).LastIndexOf(':')); } else if (occurance.Name.Contains('_')) { partName = (occurance.Name).Substring(0, (occurance.Name).LastIndexOf('_')); } else if (occurance.Name.Contains('-')) { partName = (occurance.Name).Substring(0, (occurance.Name).LastIndexOf('-')); } if (partName == doc.DisplayName) { numOccurances++; } } return(numOccurances); }
public ComponentOccurrence FindComponentOccurrence(ComponentOccurrences Comp, string name) { foreach (ComponentOccurrence occur in Comp) { if (occur.Name.IndexOf(name) >= 0) { return(occur); } } return(null); }
//Builds the Assembly, Part and Sheetmetal part objects using recursion public void TraverseAssembly(AssemblyDocument currentAsmDocument, int parentID) { int currentID = GetAssemblyID(); //to stop instantiating a new instance of Assembly with a null AssemblyDocument - should never happen anyway if (currentAsmDocument == null) { return; } Assembly assembly = NewAssembly(currentAsmDocument, parentID, currentID); EventLogger.CreateLogEntry($"Processing assembly document {assembly.AssemblyDocument.DisplayName}"); AssemblyList.Add(assembly); ComponentOccurrences occurrences = currentAsmDocument.ComponentDefinition.Occurrences; noOccurrences += occurrences.Count; EventLogger.CreateLogEntry($"Current part count {noOccurrences}"); foreach (ComponentOccurrence occurrence in occurrences) { //the UI layer is listening for this Event to increment the progress bar IncrementProgressBar(); if (DocumentInfo.IsPartDocument(occurrence.DefinitionDocumentType)) { PartDocument partDocument = (PartDocument)occurrence.Definition.Document; EventLogger.CreateLogEntry($"processing part document {partDocument.DisplayName}"); if (DocumentInfo.IsSheetMetalPart(partDocument.SubType)) { assembly.SheetmetalPartList.Add(NewSheetMetalPart(partDocument)); } else { assembly.PartList.Add(NewPart(partDocument)); } } if (DocumentInfo.IsAssemblyDocument(occurrence.DefinitionDocumentType)) { AssemblyDocument subAssemblyDocument = (AssemblyDocument)occurrence.Definition.Document; TraverseAssembly(subAssemblyDocument, assembly.ID); } } }
/// <summary> /// Gets all the components in the active assembly /// </summary> /// <param name="occurrences"></param> /// <param name="recurse"></param> public void GetComponents(ComponentOccurrences occurrences, bool recurse) { foreach (ComponentOccurrence c in occurrences) { Add(new InventorComponent(c)); if (recurse) { if (c.Definition.Type == ObjectTypeEnum.kAssemblyComponentDefinitionObject || c.Definition.Type == ObjectTypeEnum.kWeldmentComponentDefinitionObject) { GetComponents(occurrences, recurse); } } } }
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 static void CalculateAllNonPhantomNonReferencedOccurances(ComponentOccurrences componentOccurrences, object targetDoc) { foreach (ComponentOccurrence occurrence in componentOccurrences) { if (occurrence.Definition.BOMStructure != BOMStructureEnum.kReferenceBOMStructure && occurrence.Definition.BOMStructure != BOMStructureEnum.kPhantomBOMStructure) { if (occurrence.Definition.Document == targetDoc) { _list.Add(occurrence); } else if (occurrence.DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { CalculateAllNonPhantomNonReferencedOccurances(occurrence.Definition.Occurrences, targetDoc); } } } }
public void EvaluateOccurrences(ComponentOccurrences componentOccurrences) { for (int i = 0; i < componentOccurrences.Count; i++) { if (componentOccurrences[i + 1].DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { occurrencesList.Add(componentOccurrences[i + 1]); EvaluateOccurrences((ComponentOccurrences)componentOccurrences[i + 1].SubOccurrences); } else if (componentOccurrences[i + 1].DefinitionDocumentType != DocumentTypeEnum.kAssemblyDocumentObject) { occurrencesList.Add(componentOccurrences[i + 1]); } else { continue; } } }
private void IterateAssemblyRecursive(ComponentOccurrences occurrences) { try { foreach (ComponentOccurrence occurrence in occurrences) { if (occurrence.DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { ChangeProperties(occurrence); IterateAssemblyRecursive((ComponentOccurrences)occurrence.SubOccurrences); } else if ((occurrence.DefinitionDocumentType == DocumentTypeEnum.kPartDocumentObject)) { ChangeProperties(occurrence); } } } catch (Exception ex) { MessageBox.Show(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name, MessageBoxButton.OK); } }
/// <summary> /// list of occuraces that are not phantom or referenced in their document settings. /// </summary> /// <param name="targetDoc">the document that needs to be searched for</param> /// <returns>List<ComponentOccurrence></returns> public static List <ComponentOccurrence> AllNonPhantomNonReferencedOccurances(this ComponentOccurrences componentOccurrences, object targetDoc) { CalculateAllNonPhantomNonReferencedOccurances(componentOccurrences, targetDoc); return(_list); }
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 CostOf(Document bomItem) { double mass; string material; if (bomItem.DocumentType == DocumentTypeEnum.kPartDocumentObject) { PartDocument partDoc = (PartDocument)bomItem; PartComponentDefinition partCompDef = partDoc.ComponentDefinition; PropertySets propertySets = partDoc.PropertySets; PropertySet propertySet = propertySets["Design Tracking Properties"]; Property costProp = propertySet["Cost"]; if (partCompDef.BOMStructure == BOMStructureEnum.kPurchasedBOMStructure || partCompDef.BOMStructure == BOMStructureEnum.kInseparableBOMStructure) { cost = Convert.ToDouble(costProp.Value); // purchasedCost = Convert.ToDouble(costProp.Value); Marshal.ReleaseComObject(costProp); costProp = null; Marshal.ReleaseComObject(propertySet); propertySet = null; Marshal.ReleaseComObject(propertySets); propertySets = null; Marshal.ReleaseComObject(partCompDef); partCompDef = null; Marshal.ReleaseComObject(partDoc); partDoc = null; return; } Property materialProp = propertySet["Material"]; // Mass of Part mass = partCompDef.MassProperties.Mass; // Material of Part if (materialProp.Value.ToString().Contains("MESH")) { material = "MESH"; } else if (materialProp.Value.ToString().Contains("EXPANDED METAL")) { material = "EXPANDED METAL"; } else { material = materialProp.Value.ToString(); } // Cost try { // Multiple by 2.20462262 for kg to lbs conversion cost = mass * 2.20462262 * materialMap[material]; } catch (Exception) { cost = 0.0; } costProp.Value = cost; // Set Estimated Cost Marshal.ReleaseComObject(materialProp); materialProp = null; Marshal.ReleaseComObject(costProp); costProp = null; Marshal.ReleaseComObject(propertySet); propertySet = null; Marshal.ReleaseComObject(propertySets); propertySets = null; Marshal.ReleaseComObject(partCompDef); partCompDef = null; Marshal.ReleaseComObject(partDoc); partDoc = null; return; } foreach (Document nestedAsm in bomItem.ReferencedDocuments) { CostOf(nestedAsm); } if (bomItem.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { cost = 0; AssemblyDocument assemblyDoc = (AssemblyDocument)bomItem; PropertySets assemblySets = assemblyDoc.PropertySets; PropertySet assemblySet = assemblySets["Design Tracking Properties"]; Property asmCost = assemblySet["Cost"]; AssemblyComponentDefinition asmCompDef = assemblyDoc.ComponentDefinition; ComponentOccurrences occurances = asmCompDef.Occurrences; foreach (Document nestedPart in bomItem.ReferencedDocuments) { try { PropertySets propertySets = nestedPart.PropertySets; PropertySet propertySet = propertySets["Design Tracking Properties"]; Property costProp = propertySet["Cost"]; cost = cost + Convert.ToDouble(costProp.Value.ToString()) * GetOccurances(nestedPart, occurances); Marshal.ReleaseComObject(costProp); costProp = null; Marshal.ReleaseComObject(propertySet); propertySet = null; Marshal.ReleaseComObject(propertySets); propertySets = null; } catch { continue; } } asmCost.Value = cost; Marshal.ReleaseComObject(occurances); occurances = null; Marshal.ReleaseComObject(asmCompDef); asmCompDef = null; Marshal.ReleaseComObject(asmCost); asmCost = null; Marshal.ReleaseComObject(assemblySet); assemblySet = null; Marshal.ReleaseComObject(assemblySets); assemblySets = null; Marshal.ReleaseComObject(assemblyDoc); assemblyDoc = null; } }
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); }