iLogic Export BOM Sheet Metal parts to Excel

iLogic Export BOM Sheet Metal parts to Excel

Makronyl114
Explorer Explorer
505 Views
4 Replies
Message 1 of 5

iLogic Export BOM Sheet Metal parts to Excel

Makronyl114
Explorer
Explorer

I want to Export a BOM of only Sheet Metal parts to Excel.

 

In Inventor I have an Assembly containing several parts. Normal parts and Sheet Metal parts. Now I need a partslist or BOM of Sheet Metal only in Excel with the folowing properties:

- Filename

- Description

- Material

- Project

- Bon (custom property)

- QTY

0 Likes
506 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor

This is a bit different solution then you asked for but could work for you. The following rule will add a custom iProperty to each document. With information if the document is a sheet metal part. Then if you add that custom property to your bom view you can sort and export it like normal. And if you want you can filter the parts in excel.

JelteDeJong_0-1640878659481.png

 

Public Sub Main()
    Dim doc As AssemblyDocument = ThisDoc.Document

    For Each refDoc As Document In doc.AllReferencedDocuments
        If (refDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject) Then
            Continue For
        End If

        Dim isSheetMetal = (refDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}")
        SetCustomProperty(refDoc, "IsSheetMetalPart", isSheetMetal)
    Next
		
End Sub

Public Sub SetCustomProperty(doc As Document, name As String, value As Object)

    Dim fileInfo As New IO.FileInfo(doc.FullFileName)
    fileInfo.IsReadOnly = False

    Dim propSet = doc.PropertySets.Item("Inventor User Defined Properties")
    Try
        Try
            Dim prop = propSet.Item(name)
            prop.Value = value
        Catch ex As Exception
            propSet.Add(value, name)
        End Try
    Catch ex As Exception
        MsgBox("Could not change/update document: " & doc.FullFileName)
    End Try

End Sub

 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

fidel.makatiaD5W7V
Alumni
Alumni

Hi @Makronyl114 try suppressing the components you dont want before generating the BOM

Check out this code and let me know if it worked

 Public Sub ExportBOM()

        Dim oDoc As AssemblyDocument
        oDoc = _InvApplication.ActiveDocument


        Dim oAsmDef As AssemblyComponentDefinition
        oAsmDef = _InvApplication.ActiveDocument.ComponentDefinition

        oAsmDef.Occurrences.Item(1).Suppress()


        Dim oBOM As BOM
        oBOM = oDoc.ComponentDefinition.BOM

        ' Set the structured view to 'all levels'
        oBOM.StructuredViewFirstLevelOnly = False

        ' Make sure that the structured view is enabled.
        oBOM.StructuredViewEnabled = True

        ' Set a reference to the "Structured" BOMView
        Dim oStructuredBOMView As BOMView
        oStructuredBOMView = oBOM.BOMViews.Item("Structured")

        ' Export the BOM view to an Excel file
        oStructuredBOMView.Export("C:\Temp\BOMtest.xls", FileFormatEnum.kMicrosoftExcelFormat)

    End Sub


Fidel Makatia
Developer Advocate

href=https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-0BD48573-7193-4285-87B7-6727555D053E rel= "noopener noreferrer">Inventor 2022 Documentation |
0 Likes
Message 4 of 5

JelteDeJong
Mentor
Mentor

@fidel.makatiaD5W7VI think that is not a good option. In general suppressing parts (and unsurprising parts) seems to me the long way around. But that is not my biggest issue with that solution. As soon as you start using model states (and have sub-assemblies) you will run into problems. As @johnsonshiue wrote "I believe you are attempting to suppress an occurrence across level. This is not a supported workflo..." In that post, you might find workarounds but I did not manage to make them work reliably.

Anyway, if the option above doesn't work for TS then I would suggest making your own export function. That isn't very difficult as you can just loop over all BOM rows and check if you want to export the row or not.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 5

Makronyl114
Explorer
Explorer

Hi @JelteDeJong both solutions aren't exactly what I wanted. But you suggested to loop over all BOM rows and check if you want to export the row or not. 

 

I think that should be the solution but I'm not very well known in programming.

 

Can you give me an example code to do this?

0 Likes