By Barbara Han
Issue
I'm trying to find out if a ComponentOccurrence is excluded or not in iAssembly, but did not find any property I could use. Is it possible?
Solution
You can use the iAssemblyTableRow.IsExcluded() function for this purpose. The code below assumes that the ActiveDocument is an iAssembly.
VBA code sample:
Sub testExclude()
Dim invAD As AssemblyDocument
Set invAD = ThisApplication.ActiveDocument
If invAD.ComponentDefinition.IsiAssemblyFactory Then
Dim invCO As ComponentOccurrence
For Each invCO In invAD.ComponentDefinition.Occurrences
Debug.Print invCO.Name & " is excluded = " & _
invAD.ComponentDefinition.iAssemblyFactory.DefaultRow.IsExcluded(invCO)
Next
End If
End Sub
VB.NET code sample:
Sub testExclude()
Dim m_inventorApp As Inventor.Application = Nothing
Dim m_quitInventor As Boolean = False
' Try to get an active instance of Inventor
Try
m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
Catch ex As Exception
End Try
' If not active, create a new Inventor session
If m_inventorApp Is Nothing Then
Dim inventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application")
m_inventorApp = System.Activator.CreateInstance(inventorAppType)
m_quitInventor = True
End If
Dim invAD As AssemblyDocument
invAD = m_inventorApp.ActiveDocument
If invAD.ComponentDefinition.IsiAssemblyFactory Then
Dim invCO As ComponentOccurrence
For Each invCO In invAD.ComponentDefinition.Occurrences
System.Diagnostics.Debug.Write(invCO.Name & " is excluded = " & _ invAD.ComponentDefinition.iAssemblyFactory.DefaultRow.IsExcluded(invCO) & vbCr)
Next
End If
If Not m_inventorApp Is Nothing AndAlso m_quitInventor = True Then
m_inventorApp.Quit()
End If
m_inventorApp = Nothing
End Sub