Hello,
I am trying to work with the inventor API, trying to export parts lists from .idw drawings for assemblies using C#. I looked through the documentation and found the 'Parts List Query' sample program in the Autodesk Inventor 2014 API Help document. This is in VBA and also only works on active drawing sheets. I want my program to take in a list of .idw files and output excel or csv files of the parts list. I would like this program to be in C# becuase I already have code in C# interfacing with the Vault. Could someone please point me in the direction of where to find the answer to this question?
Below is my C# code that is a modified version of 'AssemblyTree' that is included as a C# sample with the SDK. This allows the user to point to an .iam file and it outputs a .csv file of the files on which it depends. This is close to what I need, but many of our drawings have parts on the BOM that do not have files and some filenames are not the same as their part numbers
Thank you so much
private void BuildTree() { try { Inventor.ApprenticeServerDocument objapprenticeServerDocument = objapprenticeServerApp.Open(txtFileName.Text); if (objapprenticeServerDocument == null) { MessageBox.Show("Unable to open the specified file", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } IEnumerator objoccsEnumerator = objapprenticeServerDocument.ComponentDefinition.Occurrences.GetEnumerator(); string csv = ""; Inventor.ComponentOccurrence objcompOccurrence; while (objoccsEnumerator.MoveNext()) { objcompOccurrence = (Inventor.ComponentOccurrence)objoccsEnumerator.Current; csv += objcompOccurrence.Name + "\n"; } File.WriteAllText(@"C:\test.csv", csv); } catch (Exception) { MessageBox.Show("Unable to open and get the assembly heirarchy of the specified file", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
}
Hi,
The VBA PartListQuery example that was converted to C# in this DevBlog post may help.
You could update it so it processes each sheet in a for loop using the Sheets collection of the DrawingDocument. The sheet has a PartsLists property you could use to get each partslist on the sheet.
Thanks,
Wayne