Component visibility via Document object

Component visibility via Document object

chendersonCRKPU
Contributor Contributor
240 Views
1 Reply
Message 1 of 2

Component visibility via Document object

chendersonCRKPU
Contributor
Contributor

Is there a way to access the visibility status of a component via the Document object?

 

I'm looping through the BOMRows enumerator and would like to determine the visibility status of each component.

 

Or is this only achievable through a Component Occurrences loop?

0 Likes
Accepted solutions (1)
241 Views
1 Reply
Reply (1)
Message 2 of 2

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @chendersonCRKPU . You can't get visibility information in a Document object, you need to use oRow.ComponentOccurrences.Item(1). Example code:

 

Private Sub Main()
	Dim oDoc As Document = ThisApplication.ActiveDocument
	If TypeOf oDoc Is AssemblyDocument Then
		Dim oAssDoc As AssemblyDocument = oDoc
		If CheckDocMiss(oAssDoc) Then Exit Sub
		Call WorkWithAssembly(oAssDoc)
	Else If TypeOf oDoc Is DrawingDocument Then
		Dim oDrawDoc As DrawingDocument = oDoc
		Dim oAssDoc As AssemblyDocument = oDrawDoc.ReferencedDocuments.Item(1)
		If CheckDocMiss(oAssDoc) Then Exit Sub
		Call WorkWithAssembly(oAssDoc)
	Else
		MessageBox.Show("This rule can only be run in an assembly or a drawing files.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
	End If
End Sub

Private Sub WorkWithAssembly(ByVal oDoc As AssemblyDocument)
	Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oBOM As BOM = oDef.BOM
	Dim oBOMViewStruc As BOMView = GetBOMstructure(oBOM)
	If IsNothing(oBOMViewStruc) Then Exit Sub
	For Each oRow As BOMRow In oBOMViewStruc.BOMRows
		Dim oOcc As ComponentOccurrence = oRow.ComponentOccurrences.Item(1)
		MessageBox.Show("Visible - " & oOcc.Visible, oOcc.Name)
	Next
End Sub

Private Function GetBOMstructure(ByVal oBOM As BOM) As BOMView
	
	Dim sLanguageBOM, sSortItem As String
	
	Select Case ThisApplication.LanguageCode
	Case "en-US"
		sLanguageBOM = "Structured"
		sSortItem = "Item"
	Case "ru-RU"
		sLanguageBOM = "Структурированный"
		sSortItem = "Номер"
	Case Else
		Exit Function
	End Select
	
	If oBOM.StructuredViewEnabled = False Then oBOM.StructuredViewEnabled = True
	If oBOM.StructuredViewFirstLevelOnly = False Then oBOM.StructuredViewFirstLevelOnly = True
	oBOM.BOMViews.Item(sLanguageBOM).Sort(sSortItem, True)
	
	Return oBOM.BOMViews.Item(sLanguageBOM)
End Function

Private Function CheckDocMiss(ByVal oDoc As Document) As Boolean
	For Each oRefDoc As DocumentDescriptor In oDoc.ReferencedDocumentDescriptors
		If Not oRefDoc.ReferenceSuppressed Then
			If oRefDoc.ReferenceMissing Then
				Return True			
			End If
		End If
	Next
	Return False
End Function

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes