By Adam Nagy
When you select a component occurrence in the UI the context menu provides you with the Constrained To option to select all constrained occurrences:
If you want to retrieve the same occurrences programmatically, then you can iterate through the constraints of the selected occurrence and store all the occurrences those constraints reference:
Sub ConstrainedTo() Dim asm As AssemblyDocument Set asm = ThisApplication.ActiveDocument Dim occSel As ComponentOccurrence Set occSel = asm.SelectSet(1) Dim tr As TransientObjects Set tr = ThisApplication.TransientObjects Dim coll As ObjectCollection Set coll = tr.CreateObjectCollection() Dim ac As AssemblyConstraint For Each ac In occSel.Constraints coll.Add ac.OccurrenceOne coll.Add ac.OccurrenceTwo Next ' If you want to ignore the originally' selected occurrence then you can remove it'coll.RemoveByObject occSel' Now we have all the occurrences' Let's list their names Dim text As String Dim occ As ComponentOccurrence For Each occ In coll text = text + occ.Name + vbCrLf Next MsgBox text End Sub
The result: