How can I reference a child in an assembly?

If I want to reference a child of an assembly as an object so that I can save it specifically instead of the top level component how would I do that.

This is how I would do it with a non assembly.
Public dispPart as NXOpen.Part = theSession.Parts.Display
dispPart = thesession.parts.display
part1 = dispPart

But I want to reference a child in the assembly specifically so I can save that child as a new part.

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
fileNameNoExt = Child.DisplayName

This wont be the correct code but I want something like

part1 = child

Thanks for all the help i know i've been asking a lot of questions lately.

part1 = child.Prototype.OwningPart

When I use this to reference a child for a save-as it just saves the parent instead.

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
childpart = child.prototype.owningpart
fileNameNoExt = Child.DisplayName
fileNameNoExt = fileNameNoExt.Substring(0, Len(fileNameNoExt)-2) 'GETS THE DISPLAYED PART NAME AND TRIMS OFF TWO LETTERS FROM THE STRING IN ORDER TO REMOVE THE FORWARD SLASH AND REVISION NUMBER
for j = 0 to UBound(PartNames)
if fileNameNoExt = PartNames(j) then
match = 1
end if
next
if match <> 1 then
Redim Preserve PartNames(ArrayIndex)
PartNames(ArrayIndex) = fileNameNoExt
lw.writeline("I added at the 3rd bottom most level")
for intchecker = 0 to UBound(PartNames2DArray)
if PartNames(ArrayIndex) = PartNames2DArray(intchecker, 0) then
savename = PartNames2DArray(intchecker, 1)
part1 = childpart
saveas
exit for
end if
next
ArrayIndex = ArrayIndex + 1
end if
match = 0

What am I doing wrong?

sub SaveAs()

if savename = "" then
theUISession.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "The Save-As name is blank or an error")
exit sub
end if

readOnly1 = dispPart.IsReadOnly
partOperationCopyBuilder1 = theSession.PdmSession.CreateCopyOperationBuilder(NXOpen.PDM.PartOperationBuilder.OperationType.SaveAs)
partOperationCopyBuilder1.SetOperationSubType(NXOpen.PDM.PartOperationCopyBuilder.OperationSubType.Default)
partOperationCopyBuilder1.DefaultDestinationFolder = ":Newstuff"
partOperationCopyBuilder1.DependentFilesToCopyOption = NXOpen.PDM.PartOperationCopyBuilder.CopyDependentFiles.All
partOperationCopyBuilder1.ReplaceAllComponentsInSession = True
partOperationCopyBuilder1.SetDialogOperation(NXOpen.PDM.PartOperationBuilder.OperationType.Revise)
selectedparts1(0) = dispPart
partOperationCopyBuilder1.SetSelectedPartsToCopy(selectedparts1, failedparts1)
partOperationCopyBuilder1.CreateLogicalObjects(logicalobjects1)
sourceobjects1 = logicalobjects1(0).GetUserAttributeSourceObjects()
sourceobjects2 = logicalobjects1(0).GetUserAttributeSourceObjects()
sourceobjects3 = logicalobjects1(0).GetUserAttributeSourceObjects()
sourceobjects4 = logicalobjects1(0).GetUserAttributeSourceObjects()
sourceobjects5 = logicalobjects1(0).GetUserAttributeSourceObjects()
partOperationCopyBuilder1.SetDialogOperation(NXOpen.PDM.PartOperationBuilder.OperationType.SaveAs)
sourceobjects6 = logicalobjects1(0).GetUserAttributeSourceObjects()
selectedparts2(0) = dispPart
partOperationCopyBuilder1.SetSelectedPartsToCopy(selectedparts2, failedparts2)
partOperationCopyBuilder1.CreateLogicalObjects(logicalobjects2)
sourceobjects7 = logicalobjects2(0).GetUserAttributeSourceObjects()
sourceobjects8 = logicalobjects2(0).GetUserAttributeSourceObjects()
sourceobjects9 = logicalobjects2(0).GetUserAttributeSourceObjects()
sourceobjects10 = logicalobjects2(0).GetUserAttributeSourceObjects()
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(nullNXOpen_BasePart, objects1, NXOpen.AttributePropertiesBuilder.OperationType.None)
objects2(0) = sourceobjects7(0)
attributePropertiesBuilder1.SetAttributeObjects(objects2)
attributePropertiesBuilder1.Title = "DB_PART_NO"
attributePropertiesBuilder1.Category = "N4_NonDesignPart"
attributePropertiesBuilder1.StringValue = savename
changed1 = attributePropertiesBuilder1.CreateAttribute()
sourceobjects11 = logicalobjects2(0).GetUserAttributeSourceObjects()
nXObject1 = partOperationCopyBuilder1.CreateAttributeTitleToNamingPatternMap(attributetitles1, titlepatterns1)
objects3(0) = logicalobjects2(0)
properties1(0) = nXObject1
errorList1 = partOperationCopyBuilder1.AutoAssignAttributesWithNamingPattern(objects3, properties1)
errorList1.Dispose()
errorMessageHandler1 = partOperationCopyBuilder1.GetErrorMessageHandler(True)
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Save Parts As")
theSession.DeleteUndoMark(markId2, Nothing)
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Save Parts As")
partOperationCopyBuilder1.ValidateLogicalObjectsToCommit()
errorMessageHandler2 = partOperationCopyBuilder1.GetErrorMessageHandler(True)
errorMessageHandler3 = partOperationCopyBuilder1.GetErrorMessageHandler(True)
nXObject2 = partOperationCopyBuilder1.Commit()
errorMessageHandler4 = partOperationCopyBuilder1.GetErrorMessageHandler(True)
theSession.DeleteUndoMark(markId3, Nothing)
partOperationCopyBuilder1.Destroy()
attributePropertiesBuilder1.Destroy()
partstocheckin1(0) = dispPart
operationErrors1 = dispPart.PDMPart.CheckinParts(partstocheckin1, checkininput1)
operationErrors1.Dispose()
part1 = nothing
savename = ""

end sub

The SaveAs Subroutine appears to operate on the "dispPart"; which, I assume, is a reference to the current display part. If so, make sure that you are changing the display part and updating the "dispPart" reference. Alternatively, and this is my suggestion, you could change the SaveAs subroutine to accept a parameter, and pass in the part that you want to save. Update the code to work on the passed in part rather than "dispPart".

ah yes you're absolutely right.

So would I write it like disppart = child.prototype.owningpart

Okay that wasn't correct I'm getting an error that "object reference not set to an instance of an object" I basically made the disppart equal what I wrote above under each child and children loop. I'm pretty new to this so sorry if this is basic stuff.

But seriously thanks for the reply hopefully you can help me out some more.

For anyone reading this chain in the future the solution is

dispPart = CType(theSession.Parts.FindObject("@DB/" & child.GetStringAttribute("DB_PART_NO") & "/" & child.GetStringAttribute("DB_PART_REV")), NXOpen.Part)

this is for team center.

That's certainly one way of doing it.
Thanks for posting the solution that you found.