Hi AMIR,
first of all, I guess you have to find the select object coordinates for example:
Dim MyObject As AcadEntity
Dim MyCoord() As Double
Dim MyX As Double
Dim MyY As Double
Dim MyZ As Double
Dim ss As AcadSelectionSet
Dim FilterType(0) As Integer
Dim FilterData(0) As Variant
FilterType(0) = 0
FilterData(0) = "TEXT,MTEXT"
Set ss = ThisDrawing.SelectionSets.Add("MySS")
ss.SelectOnScreen FilterType, FilterData
For Each MyObject In ss
MyCoord = MyObject.InsertionPoint
MyX = MyCoord(0)
MyY = MyCoord(1)
MyZ = MyCoord(2)
Next
ss.Delete
Best Solution could be put in three different arrays and sort by single array, later you can move object inside drawing based upon sorted coordinates.
Dim MyX() As Double
Dim MyY() As Double
Dim MyZ() As Double
Dim A As integer
....
'For Each MyObject In ss
' MyCoord = MyObject.InsertionPoint
' MyX = MyCoord(0)
' MyY = MyCoord(1)
' MyZ = MyCoord(2)
'Next
A = 1
ReDim MyX(ss.Count) ' Array first Dimension was uncounted Dim MyX() As Double
ReDim MyY(ss.Count) ' Array first Dimension was uncounted Dim MyY() As Double
ReDim MyZ(ss.Count) ' Array first Dimension was uncounted Dim MyZ() As Double
For Each MyObject In ss
MyCoord = MyObject.InsertionPoint
MyX(A) = MyCoord(0)
MyY(A) = MyCoord(1)
MyZ(A) = MyCoord(2)
A = A + 1
Next
ss.Delete
iFirstRow = LBound(MyY)
iLastRow = UBound(MyY)
For i = iFirstRow To iLastRow - 1
For j = i + 1 To iLastRow
If MyY(i) > MyY(j) Then
varTemp = MyY(j)
MyY(j) = MyY(i)
MyY(i) = varTemp
End If
Next j
Next i
So now you have Y coordinates ordered by lower to higher.