Fail to access Structured BOMView - does not exist?

Fail to access Structured BOMView - does not exist?

jonas.hoffmeisterFYFHQ
Enthusiast Enthusiast
503 Views
6 Replies
Message 1 of 7

Fail to access Structured BOMView - does not exist?

jonas.hoffmeisterFYFHQ
Enthusiast
Enthusiast

Hi all,

 

I am running the code below:

 

Dim oAssDoc As AssemblyDocument
oAssDoc = ThisApplication.ActiveDocument
oAssDoc.Save

Dim oBOM As BOM
oBOM = oAssDoc.ComponentDefinition.BOM

MessageBox.Show("FLO " & oBOM.StructuredViewFirstLevelOnly)
MessageBox.Show("Str " & oBOM.StructuredViewEnabled )

'oBOM.StructuredViewFirstLevelOnly = False
oBOM.StructuredViewEnabled = True

Dim oBVList As New ArrayList
For Each item As BOMView In oBOM.BOMViews
	oBVList.Add(item.Name)
	MessageBox.Show(item.Name)
Next

Dim BOM As Inventor.BOMView 
BOM = oBOM.BOMViews.Item("Unbenannt")

 

The values I am reading in the MsgBoxes are FLO False and Str True. The reason why "'oBOM.StructuredViewFirstLevelOnly = False" is commented out is because I get an error as soon as I dont ("Wrong parameter"). As shown above the code runs fine but the only BOMView in oBOMViews is "Unbenannt" (unnamed). I would however need "Strukturiert" (structured). I did run the code in other assemblies and there is works fine and I do have a structured view. Hence there must be something wrong with the assembly doc settings?? Any idea?

 

Thanks

Jonas

 

 

 

 

0 Likes
Accepted solutions (1)
504 Views
6 Replies
Replies (6)
Message 2 of 7

A.Acheson
Mentor
Mentor

Hi @jonas.hoffmeisterFYFHQ 

Can you share an image of each tab? Any issues within the BOM itself?

Have you tried with just index Like

oBOM.BOMViews.Item(2)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 7

jjstr8
Collaborator
Collaborator
Accepted solution

@jonas.hoffmeisterFYFHQ :  I'm not sure what version of Inventor you're, but older versions that had Level Of Detail representations would only expose the "unnamed" BOM (through the API) if the LOD was set to anything but "Master".  I'm on 2019, so don't know how it works with Model States.

Message 4 of 7

WCrihfield
Mentor
Mentor

Hi @jonas.hoffmeisterFYFHQ.  If accessing the BOMView you want by Item Index or by Name is failing or unstable for you, you could always access the one you want by its ViewType.  Here is another simple example iLogic rule, similar to your original, but it includes the BOMView.Name and BOMView.ViewType in the same message box.

 

Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oBOM As BOM = oADoc.ComponentDefinition.BOM
oBOM.PartsOnlyViewEnabled = True
oBOM.StructuredViewEnabled = True
Dim oBOMViews As BOMViews = oBOM.BOMViews
Dim oStrView As BOMView = Nothing
For Each oBOMView As BOMView In oBOMViews
	MsgBox("oBOMView.Name = " & oBOMView.Name & vbCrLf & _
	"oBOMView.ViewType.ToString = " & oBOMView.ViewType.ToString, , "")
	If oBOMView.ViewType = BOMViewTypeEnum.kStructuredBOMViewType Then
		oStrView = oBOMView
	End If
Next
If oStrView Is Nothing Then
	MsgBox("Structured BOMView not found.", vbCritical, "")
	Exit Sub
Else
	MsgBox("Structured BOMView found:" & vbCrLf & _
	"oStrView.Name = " & oStrView.Name & vbCrLf & _
	"oStrView.ViewType.ToString = " & oStrView.ViewType.ToString, vbInformation, "BOMView Info")
End If

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

jonas.hoffmeisterFYFHQ
Enthusiast
Enthusiast

This was it. At some point along the delevopment inventor wanted me to adjust the LOD rep (via some pop-up msg and I just ok'ed it). I had no clue what this was. Never used it. But after some quick research I adjusted this back to master and everything works fine now.

 

Thanks to the entire team for the awesome quick responds. You guys are rockstars.

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

Hi @jonas.hoffmeisterFYFHQ.  Just so you are aware going forward, those LOD's (LevelOfDetailRepresentations) are only for recording component suppression settings/status.  So if you suppress an assembly component, it will want to record that suppression status change, and it can only be recorded if there is an 'unlocked' LOD present and active at that time.  If there is no unlocked LOD present, or one is not active, it will want to create one and/or activate one to record that suppression change.  Then certain actions were not permitted while a non-master LOD was active.  The behavior was sometimes a bit disruptive, if you are not used to them.  I mostly avoided using LOD's, in favor of using DVR's (DesignViewRepresentations), which are used to record things like Appearance and Visibility settings, and BOMStructure (for controlling item status in the BOM).  I would turn visibility of some components off, instead of suppressing them, record that with DVR's, then use those DVR's to filter the PartsList in my assembly drawings.  If an assembly was really large, and was slow to open or work with, I would then use LOD's to suppress components, and help with performance (speed things up a bit).  Although the primary purpose of suppressing components is to increase performance, a lot of folks used LOD's to help manage BOM quantities also.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7

jjstr8
Collaborator
Collaborator
Glad to help. I would suggest adding a check for the active LOD. You might even prompt the user to ask if it's okay to switch it to master LOD. Inventor does handle exceptions from iLogic and VBA and not crash, but not from add-ins, if you progress to making add-ins. Nothing worse than having your add-in crash Inventor. I usually do as many "prerequisite" checks as I can, and wrap other things, like a Save, in a try-catch.

<assemblyDocument>.ComponentDefinition.RepresentationsManager.ActiveLevelOfDetailRepresentation.LevelOfDetail = LevelOfDetailEnum.kMasterLevelOfDetail