- Sub PatchInsertAttBlock()
- '设置给定坐标文件路径
- Dim fileName
- fileName = ThisDrawing.Path & "\坐标表.txt"
- '使用顺序方式打开文本文件
- Dim fNo
- fNo = FreeFile
- Open fileName For Input As #fNo
- '顺序的根据每行坐标插入块并赋值块属性
- Dim vID, BlName, ValueStr
- Dim i As Long, j As Long, k As Long
- Dim vAtt, attTag, attText
- Dim AttBlR As AcadBlockReference
- Dim Ip(2) As Double
- Ip(2) = 0
- Do
- Line Input #fNo, BlName
- If k > 0 Then '坐标文件第一行标题调过
- vID = Split(BlName, ",")
- ValueStr = vID(2)
- BlName = "原高程"
- '转换坐标为double类型并插入块参照
- Ip(0) = Val(vID(0)): Ip(1) = Val(vID(1))
- Set AttBlR = ThisDrawing.ModelSpace.InsertBlock(Ip, BlName, 1, 1, 1, 0)
- '读取块参照属性值,并设置新值
- vAtt = AttBlR.GetAttributes
- If IsArray(vAtt) Then
- For i = 0 To UBound(vAtt)
- If vAtt(i).TagString = BlName Then vAtt(i).TextString = ValueStr
- Next
- End If
- End If
- k = k + 1
- Loop Until EOF(fNo)
- Close #fNo
- ThisDrawing.Utility.Prompt "共插入块个数:" & k - 1
- End Sub
|