Z-order iterating through objects

My diagrams build a map from objects in differant files, and therefore there is no means of saving the order that items are displayed on the screen.
To solve this I want to store the z-order of objects in a layer by partid to a seperate file, but I am having trouble getting the bottom most object in a layer so i can start iterating through them.
I want to use something like:
dim BottomObject as GoObject = myLayer(Nothing,1)
but this returns nothing. Is there anyway of doing this, or any other means of saving and loading the z-order of objects?

The z-order is the order of the top-level objects in the Document. In other words, the first item is the backmost, and the last one in the list is the frontmost.

Jake the following code does what I want…

.... but there must be a cleaner neater way!
Public Function GetLayerChildrenZOrder(ByVal lyr As GoLayer) As String
Dim gobj As GoObject = Nothing
For Each gobj2 As GoObject In lyr
gobj = gobj2
While Not lyr.NextObject(gobj, 1) Is Nothing
gobj = lyr.NextObject(gobj, 1)
End While
Dim ItmZorder As String = ""
While Not gobj Is Nothing
If TypeOf (gobj) Is IGoIdentifiablePart Then
ItmZorder += String.Format("{0},", CType(gobj, IGoIdentifiablePart).PartID)
End If
gobj = lyr.NextObject(gobj, -1)
End While
ItmZorder = ItmZorder.Trim(",")
Return ItmZorder
End Function
Public Sub SetLayerChildrenZOrder(ByVal lyr As GoLayer, ByVal ItmZOrder As String)
'restore zorder of objects
For Each pid As String In ItmZOrder.Split(",")
If IsNumeric(pid) Then
Dim gobj As GoObject = Me.Document.FindPart(CInt(pid))
If Not gobj Is Nothing Then lyr.MoveBefore(Nothing, gobj)
End If
End Sub

I’m not following what you’re doing here, but I don’t understand why it isn’t basically:

Dim ItmZorder As String = ""
For Each obj As GoObject In goView1.Document ' (or layer)
Dim p As IGoIdentifiablePart = TryCast(obj, IGoIdentifiablePart)
If p IsNot Nothing Then
ItmZorder += p.PartID.ToString() + ","
End If

The main objective is to get a list of the objects ordered by their z order, so that I can reposition them in the correct zorder when the user reloads a file and my app rebuilds the map

I've found ".SortByZOrder" which might be a little better!!!
- although I'm having difficulty trying to understand how to apply it to the objects within a layer!

You don’t need to sort. The order in the Layer is the Z order.

if you want the frontmost object first, add a ".Backwards" to the end of your
For Each obj As GoObject In goView1.Document.Backwards


Thanks! Sorry for wasting time!