Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: tecnico

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

EESignature

(Not an Autodesk Employee)