’把当前图纸中符合条件的圆替换为块(注:块在当前图纸中已存在)
Public Sub ChangeEntity(ByVal MinRadius As Double, ByVal MaxRadius As Double, _
ByVal BlockName As Variant, ByVal AutoSelect As Boolean)
On Error Resume Next
Dim ssobject As AcadCircle
Dim InsertionPoint(0 To 2) As Double
Dim NewBlock As AcadBlockReference
’创建选择集
Dim ssetObj As AcadSelectionSet
Set ssetObj = AcadDoc.SelectionSets("BlockCount")
If Err.Number <> 0 Then
Err.Clear
Set ssetObj = AcadDoc.SelectionSets.Add("BlockCount")
End If
’清空选择集
ssetObj.Clear
’创建过滤机制
Dim fType(0 To 6) As Integer
Dim fData(0 To 6) As Variant
’选择符合条件的所有图元-圆
If AutoSelect Then
’自动选择方式
ssetObj.Select acSelectionSetAll, , , fType, fData
Else
’提示用户选择
ssetObj.SelectOnScreen fType, fData
End If
If ssetObj.Count = 0 Then Exit Sub
’替换每一个圆为指定的块对象
For Each ssobject In ssetObj
InsertionPoint(0) = ssobject.Center(0)
InsertionPoint(1) = ssobject.Center(1)
InsertionPoint(2) = ssobject.Center(2)
On Error GoTo ErrHandle
Set NewBlock = AcadDoc.ModelSpace.InsertBlock(InsertionPoint, BlockName, 1, 1, 1, 0)
Set ssetObj = Nothing
Exit Sub
ErrHandle:
Select Case Err.Number
Case -2147418113
MsgBox "在当前图纸中找不到名称为: “" & BlockName & "” 的块参照,请确认块名!", vbCritical, "错误:"
Case Else
MsgBox Err.Number & Chr(13) & Err.Descri ption, vbCritical, "产生了以下错误:"
End Select
Err.Clear
End Sub
全部回复(3 )
只看楼主 我来说两句但无法在cad宏中找到,小弟不知该怎么运行,哪位大哥告诉小弟下!谢谢啦!!!
:L :L
[ 本帖最后由 ai361210 于 2009-10-17 08:24 编辑 ]
回复 举报
参数是内接圆半径,圆心。
回复 举报