11-13-2023
05:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
11-13-2023
05:47 AM
Hi @tecnico. OK. Here is a slightly different version of the code, but this version compares the Part Number of the main assembly to the Part Number of the virtual component. And also uses a Boolean to let you know if no match was found after the loop.
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 sAssemblyPN As String = oADoc.PropertySets.Item(3).Item(2).Value
Dim bFound As Boolean = False
Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Suppressed Then Continue For 'cant access Definition if Suppressed
If TypeOf oOcc.Definition Is VirtualComponentDefinition Then
Dim oVCD As VirtualComponentDefinition = oOcc.Definition
Dim sVOccPN As String = oVCD.PropertySets.Item(3).Item(2).Value
If sVOccPN.Equals(sAssemblyPN, StringComparison.CurrentCultureIgnoreCase) Then
bFound = True
MsgBox("Found a Virtual component with same Part Number as main assembly.", vbInformation, "iLogic")
End If
End If
Next 'oOcc
If bFound = False Then
MsgBox("Did not find a Virtual component with same Part Number as main assembly.", vbInformation, "iLogic")
End If
End Sub
Wesley Crihfield
(Not an Autodesk Employee)