Dim objDic1 As New Scripting.Dictionary
Dim objDic2 As New Scripting.Dictionary
Dim objDic3 As New Scripting.Dictionary
Dim objFSO As New Scripting.FileSystemObject
Sub CT79()
Dim objSS As AcadSelectionSet
Set objSS = ThisDrawing.SelectionSets.Add(ThisDrawing.SelectionSets.Count & Now & "79")
Dim DXF(1) As Integer
Dim DATA(1) As Variant
DXF(0) = 0: DATA(0) = "INSERT"
DXF(1) = 2: DATA(1) = "79_CT_DANG*"
objSS.SelectOnScreen DXF, DATA
Dim objBlkRef As AcadBlockReference
'==============================================================
objDic1.RemoveAll
objDic2.RemoveAll
objDic3.RemoveAll
Dim str0_SH As String, str0_n As Double, str0_dk As Double, str1_L As Double
'-----------------------------------------
For Each objBlkRef In objSS
str0_SH = Fn_GetValueBlockAtt(objBlkRef, "0_SH")
str0_n = Fn_GetValueBlockAtt(objBlkRef, "0_n")
If objDic1.Exists(str0_SH) = False Then
objDic1.Add str0_SH, str0_n
Else
objDic1(str0_SH) = objDic1(str0_SH) + str0_n
End If
Next ' ta da co objDic1( SH,n)
'-----------------------------------------
For Each objBlkRef In objSS
str0_SH = Fn_GetValueBlockAtt(objBlkRef, "0_SH")
str0_dk = Fn_GetValueBlockAtt(objBlkRef, "0_DK")
If objDic2.Exists(str0_SH) = False Then
objDic2.Add str0_SH, str0_dk
Else
objDic2(str0_SH) = objDic2(str0_SH)
End If
Next ' ta da co objDic2( SH,dk)
'-----------------------------------------
For Each objBlkRef In objSS
str0_SH = Fn_GetValueBlockAtt(objBlkRef, "0_SH")
str1_L = Fn_GetValueBlockAtt(objBlkRef, "1_L")
If objDic3.Exists(str0_SH) = False Then
objDic3.Add str0_SH, str1_L
Else
objDic3(str0_SH) = objDic3(str0_SH)
End If
Next ' ta da co objDic3( SH,cDai1Thanh)
'===============================gán các giá tri vao bien strText
Dim objKey As Variant
Dim strText As String
For Each objKey In objDic1.Keys
strText = strText & objKey & "_" & objDic1(objKey) & "_" & objDic2(objKey) & "_" & objDic3(objKey) & Chr(10)
Next
'===============================ghi bien strText ra man hinh cad
Dim varpOint As Variant
varpOint = ThisDrawing.Utility.GetPoint
Dim objMText As AcadMText
Set objMText = ThisDrawing.ModelSpace.AddMText(varpOint, 0, strText)
objMText.Height = 150
objMText.InsertionPoint = varpOint
objSS.Delete
End Sub
Function Fn_GetValueBlockAtt(ByVal objBlockRef As AcadBlockReference, ByVal strTagName As String) As String
Dim arrAttributes As Variant
Dim objAttRef As AcadAttributeReference
Dim i As Integer
Dim strA As String
If objBlockRef.HasAttributes = True Then
arrAttributes = objBlockRef.GetAttributes
For i = 0 To UBound(arrAttributes)
Set objAttRef = arrAttributes(i)
Select Case objAttRef.TagString
Case strTagName
Fn_GetValueBlockAtt = objAttRef.TextString
Exit Function
End Select
Next
End If
End Function