Cycling through Assembly Children - structure isn't updated

So I have created a recursive function to go through all children of the current displayed part that contain some text in their display name. I use a method like this:

Sub WalkAssemblyTree(ByVal c As Component, ByVal indent As String)

Dim children As Component() = c.GetChildren()
Dim newIndent As String
Dim loadStatus1 As UFPart.LoadStatus = Nothing
For Each child As Component In children

If indent.Length = 0 Then
newIndent = " "
Else
newIndent = indent & " "
End If
Dim theInst As NXOpen.Tag = ufs.Assem.AskInstOfPartOcc(child.Tag)
Try

If child.getStringAttribute("DB_PART_NAME").Contains("IA-WELDS") = TRUE or child.getStringAttribute("DB_PART_NAME").Contains("WLD_") = true Then

ufs.Assem.EnsureChildLoaded(theInst, loadStatus1)

End If
Catch ex As Exception
Echo("Exception: " & ex.Message())
End Try

WalkAssemblyTree(child, newIndent)

Next
End Sub

This method works well for almost everything. The problem I have is that none of the subassembly files are loaded. Initially looking at the tree for one item, it shows one of its components as a part (not assembly, like it doesn't have any children) but if I actually open the assembly, I discover that the component it thought was a part, is actually an assembly. This creates a problem with my method, as it will not find the children of that component since it things it is a part, and not an assembly.

Is there a way to make my search look inside this type of a file or to update the treeview structure to be accurate to what actually exists?

Here's a link to some code that I've been using to ensure that components are loaded.

http://nxjournaling.com/comment/718#comment-718

I have looked and tried using the method shown there, however that function opens all the parts (displaying them too). I want to only load the tree, not display all parts otherwise it takes WAY too long for what I am after. Do you know how to only load the tree?

I depends on what you mean by "only load the tree". If you want to load "structure only" or load all the components with the empty reference set, you can adjust the load options before opening the assembly file.

If you need a different result than above, please explain and detail how you would accomplish it in interactive NX. Recording a journal of the process in interactive NX usually gets you most of the way there.

I think I found a round about solution... The problem comes that NX can't tell if a component is an assembly or a part until it opens the component. Therefore I wrote it so that it goes line by line down the tree, opening everything one at a time. Once opened, I have it check the number of children on the file it just opened. If the number = 0 then it is a part and it will then close the file. This results in the entire assembly open minus the parts. It is a little slow on large assemblies but I believe this is the only way. Thank you for your help.

If you are using native NX (no PLM system attached to it), you can use ugpc.exe and/or ug_edit_part_names.exe to see if they are piece parts or assemblies. These programs are command line utilities that ship with NX, you can find them in the {NX install}\UGII folder (NX 10 and below, I think NX 11 moved some stuff around to a "bin" folder). You'll need to parse the output to get the info you want, but it may help speed things up as these utilities do not need to fully open the part file, they just analyze the references contained in the file structure.

I don't have any example code listed on the site for calling these particular utilities, but it would be similar to the code for converting part units found in this article:
http://nxjournaling.com/content/convert-part-units