Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Parts List from Drawing using C#

1 REPLY 1
Reply
Message 1 of 2
adhurjaty
1416 Views, 1 Reply

Get Parts List from Drawing using C#

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);
        }
    }
}

1 REPLY 1
Message 2 of 2
wayne.brill
in reply to: adhurjaty

Hi,

 

The VBA PartListQuery example that was converted to C# in this DevBlog post may help.

http://modthemachine.typepad.com/my_weblog/2012/11/c-help-examples-for-drawing-annotations-part-two....

 

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



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report