Code:
Function reNumberPanels()
Dim myBlock As AcadBlockReference
Dim oBkRef As AcadBlockReference
Dim i As Integer, J As Integer, temp As Double
Dim DArray() As Double
Dim PanelNumber As Integer
Dim ssetObj As AcadSelectionSet
Dim mode As Integer
Dim gpCode(0) As Integer
Dim dataValue(0) As Variant
Dim varAttributes As Variant, k As Integer
Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
mode = acSelectionSetAll
gpCode(0) = 8
dataValue(0) = "ATTRIB"
ssetObj.Select mode, , , gpCode, dataValue
'******** Determine the coordinates for the SCP* blocks and set in Data Array **************'
Dim ik As Integer
ik = -1
For i = 0 To ssetObj.Count - 1
If TypeOf ssetObj(i) Is AcadBlockReference Then
Set oBkRef = ssetObj(i)
If UCase(oBkRef.Name) Like "SCP*" Then
ik = ik + 1
ReDim Preserve DArray(1, ik)
DArray(0, ik) = oBkRef.InsertionPoint(0)
DArray(1, ik) = oBkRef.InsertionPoint(1)
End If
End If
Next i
'******** Sort the dtat array by x then y coordinate **************'
For i = 0 To UBound(DArray, 2) - 1
For J = i + 1 To UBound(DArray, 2)
If Round(DArray(0, i), 2) > Round(DArray(0, J), 2) Then
temp = DArray(0, i)
DArray(0, i) = DArray(0, J)
DArray(0, J) = temp
temp = DArray(1, i)
DArray(1, i) = DArray(1, J)
DArray(1, J) = temp
Else
If Round(DArray(0, i), 2) = Round(DArray(0, J), 2) Then
If Round(DArray(1, i), 2) > Round(DArray(1, J), 2) Then
temp = DArray(0, i)
DArray(0, i) = DArray(0, J)
DArray(0, J) = temp
temp = DArray(1, i)
DArray(1, i) = DArray(1, J)
DArray(1, J) = temp
End If
End If
End If
Next
Next
'******** Search the for the "PANELNUMBER" attribute by Data Array and reset values sequtinally **************'
If ssetObj.Count > 0 Then ssetObj.Clear
ssetObj.Select mode, , , gpCode, dataValue
For i = 0 To ssetObj.Count - 1
If TypeOf ssetObj(i) Is AcadBlockReference Then
Set oBkRef = ssetObj(i)
If UCase(oBkRef.Name) Like "SCP*" Then
For J = 0 To UBound(DArray, 2) - 1
If Round(DArray(0, J), 2) = Round(oBkRef.InsertionPoint(0), 2) And Round(DArray(1, J), 2) = Round(oBkRef.InsertionPoint(1), 2) Then
varAttributes = oBkRef.GetAttributes
For k = LBound(varAttributes) To UBound(varAttributes)
If varAttributes(k).TagString = "PANELNUMBER" Then
varAttributes(k).TextString = J + 1
varAttributes(k).Update
End If
Next k
End If
Next
End If
End If
Next
ThisDrawing.SelectionSets("SSET").Delete
End Function
Bookmarks