Hi @pavol_krasnansky. This is sort of a tough one to deal with, because you normally can not do much of anything with a suppressed component. You can not access its Definition, and you can not access its referenced document either, until after you un-suppress it. But if you un-suppress it, you have to remember that you did so, and then re-suppress it later, to leave it the way it was found. Also, dealing with document references when ModelStates are involved can be fairly complicated. Most of the time, if no ModelState is involved, you will always get the main file document with most methods. However, when non-master ModelStates are involved, you usually get what is called a 'member' document, which is not the main document, but a modified virtual copy of it. And there are some object Properties sometimes encountered along the way which are pretty misleading, in my opinion.
Below is an iLogic rule you can try that I believe should do a better job at the specific task you wanted:
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOcc As ComponentOccurrence = Nothing
If oADoc.SelectSet.Count = 0 Then
MsgBox("Nothing was pre-selected. Exiting rule.", vbCritical,"")
Exit Sub
End If
If TypeOf oADoc.SelectSet.Item(1) Is ComponentOccurrence Then
oOcc = oADoc.SelectSet.Item(1)
Else
MsgBox("A single component was NOT pre-selected. Exiting rule.", vbCritical,"")
Return
End If
If IsNothing(oOcc) Then Exit Sub
Dim oOriginalOccFactoryDoc As Document = GetComponentFactoryDocument(oOcc)
If IsNothing(oOriginalOccFactoryDoc) Then
MsgBox("No 'factory' document was returned from the originally selected component.", vbCritical,"")
Exit Sub
End If
Dim oOccsLikeSelected As New List(Of ComponentOccurrence)
'get all other components that are also referencing the same document
'but also count them if they are suppressed or if set to a different ModelState than the original
'this loop is only looking at 'top level' components, not components within sub-assemblies
For Each oComp As ComponentOccurrence In oADef.Occurrences
'if a component is suppressed, you can not access its Definition, or its referenced Document
'also, when the component is under the influence of a non-master ModelState,
'the Document you get from it will be a 'member' document, not the true 'factory' or main document
Dim oCompFactoryDoc As Document = GetComponentFactoryDocument(oComp)
If IsNothing(oCompFactoryDoc) Then
Logger.Info("No 'factory' document was returned from component named '" & oComp.Name & "'.")
Continue For
End If
If oCompFactoryDoc.FullFileName = oOriginalOccFactoryDoc.FullFileName Then
oOccsLikeSelected.Add(oComp)
End If
Next
'this count will include the originally selected component
Dim oCount As Integer = oOccsLikeSelected.Count
MsgBox("There are " & oCount & " total components referencing the same document" & _
vbCrLf & "as the originally selected component.", vbInformation, "")
End Sub
Function GetComponentFactoryDocument(oComponent As ComponentOccurrence) As Inventor.Document
If IsNothing(oComponent) Then Return Nothing
Dim oSuppressed As Boolean = False
If oComponent.Suppressed Then
oSuppressed = True
Try
oComponent.Unsuppress
Catch
Logger.Error("Could not Unsuppress component named '" & oComponent.Name & "'.")
Return Nothing
End Try
End If
If TypeOf oComponent.Definition Is VirtualComponentDefinition Then Return Nothing
Dim oMSs As ModelStates = oComponent.Definition.ModelStates
Dim oFactoryDoc As Document = oMSs.Item(1).Document
If oSuppressed Then
Try
oComponent.Suppress
Catch
Logger.Error("UnSuppressed component named: '" & oComponent.Name & "'," & _
vbCrLf & "but was unable to Suppress it again.")
End Try
End If
Return oFactoryDoc
End Function
Wesley Crihfield

(Not an Autodesk Employee)