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: 

Export BOM Using Ilogic

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
4935 Views, 4 Replies

Export BOM Using Ilogic

I'm using ilogic to export my BOM in Microsoft Access Database format. We are using Access 2010. The code I am using is saving the file in an earlier version of Access, so when i open the database I am prompted by Access to have the file converted to the latest (2010) version. It seems to convert ok through Access so I'm not totally stuck, but it would be nice if Ilogic could do the job right on the export so I don't have to be prompted every time. Anyone have any suggestions as to how to specify the correct version of Access in the export code? Below is my code. Also, I've been unable to export my BOM using ilogic from a custom LOD. My assemblies are almost never in a master LOD at the point that I want to export. In my code I have the model switching LOD to master prior to the export, then switching back to custom as a work-around. Any suggestions as to how I can export through ilogic form a custom LOD? The code below works, but takes a while to run because of the LOD switch.

ThisDoc.Save
ThisApplication = InventorVb.Application

oMyDoc = ThisDoc.ModelDocument

Dim oRepMgr As RepresentationsManager
oRepMgr = oMyDoc.ComponentDefinition.RepresentationsManager

Dim oMasterLOD As LevelOfDetailRepresentation
oMasterLOD = oRepMgr.LevelOfDetailRepresentations.Item("Master")

oMasterLOD.Activate()

ThisBOM.Export("Parts Only", "C:\TEMP\bom_temp\export_inventor_files_here.mdb", kMicrosoftAccessFormat)

oMasterLOD = oRepMgr.LevelOfDetailRepresentations.Item("custom")

oMasterLOD.Activate()

 

4 REPLIES 4
Message 2 of 5
adam.nagy
in reply to: Anonymous

Happy New Year!

 

I'm quite sure that iLogic ThisBOM.Export is using BOMView.Export underneath.

If you check in the API reference (C:\Program Files\Autodesk\Inventor 2013\Local Help\admapi_17_0.chm) then it has this information on the available options:

>>>>>

Options - Optional input String that specifies the 'Table Name' for kMicrosoftAccess and kMicrosoftExcel file formats. This is the name of the Excel/Access sheet. If not provided, the name of the file is used as the sheet name. For other formats, this argument is ignored.

<<<<<

 

So unfortunately, it does not seem possible to influcence the file version being used - but I'm chekcing with colleagues and will get back to you if I get any different information on this.

 

Concerning the second question.

Probably you could open the Master LOD in the background to do what you need like it is done in the following sample code:

http://adndevblog.typepad.com/manufacturing/2012/08/access-to-the-bill-of-materials-from-a-different...

 

I hope this helps.

 

Cheers, 



Adam Nagy
Autodesk Platform Services
Message 3 of 5
YuhanZhang
in reply to: Anonymous

Becides switching the active LOD, another workaround is that you can open the assembly document with master LOD active in invisible mode, if you already have the document opened with custom LOD active you can try below code:

 

Sub ExportBOMSample()
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    ' If the current non-master LOD document is dirty you should save it before you can use the master-LOD document background
    If oDoc.Dirty Then
        If MsgBox("You should save the document first!" & vbCrLf & "Would you like to save the document?", vbYesNo) = vbYes Then
            oDoc.Save
        Else
            Exit Sub
        End If
        
    End If
    
    Dim sFileName As String
    sFileName = oDoc.FullFileName
    
    Dim oMasterLODDoc As AssemblyDocument
    Set oMasterLODDoc = ThisApplication.Documents.Open(sFileName, False)
    
    Dim oBOM As BOM
    Set oBOM = oMasterLODDoc.ComponentDefinition.BOM
    
    oBOM.PartsOnlyViewEnabled = True
    
    Dim oBOMView As BOMView
    Set oBOMView = oBOM.BOMViews.Item("Parts Only")
    
    oBOMView.Export "C:\Temp\BOM.accdb", kMicrosoftAccessFormat
    
    oMasterLODDoc.Close True
    
End Sub

 

 

Note: To access the master-LOD document's BOM background you should make sure the document is not dirty in custom LOD document, otherwise you should save it first.

 

Hope it helps!



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 4 of 5
Anonymous
in reply to: YuhanZhang

That worked. Thanks!

Message 5 of 5
DeerSpotter
in reply to: YuhanZhang

How to make this BOM renumber?

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report