How to recognize if two occurrences are the same virtual component?

How to recognize if two occurrences are the same virtual component?

CattabianiI
Collaborator Collaborator
511 Views
4 Replies
Message 1 of 5

How to recognize if two occurrences are the same virtual component?

CattabianiI
Collaborator
Collaborator

What I refer to is when you create a pattern of virtual component or copy and paste a virtual component.
Comparing the ComponentDefinition property of the occurrences  seems to work (check the code below), is there something more specific inside VirtualComponentDefinition object that I can check?

Dim oSS As SelectSet
oSS = ThisApplication.ActiveDocument.SelectSet

Dim occ1 As ComponentOccurrence = oSS.Item(1)
Dim occ2 As ComponentOccurrence = oSS.Item(2)
Dim cmpDef1 As VirtualComponentDefinition = occ1.Definition 
Dim cmpDef2 As VirtualComponentDefinition = occ2.Definition 

Logger.Info((cmpDef1 Is cmpDef2).ToString())

Checking the name not a good idea because it can change per occurrence.
Checking the part number or something like that not ok because I could have set the same part number for occurrences of different virtual components.

0 Likes
Accepted solutions (1)
512 Views
4 Replies
Replies (4)
Message 2 of 5

yuzeaa
Advocate
Advocate

ComponentOccurrence.Definition.Document.FullDocumentName?

0 Likes
Message 3 of 5

CattabianiI
Collaborator
Collaborator

What value do you expect on a virtual component? 🙂
Nope btw, that's the assembly document that contains the virtual occurrence.

0 Likes
Message 4 of 5

Frederick_Law
Mentor
Mentor
Accepted solution
Message 5 of 5

CattabianiI
Collaborator
Collaborator

That's it! 
And it's not possible to have different VirtualComponentDefinition with same DisplayName: perfect!
Thank you!

Dim oSS As SelectSet
oSS = ThisApplication.ActiveDocument.SelectSet

Dim occ1 As ComponentOccurrence = oSS.Item(1)
Dim occ2 As ComponentOccurrence = oSS.Item(2)
Dim cmpDef1 As VirtualComponentDefinition = occ1.Definition
Dim cmpDef2 As VirtualComponentDefinition = occ2.Definition



If cmpDef1.DisplayName = cmpDef2.DisplayName Then
	Logger.Info("Selected occs refer to the same virtual component")
Else
	Logger.Info("Selected occs do not refer to the same virtual component")
	
	Logger.Info(cmpDef1.DisplayName)
	Logger.Info(cmpDef2.DisplayName)
	
	cmpDef1.DisplayName = "foo"
	Try
		cmpDef2.DisplayName = "foo"
	Catch ex As Exception
		Logger.Info("Cannot set the same name on different virtual components")
	End Try
End If