public Assembly(AssemblyDocument assemblyDocument) { if (assemblyDocument == null) throw new ArgumentNullException(nameof(assemblyDocument)); Document = assemblyDocument; SetCustomPropertyFormat(CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision, showTrailingZeros: false); }
public void Show(AssemblyDocument assembly, List<Part> parts) { if (parts == null || parts.Count == 0) return; using (var comparer = new HumanReadableStringComparer()) { ViewModel.Assembly = assembly; ViewModel.Parts = parts.OrderBy(x => x.Name, comparer).ToList(); } base.Show(); }
public InventorController() { isConstructed=false; try { inventorApplication = (Inventor.Application) System.Runtime.InteropServices.Marshal. GetActiveObject("Inventor.Application"); assemblyDoc = (AssemblyDocument)inventorApplication.ActiveDocument; assemblyComp = assemblyDoc.ComponentDefinition; parameterList = getParameterList(); isConstructed = true; createConstraintList(); } catch (Exception ex) { System.Diagnostics.Debug.Write(ex.Message); return; } isConstructed = true; }
static void TestDocument(AssemblyDocument document) { }
public void ReplaceReferences(AssemblyDocument targetAssembly, TupleList<string, string> namePair, string folderPath) { OccurrenceList newOccs = new OccurrenceList(targetAssembly); string pathString = folderPath; List<string> patternComponentsList = new List<string>(); for (int i = 0; i < newOccs.Items.Count; i++) { if (newOccs.Items[i].DefinitionDocumentType == DocumentTypeEnum.kPartDocumentObject) { for (int f = 0; f < namePair.Count; f++) { if (namePair[f].Item1 == newOccs.Items[i].ReferencedFileDescriptor.FullFileName) { if (patternComponentsList.Contains(namePair[f].Item1)) { newOccs.Items[i].ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(namePair[f].Item2); } else { if (!System.IO.File.Exists(namePair[f].Item2)) { PartDocument partDoc = (PartDocument)PersistenceManager.InventorApplication.Documents.Open(namePair[f].Item1, false); partDoc.SaveAs(namePair[f].Item2, true); partDoc.Close(true); newOccs.Items[i].ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(namePair[f].Item2); } patternComponentsList.Add(namePair[f].Item1); } } } } else if (newOccs.Items[i].DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { for (int n = 0; n < namePair.Count; n++) { if (namePair[n].Item1 == newOccs.Items[i].ReferencedFileDescriptor.FullFileName) { AssemblyDocument subAssembly = (AssemblyDocument)PersistenceManager.InventorApplication.Documents.Open(newOccs.Items[i].ReferencedFileDescriptor.FullFileName,false); ReplaceReferences(subAssembly, namePair, pathString); string newFilePath = namePair[n].Item2; subAssembly.SaveAs(namePair[n].Item2, true); subAssembly.Close(true); newOccs.Items[i].ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(namePair[n].Item2); } } } } }
public OccurrenceList(AssemblyDocument assDoc) { templateAssemblyDoc = assDoc; ComponentOccurrences topLevelOccurrences = templateAssemblyDoc.ComponentDefinition.Occurrences; EvaluateOccurrences(topLevelOccurrences); }
//Profiles for reinforcing panel #region Усиливающие рамки public void ReinforcingProfile(string testName) { const double thiknessF = 1; //var bendParams = sbSqlBaseData.BendTable(thiknessF); //var bendRadius = Convert.ToDouble(bendParams[0]); //var kFactor = Convert.ToDouble(bendParams[1]); const double heightF = 38.0; // Артурчик сказал не надо. 06.03.2017 16:45 #region Усиливающая рамка по ширине //newName = усиливающаяРамкаПоШирине.NewName; //newName = modelName + "-06-" + width + "-" + "40-" + materialP2[0] + скотч; //newPartPath = $@"{Settings.Default.DestinationFolder}\{_destinationFolder}\{newName}.SLDPRT"; SolidWorksDocument = SolidWorksAdapter.AcativeteDoc(testName);// "02-11-07-40-"); // horisontal up if (false) { } else { parameters.Add("D2@Эскиз1", framelessPanel.PanelType == PanelType_e.RemovablePanel ? framelessPanel.SizePanel.X - 49.2 : framelessPanel.SizePanel.X - 47.2); //parameters.Add("D1@Эскиз1", heightF); parameters.Add("D1@Кривая3", ScrewsByWidthInner); parameters.Add("D1@Кривая2", колСаморезВинтШирина); //Размеры для отверсти под клепальные гайки под съемные панели parameters.Add("G0@Эскиз32", OutputHolesWrapper.G0 - 3.6); parameters.Add("G1@Эскиз32", OutputHolesWrapper.G1); parameters.Add("G2@Эскиз32", OutputHolesWrapper.G2); parameters.Add("G3@Эскиз32", OutputHolesWrapper.G0); //Convert.ToString(количествоВинтов) parameters.Add("L1@Эскиз32", OutputHolesWrapper.L1); parameters.Add("D1@Кривая4", OutputHolesWrapper.D1); parameters.Add("L2@Эскиз32", OutputHolesWrapper.L2); parameters.Add("D1@Кривая5", OutputHolesWrapper.D2); parameters.Add("L3@Эскиз32", OutputHolesWrapper.L3); parameters.Add("D1@Кривая6", OutputHolesWrapper.D3); parameters.Add("Толщина@Листовой металл", thiknessF); parameters.Add("D1@Листовой металл", (double)BendRadius); parameters.Add("D2@Листовой металл", (double)KFactor * 1000); EditPartParameters("02-11-06-40-", "", 0); // $@"{Settings.Default.DestinationFolder}\{_destinationFolder}\{newName}", } #endregion #region Усиливающая рамка по ширине 2 if (framelessPanel.PanelType == PanelType_e.BlankPanel) { SolidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2(AssemblyName + ".SLDASM", true, 0))); DocumentExtension.SelectByID2("02-11-06_2-40--4@" + AssemblyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); // AssemblyDocument.ReplaceComponents(System.IO.Path.Combine(RootFolder, SubjectDestinationFolder, усиливающаяРамкаПоШирине.NewName + "SLDPRT"), String.Empty, true, true); //($@"{RootFolder}\{SubjectDestinationFolder}\{усиливающаяРамкаПоШирине.NewName}.SLDPRT", "", true, true); SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("02-11-06_2-40-.SLDPRT"); } else { //newName = усиливающаяРамкаПоШирине2.NewName; //newName = modelName + "-06-" + width + "-" + "40-" + materialP2[0] + скотч; //newPartPath = $@"{Settings.Default.DestinationFolder}\{_destinationFolder}\{newName}.SLDPRT"; if (false) { SolidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2(AssemblyName + ".SLDASM", true, 0))); DocumentExtension.SelectByID2("02-11-06_2-40--4@" + AssemblyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); AssemblyDocument.ReplaceComponents(base.NewPartPath, "", true, true); SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("02-11-06_2-40-.SLDPRT"); } else { parameters.Add("D2@Эскиз1", framelessPanel.PanelType == PanelType_e.RemovablePanel ? framelessPanel.SizePanel.X - 49.2 : framelessPanel.SizePanel.X - 47.2); parameters.Add("D1@Эскиз1", heightF); parameters.Add("D1@Кривая3", ScrewsByWidthInner); parameters.Add("D1@Кривая2", колСаморезВинтШирина); parameters.Add("G0@Эскиз32", OutputHolesWrapper.G0 - 3.6); parameters.Add("G1@Эскиз32", OutputHolesWrapper.G1); parameters.Add("G2@Эскиз32", OutputHolesWrapper.G2); parameters.Add("G3@Эскиз32", OutputHolesWrapper.G0); parameters.Add("L1@Эскиз32", OutputHolesWrapper.L1); parameters.Add("D1@Кривая4", OutputHolesWrapper.D1); parameters.Add("L2@Эскиз32", OutputHolesWrapper.L2); parameters.Add("D1@Кривая5", OutputHolesWrapper.D2); parameters.Add("L3@Эскиз32", OutputHolesWrapper.L3); parameters.Add("D1@Кривая6", OutputHolesWrapper.D3); parameters.Add("Толщина@Листовой металл", thiknessF); parameters.Add("D1@Листовой металл", (double)base.BendRadius); parameters.Add("D2@Листовой металл", (double)base.KFactor * 1000); EditPartParameters("02-11-06_2-40-", NewPartPath, 0); } } #endregion #region Усиливающая рамка по высоте // PartName = усиливающаяРамкаПоВысоте.NewName; NewPartPath = ""; // newName = modelName + "-07-" + lenght + "-" + "40-" + materialP2[0] + скотч; NewPartPath = System.IO.Path.Combine(RootFolder, SubjectDestinationFolder, NewPartPath + "SLDPRT"); //$@"{Settings.Default.DestinationFolder}\{_destinationFolder}\{newName}.SLDPRT"; //if (GetExistingFile(Path.GetFileNameWithoutExtension(NewPartPath), 1)) { // SolidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2(AssemblyName + ".SLDASM", true, 0))); // DocumentExtension.SelectByID2("02-11-07-40--1@" + AssemblyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); // AssemblyDocument.ReplaceComponents(newPartPath, "", true, true); // SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("02-11-07-40-.SLDPRT"); if (false) { ; } else { parameters.Add("D3@Эскиз1", framelessPanel.PanelType == PanelType_e.RemovablePanel ? framelessPanel.SizePanel.Y - 2 : framelessPanel.SizePanel.Y); parameters.Add("D1@Эскиз1", heightF); parameters.Add("D1@Эскиз23", framelessPanel.PanelType == PanelType_e.BlankPanel ? 44.4 : 125); parameters.Add("D1@Кривая2", ScrewsByHeightInner); parameters.Add("D1@Кривая1", колЗаклепокВысота); parameters.Add("Толщина@Листовой металл", thiknessF); parameters.Add("D1@Листовой металл", (double)base.BendRadius); parameters.Add("D2@Листовой металл", (double)base.KFactor * 1000); EditPartParameters("02-11-07-40-", NewPartPath, 0); #endregion } #endregion }
/// <summary> /// Main program control for copying, placing, constraining template assemblies, /// as well as evaluating duplicate geometries. /// </summary> /// <param name="templateAssemblyPath">Path to template assembly file to be copied and placed in model</param> /// <param name="destinationFolder">Path where created files will be saved</param> /// <param name="reuseDuplicates">Let the library determine if files can be reused</param> /// <param name="testMode">If true will create only three modules</param> private void InternalPlaceModules(string templateAssemblyPath, string destinationFolder, bool reuseDuplicates, bool testMode) { //Do some initial validation that this is going to work. //TODO: MOVE THIS INTO THE CONSTRUCTOR if (!IsConstraintSetUniform) { throw new Exception("Each module must have the same number of points."); } //If the user has chosen to try to reuse files for duplicate geometries, we need //evaluate that first before creating any new files. //TODO: MOVE THIS TO THE CONSTRUCTOR/ModulePoints property changed event. //Create this thing in constructor and set it to null in //this method if the user sets reuseDuplicates to false. We //are evaluating this shit every time UniqueModules = null; if (reuseDuplicates) { ModulesList.Select(p => { p.ReuseDuplicates = false; return(p); }).ToList(); //UniqueModuleEvaluator needs to be passed into the constructor. UniqueModules = UniqueModuleEvaluator.ByModules(ModulesList); } //We need to get a flattened list of all the ComponentOccurrence objects in the //template assembly. //Inventor's API was developed in Russia. AssemblyDocument templateAssembly = (AssemblyDocument)PersistenceManager.InventorApplication.Documents.Open(templateAssemblyPath, false); OccurrenceList templateOccurrences = new OccurrenceList(templateAssembly); _testMode = testMode; if (testMode) { if (ModulesList.Count < 3) { for (int i = 0; i < ModulesList.Count; i++) { ModulesList[i].MakeInvCopy(templateAssemblyPath, destinationFolder, templateOccurrences, UniqueModules); } } else { for (int i = 0; i < 3; i++) { ModulesList[i].MakeInvCopy(templateAssemblyPath, destinationFolder, templateOccurrences, UniqueModules); } } } else { for (int i = 0; i < ModulesList.Count; i++) { ModulesList[i].MakeInvCopy(templateAssemblyPath, destinationFolder, templateOccurrences, UniqueModules); } } templateAssembly.Close(); //ApprenticeServerComponent apprenticeServer = InventorPersistenceManager.ActiveApprenticeServer; //ApprenticeServerDocument templateAssemblyApprenticeDoc = apprenticeServer.Open(templateAssemblyPath); //OccurrenceList templateOccurrences = new OccurrenceList(apprenticeServer, templateAssemblyApprenticeDoc); //apprenticeServer.Close(); //Create Inventor files needed to accommodate this set of "Modules". //Create a layout file. This file will contain all the individual geometries as //work geometry. It will be placed first in the assembly we are making, and each //Module will get constrained to its corresponding set of work geometry. //This only needs to happen the first time. EnsureLayoutPartExists(destinationFolder); //Place the layout part and put work geometry in it. CreateLayout(destinationFolder); //Place the actual Inventor assemblies. //PersistenceManager.InventorApplication.Visible = false; try { if (testMode) { if (ModulesList.Count < 3) { for (int i = 0; i < ModulesList.Count; i++) { ModulesList[i].PlaceModule(); } } else { for (int i = 0; i < 3; i++) { ModulesList[i].PlaceModule(); } } } else { for (int i = 0; i < ModulesList.Count; i++) { ModulesList[i].PlaceModule(); } } } catch { PersistenceManager.InventorApplication.Visible = true; } //PersistenceManager.InventorApplication.Visible = true; //Update the view PersistenceManager.ActiveAssemblyDoc.Update2(); }
public void pushChildren() { DocumentsEnumerator allRefDocs = assemblyDoc.AllReferencedDocuments; try { foreach (Document oDoc in allRefDocs) { if (oDoc.DocumentType.Equals(DocumentTypeEnum.kPartDocumentObject)) { // For Parts PartDocument partFile = (PartDocument)oDoc; PartComponentDefinition partFileDef = partFile.ComponentDefinition; UserParameters partParameters = partFileDef.Parameters.UserParameters; ArrayList paraList = new ArrayList(); foreach (Parameter parameter in partParameters) { paraList.Add(parameter.Name); } try { foreach (Parameter parameter in assemblyParameters) { if (parameter.IsKey && !paraList.Contains(parameter.Name)) { // Must use add by value to get parameters that are nonnumeric partParameters.AddByValue(parameter.Name, parameter.Value, parameter.get_Units()); // partParameters.AddByExpression(parameter.Name, parameter.Value, parameter.get_Units()); } } } catch (Exception) { throw; } } else if (oDoc.DocumentType.Equals(DocumentTypeEnum.kAssemblyDocumentObject)) { // For Subassemblies AssemblyDocument partFile = (AssemblyDocument)oDoc; AssemblyComponentDefinition subAssemblyDef = partFile.ComponentDefinition; UserParameters subAssemblyParameters = subAssemblyDef.Parameters.UserParameters; ArrayList paraList = new ArrayList(); try { foreach (Parameter parameter in subAssemblyParameters) { paraList.Add(parameter.Name); } foreach (Parameter parameter in assemblyParameters) { if (parameter.IsKey && !paraList.Contains(parameter.Name)) { subAssemblyParameters.AddByExpression(parameter.Name, "1", parameter.get_Units()); } } } catch (Exception) { throw; } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
/// <summary> /// Causes the exporter to close. /// </summary> /// <param name="suppressClosingEvent">Whether or not the exporter closing handler should be suppressed from being called.</param> private async void ForceQuitExporter(AssemblyDocument document) { await Task.Delay(1); // Delay is needed so that environment is closed after it has finished opening document.EnvironmentManager.SetCurrentEnvironment(document.EnvironmentManager.EditObjectEnvironment); }
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); }
static void Main(string[] args) { SolidEdgeFramework.Application _application = null; // Connect to Solid Edge. var application = SolidEdgeUtils.Connect(true, true); // Get a reference to the Documents collection. var documents = application.Documents; // Get a folder that has Solid Edge files. //var folder = new DirectoryInfo("C:/Users/geevi/Documents/Work/Strath_CADfiles/summer work/step files/gate valves/ASAHI YUKIZAI/step files"); var folder = new DirectoryInfo("C:/Users/geevi/Documents/Work/Strath_CADfiles/test_file"); // Get the installed version of Solid Edge. var solidEdgeVesion = application.GetVersion(); // Disable prompts. application.DisplayAlerts = false; int i = 0; //count the number of files with subassemblies int k = 1; //part number in a subassembly // Process the files. foreach (var file in folder.EnumerateFiles("*.stp", SearchOption.AllDirectories)) { Console.WriteLine(file.FullName); var template = @"iso metric assembly.asm"; //var template = @"iso metric part.par"; // Open the document using a solid edge template var document = (SolidEdgeFramework.SolidEdgeDocument)documents.OpenWithTemplate(file.FullName, template); // Give Solid Edge a chance to do processing. application.DoIdle(); AssemblyDocument _doc = application.ActiveDocument as AssemblyDocument; int part_count = _doc.Occurrences.Count; var occur = _doc.Occurrences; //if there is more than one part in the assembly doc if (part_count > 1) { for (int j = 1; j <= part_count; j++) { //string newfile_name = string.Format($"C:/Users/geevi/Documents/Work/Strath_CADfiles/test_file/Saved_Part_files/Part_{k}.par"); // _doc.SaveModelAs(occur.Item(j), newfile_name); k++; } i++; } // Prior to ST8, we needed a reference to a document to close it. // That meant that SE can't fully close the document because we're holding a reference. if (solidEdgeVesion.Major < 108) { // Close the document. document.Close(); // Release our reference to the document. Marshal.FinalReleaseComObject(document); document = null; // Give SE a chance to do post processing (finish closing the document). application.DoIdle(); } else { // Release our reference to the document. if (document != null) { Marshal.FinalReleaseComObject(document); document = null; } } documents.Close(); } application.DisplayAlerts = true; // Additional cleanup. Marshal.FinalReleaseComObject(documents); Marshal.FinalReleaseComObject(application); Console.WriteLine("Finished reading files"); //Console.WriteLine("The K value = {0}",k); Console.WriteLine("Number of files with more than one part = {0}", i); Console.Read(); }