Hi, I got there with it eventually. This code will delete any instances of part with a specific name, place it in the assembly again and generate a result on the 1st iMate (i.e Part1 with Part2) which in my case was a composite iMate, then generate a result on the 2nd iMate (i.e Part1 with Part3) which was a single Insert iMate.
' Get the component definition of the currently open assembly.
' This will fail if an assembly document is not open.
Dim doc As AssemblyDocument
doc = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = doc.ComponentDefinition
Dim oComp As ComponentOccurrence
Dim oComps As ComponentOccurrences
oComps = doc.ComponentDefinition.Occurrences
Dim oOccEnumerator As ComponentOccurrencesEnumerator
'Delete any instances of files containing "Spring"
For Each oComp In oComps
If oComp.Name.Contains("Spring") Then
oComp.Delete
End If
Next
'Place part in assembly using automatically generated iMates (will generate a result for the 1st iMate in the placed part)
oOccEnumerator = oAsmCompDef.Occurrences.AddUsingiMates("fullfilepath\Spring.iam", False)
'Set part to flexible (remove if not required)
i = 1
For Each oComp In oComps
If oComp.Name.Contains("Spring") Then
oComp.Flexible = True
i = i+1
End If
Next
'Define two occurences
Dim oOcc1 As ComponentOccurrence
Dim oOcc2 As ComponentOccurrence
'Set two occurrences using their names as in model browser
oOcc1 = oAsmCompDef.Occurrences.ItemByName("Spring")
oOcc2 = oAsmCompDef.Occurrences.ItemByName("Panel")
'Define iMate1 on oOcc1
i = 1
For Each iMateDefinition In oOcc1.iMateDefinitions
If iMateDefinition.Name= "Insert1" Then
iMate1 = oOcc1.iMateDefinitions.Item(i)
Exit For
End If
i = i+1
Next
'Define iMate2 on oOcc2
i = 1
For Each iMateDefinition In oOcc2.iMateDefinitions
If iMateDefinition.Name= "Insert1" Then
iMate2 = oOcc2.iMateDefinitions.Item(i)
Exit For
End If
i = i+1
Next
' Create an iMate result between two iMate1 and iMate2
Dim oiMateResult As iMateResult
oiMateResult = oAsmCompDef.iMateResults.AddByTwoiMates(iMate1, iMate2)