It is currently Wed May 22, 2013 5:20 pm

All times are UTC





Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Jul 19, 2012 3:44 am 
Offline
MCAD Lurker

Joined: 18 Jul 2012
Posts: 3
Country: New Zealand
State: Non US/CAN Resident
CAD System: Inventor
Hi there, does anyone know how to retrieve the value of the "Default BOM Structure" of an inventor component (Normal, Phantom, Purchased etc...) using VBA?

I know how to modify the BOM Structure:

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
oDoc.ComponentDefinition.BOMStructure = kPurchasedBOMStructure

But I can't figure out how to retrieve the current value of it.

Cheers, Stew.


Share on FacebookShare on TwitterShare on DiggShare on DeliciousShare on TumblrShare on Google+
Top
 Profile  
 
PostPosted: Wed Jul 25, 2012 4:45 pm 
Offline
MCAD Contributer

Joined: 27 Jul 2004
Posts: 84
It would be nice to know the context in which you wish to use the BOM structure property, however here is a function that will return an Enumerated property of the BOM structure.

Code:
Public Function GetBOMStructure(pvarComponentDefinition As PartComponentDefinition) As BOMStructureEnum
    GetBOMStructure = pvarComponentDefinition.BOMStructure
End Function


As I've said, BOMStructureEnum property is an Enumerated value, there are 7 values to this Enumerator. Be nosey, in VBA editor, press F2 and you will be presented with "Object Browser", search for "BOMStructureEnum" in here and all will be revealed.

Hope this helps


Top
 Profile  
 
PostPosted: Wed Jul 25, 2012 8:05 pm 
Offline
MCAD Lurker

Joined: 18 Jul 2012
Posts: 3
Country: New Zealand
State: Non US/CAN Resident
CAD System: Inventor
Thanks for that, I'll check it out.

I've written a macro which exports all the text files associated with an upper level assembly (ie, exports the BOM (as a text file) of each assembly found in a given parent assembly). I want to check that the assembly isn't "phantom" because I don't want to export those ones.

Here is the code so far. I've put a comment in where I need to look up and check Default BOM structure property.

Public Sub BOMExport()
' Export BOM of all open assemblies

' get all open documents (any child of an open assembly is also open, even if not visible)
Dim oDocs As Documents
Set oDocs = ThisApplication.Documents

' get open document
Dim oDoc As Document

' cycle through each open assembly, and export the text file
For Each oDoc In oDocs

Dim invTypeProp As Property
Set invTypeProp = oDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name")

'Some code to fetch the "Default BOM Structure" value

Dim oRev As Property
Set oRev = oDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number")

Dim oCostCtr As Property
Set oCostCtr = oDoc.PropertySets.Item("Design Tracking Properties").Item("Cost Center")

If invTypeProp.Value = "Assembly" Or invTypeProp.Value = "Weldment" Then
If oCostCtr.Value = "MAN" Then
'if "Bom Structure is not "Phantom" then

' Set a reference to the BOM
On Error Resume Next

Dim oBOM As BOM
Set oBOM = oDoc.ComponentDefinition.BOM

' Set the structured view to 'first level only'
oBOM.StructuredViewFirstLevelOnly = True

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

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

' Export the BOM view to an Excel file
oStructuredBOMView.Export "I:\Temp TXT Files\" & oDoc.DisplayName & " REV " & oRev.Value & ".txt", kTextFileTabDelimitedFormat
'End If
End If
End If
Next

End Sub


Top
 Profile  
 
PostPosted: Thu Jul 26, 2012 1:29 am 
Offline
MCAD Lurker

Joined: 18 Jul 2012
Posts: 3
Country: New Zealand
State: Non US/CAN Resident
CAD System: Inventor
Thanks Scott, got it to work:
I stick the code below into my Sub, and it returns a 5 digit number corresponding to the BOM structure type.

Dim oBomStructure As BOMStructureEnum
oBomStructure = ThisApplication.ActiveDocument.ComponentDefinition.BOMStructure

Cheers, Stew


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
POWERED_BY