Not sure how legible this is, but at one point of this function it passes a textual list of shape IDs with coordinates to a numeric sort on those coordinates. It then uses the ids to retrieve a list of shapes in spatial order.
Code:
-- GET THE CHILDREN OF THE NODE IN THEIR LEFT RIGHT (OR TOP DOWN) SEQUENCE
-- (The OG Applescript library doesn't expose outline structure,
-- so we have to assume that Automatic Layout has been run, so that we can read the sibling sequence spatially)
on GetChildren(oParent, iAxis)
tell application id "OGfl"
-- Create a textual list of fields ID + horiz or vert position
set {lstOrigin, lstID} to {origin, id} of (destination of outgoing lines of oParent)
set strRows to ""
set lngID to length of lstID
repeat with i from 1 to lngID
set strRows to strRows & (item iAxis of (item i of lstOrigin)) & tab & item i of lstID & linefeed
end repeat
if strRows ≠ "" then
set lstID to paragraphs of (do shell script "echo " & quoted form of (texts 1 thru -2 of strRows) & " | sort -n | cut -f 2")
set lstChiln to {}
tell canvas of oParent
repeat with strID in lstID
set lngID to strID as integer
if not (plstSeen contains lngID) then
set end of plstSeen to lngID
set oChild to shape id lngID
set end of lstChiln to {oChild, my GetChildren(oChild, iAxis)}
end if
end repeat
end tell
return lstChiln
else
return {}
end if
end tell
end GetChildren