Since it sounds like you are looping over the product I think
the bill of materials example will be more relevant. The example
also navigates through the tree recursively to get to the leaf
level nodes, so if you are only interested in first level children
you could simplify the code. Here is an excerpt from the most
useful section of the code:
Generating Bill Of Materials (BOM) source
Sub NavigateProductStructure(oProductEditor)
'Error handling
On Error GoTo ErrorSub
'Initializes the global variable
strBrowsedPLMCompIDAttr = ""
iNewObjectIndex = 0
'Retrieves the Product Service from the editor
Dim oProductService As PLMProductService
Set oProductService = oProductEditor.GetService("PLMProductService")
'Retrieves the Root Product Occurrence from the current VPM Editor to navigate
Dim oVPMRootOccOnRoot As VPMRootOccurrence
Set oVPMRootOccOnRoot = oProductService.RootOccurrence
'Retrieves the Root Reference from the occurrence model
Dim oVPMRefOnRoot As VPMReference
Set oVPMRefOnRoot = oVPMRootOccOnRoot.ReferenceRootOccurrenceOf
'Displays the Root Product Reference name
strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + oVPMRefOnRoot.Name + vbCrLf
'Navigates the Product Reference
'(Call for Navigate on the retrieved Reference)
NavigateProdReference oVPMRefOnRoot, 1
'Displays the Occurrence Product Model Contents in the Message Box
MsgBox strBrowsedPLMCompIDAttr
'Clears the display contents
strBrowsedPLMCompIDAttr = ""
'Error handling
GoTo EndSub
ErrorSub:
MsgBox Err.Description
EndSub:
End Sub
'
'--------------------------------------------------------------------------
'Navigates the Product Reference
' Input : the Product Reference
' depth of the object in hierarchy
'--------------------------------------------------------------------------
Sub NavigateProdReference(oProdRef, depth)
'Error handling
On Error GoTo ErrorSub
'Retrieves the list of instances within the input reference
Dim oListChildrenInstances As VPMInstances
Set oListChildrenInstances = oProdRef.Instances
'Navigates through each child Reference recursively
'Loop through the List of child instances
For i = 1 To oListChildrenInstances.Count
'Retrieves the Child instance from the list
Dim oVPMInst As VPMInstance
Set oVPMInst = oListChildrenInstances.Item(i)
'Indent the PLM entity appropriately
For spaceCnt = 1 To depth
strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + vbTab
Next spaceCnt
'Retrieves the Reference of the instance
Dim oVPMRef As VPMReference
Set oVPMRef = oVPMInst.ReferenceInstanceOf
'---------------------------------------------------------------
'2.1- Retrieves the Leaf nodes
'---------------------------------------------------------------
'Retrieve count of Children Instances
Dim oListChildrenInstToIdentifyLeafNode As VPMInstances
Set oListChildrenInstToIdentifyLeafNode = oVPMRef.Instances
Dim StrNewObjRef As String
StrNewObjRef = ""
'Zero count of Children Instances shows that its leaf node
If 0 = oListChildrenInstToIdentifyLeafNode.Count Then
'-----------------------------------------------------------------
'2.2- Count and display leaf node occurrences
'-----------------------------------------------------------------
'Update its status for new or already exist node Reference in list
StrNewObjRef = GetLeafNodeStatusAndAddCount(oVPMRef)
End If
'Prepare the string for displaying purpose
strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + oVPMRef.GetAttributeValue("PLM_ExternalID") + oVPMRef.GetAttributeValue("revision") + " " + "("
strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + oVPMInst.GetAttributeValue("PLM_ExternalID") + ")" + StrNewObjRef + vbCrLf
'Navigate further into this VPM Ref. A recursive call to Navigate follows
NavigateProdReference oVPMRef, depth + 1
'Next ref
Next i
'Error handling
GoTo EndSub
ErrorSub:
MsgBox Err.Description
EndSub:
End Sub