'S1为图块的名字或图块名字中的一个关键词语,S2为编号的前缀,S2为编号的后缀。
' 比如查找图纸中所有结构图框,那么S1="结构"
' 比如对图框进行编号 GS-01/12,那么S2="GS-" S3="/12"
Function BlockIndex(S1 As String, S2 As String, S3 As String)
'On Error Resume Next
Dim I As Integer
Dim BList() As AcadEntity
Dim E As AcadEntity
Dim B As AcadBlockReference
'将图中所以图框参照块添加到选择集中
For Each E In ThisDrawing.ModelSpace
If E.ObjectName = "AcDbBlockReference" Then
Set B = E
Prompt B.name & vbCrLf
If InStr(B.name, S1) > 0 Then
ReDim Preserve BList(I)
Set BList(I) = E
I = I + 1
End If
End If
Next
BlockPaiXu BList
Dim varAttributes
Dim N As Long
N = UBound(BList)
For I = 0 To N
Set B = BList(I)
ThisDrawing.ModelSpace.AddText I, BList(I).insertionPoint, 7000
varAttributes = B.GetAttributes
varAttributes(0).textString = S2 & Format(I + 1, "00") & "/" & Format(N + 1, "00") & S3
Next I
End Function
' 比如查找图纸中所有结构图框,那么S1="结构"
' 比如对图框进行编号 GS-01/12,那么S2="GS-" S3="/12"
Function BlockIndex(S1 As String, S2 As String, S3 As String)
'On Error Resume Next
Dim I As Integer
Dim BList() As AcadEntity
Dim E As AcadEntity
Dim B As AcadBlockReference
'将图中所以图框参照块添加到选择集中
For Each E In ThisDrawing.ModelSpace
If E.ObjectName = "AcDbBlockReference" Then
Set B = E
Prompt B.name & vbCrLf
If InStr(B.name, S1) > 0 Then
ReDim Preserve BList(I)
Set BList(I) = E
I = I + 1
End If
End If
Next
BlockPaiXu BList
Dim varAttributes
Dim N As Long
N = UBound(BList)
For I = 0 To N
Set B = BList(I)
ThisDrawing.ModelSpace.AddText I, BList(I).insertionPoint, 7000
varAttributes = B.GetAttributes
varAttributes(0).textString = S2 & Format(I + 1, "00") & "/" & Format(N + 1, "00") & S3
Next I
End Function
'Cad对象(图块按插入点)排序(x坐标从小到大,y坐标从小到大)
Function BlockPaiXu(ByRef BList() As AcadEntity)
Dim I As Long
I = UBound(BList)
Dim Plist() As Variant
ReDim Plist(I)
Dim Pmin As Variant
Dim Temp As Double
Dim J As Long, K As Long, N As Long, M As Long
Dim P1 As Variant
Dim P2 As Variant
Dim P3 As Variant
Dim B As AcadBlockReference
Dim E As AcadEntity
For J = 0 To I
Set B = BList(J)
MsgBox B.name
Plist(J) = B.insertionPoint
Next
'按x坐标排序
For J = 0 To I
For K = J + 1 To I
P1 = Plist(J)
P2 = Plist(K)
If P1(0) >= P2(0) Then
P3 = Plist(J) '=P1
Plist(J) = Plist(K) 'p1=P2
Plist(K) = P3 'P2 = P3
Set E = BList(J)
Set BList(J) = BList(K)
Set BList(K) = E
End If
Next K
Next J
'对x坐标相等的进行y坐标排序
For J = 0 To I
For K = 0 To I
P1 = Plist(J)
P2 = Plist(K)
If P1(0) = P2(0) Then
If P1(1) < P2(1) Then
P3 = Plist(J) '=P1
Plist(J) = Plist(K) 'p1=P2
Plist(K) = P3 'P2 = P3
Set E = BList(J)
Set BList(J) = BList(K)
Set BList(K) = E
End If
End If
Next K
Next J
End Function
Function BlockPaiXu(ByRef BList() As AcadEntity)
Dim I As Long
I = UBound(BList)
Dim Plist() As Variant
ReDim Plist(I)
Dim Pmin As Variant
Dim Temp As Double
Dim J As Long, K As Long, N As Long, M As Long
Dim P1 As Variant
Dim P2 As Variant
Dim P3 As Variant
Dim B As AcadBlockReference
Dim E As AcadEntity
For J = 0 To I
Set B = BList(J)
MsgBox B.name
Plist(J) = B.insertionPoint
Next
'按x坐标排序
For J = 0 To I
For K = J + 1 To I
P1 = Plist(J)
P2 = Plist(K)
If P1(0) >= P2(0) Then
P3 = Plist(J) '=P1
Plist(J) = Plist(K) 'p1=P2
Plist(K) = P3 'P2 = P3
Set E = BList(J)
Set BList(J) = BList(K)
Set BList(K) = E
End If
Next K
Next J
'对x坐标相等的进行y坐标排序
For J = 0 To I
For K = 0 To I
P1 = Plist(J)
P2 = Plist(K)
If P1(0) = P2(0) Then
If P1(1) < P2(1) Then
P3 = Plist(J) '=P1
Plist(J) = Plist(K) 'p1=P2
Plist(K) = P3 'P2 = P3
Set E = BList(J)
Set BList(J) = BList(K)
Set BList(K) = E
End If
End If
Next K
Next J
End Function
[本日志由 tiancao1001 于 2009-04-05 05:47 PM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |