Originally Posted by
danderson.71652
Crickets......I am not about to start an argument with myself even though I am currently the only person to reply, any Experts out ther to put me out of my misery?
Hi Danderson,
Sorry for being late. We understand your feelings. But the same time, most of the people here are working in some companies and are unable to sit in a relaxed mood to find a quick solution to certain questions (I don't mean every problem). So be patient with us if we are little bit late.
Based on your first post, I have done some coding. Again sorry for not going through all your codes. I hope you can incorporate this logic with your program. It sorts the text by X coordinates and if the X coordinates are same, it then sorts by Y axis. Just try this code
Code:
Sub SortTextByPos()
Dim objTxt As AcadText
Dim objSSet As AcadSelectionSet
Dim gpCode(0) As Integer: Dim dataVal(0) As Variant
Set objSSet = ThisDrawing.SelectionSets.Add("TxtSet")
gpCode(0) = 0: dataVal(0) = "Text"
ReSelect:
objSSet.SelectOnScreen gpCode, dataVal
If objSSet.Count <> 0 Then
Dim TxtPnt As Variant
Dim arTxtPnts() As Variant
Dim TxtBasePnt(0 To 1) As Double
Dim iDim As Integer
iDim = 0
ReDim Preserve arTxtPnts(objSSet.Count - 1, 2)
For Each objTxt In objSSet
If objTxt.Alignment = acAlignmentLeft Then
TxtPnt = objTxt.InsertionPoint
Else
TxtPnt = objTxt.TextAlignmentPoint
End If
TxtBasePnt(0) = TxtPnt(0): TxtBasePnt(1) = TxtPnt(1)
arTxtPnts(iDim, 0) = TxtPnt(0)
arTxtPnts(iDim, 1) = TxtPnt(1)
arTxtPnts(iDim, 2) = objTxt.TextString
iDim = iDim + 1
Next
arTxtPnts = SortArrayByCoords(arTxtPnts)
'<-- Display values for checking -->
Dim strOP As String
strOP = strOP & "X Coordinate" & vbTab & vbTab & "Y Coordinate" & _
vbTab & vbTab & "Text" & vbCrLf
strOP = strOP & String(22, "-") & vbTab & vbTab & String(22, "-") & _
vbTab & vbTab & String(5, "-") & vbCrLf
For i = 0 To UBound(arTxtPnts)
strOP = strOP & arTxtPnts(i, 0) & vbTab & vbTab & arTxtPnts(i, 1) & _
vbTab & vbTab & arTxtPnts(i, 2) & vbCrLf
Next
MsgBox strOP
'<-- End display -->
objSSet.Delete
End If
End Sub
Function SortArrayByCoords(ByVal arSource As Variant)
Dim i As Integer
Dim j As Integer
Dim dblTmpVal(2)
For i = UBound(arSource) To LBound(arSource) Step -1
For j = LBound(arSource) + 1 To i
'<-- Check for the X coordinates first and if they are equel -
'<-- compare the the Y coordinates -->
If ( _
(arSource(j - 1, 0) > arSource(j, 0)) _
Or ( _
(arSource(j - 1, 0) = arSource(j, 0)) _
And _
(arSource(j - 1, 1) < arSource(j, 1)) _
) _
) Then
dblTmpVal(0) = arSource(j - 1, 0)
dblTmpVal(1) = arSource(j - 1, 1)
dblTmpVal(2) = arSource(j - 1, 2)
arSource(j - 1, 0) = arSource(j, 0)
arSource(j - 1, 1) = arSource(j, 1)
arSource(j - 1, 2) = arSource(j, 2)
arSource(j, 0) = dblTmpVal(0)
arSource(j, 1) = dblTmpVal(1)
arSource(j, 2) = dblTmpVal(2)
End If
Next j
Next i
SortArrayByCoords = arSource
End Function
Is it ok Danderson....? Please give us a feedback.
har!s