[原创]给text加框的程序
<p>'文字画框<br/>Sub WZhk()<br/> On Error Resume Next<br/> <br/> Dim mypnt1 As Variant<br/> Dim mypnt2 As Variant<br/> mypnt1 = ThisDrawing.Utility.GetPoint(, "请选择左下角点:")<br/> mypnt2 = ThisDrawing.Utility.GetCorner(mypnt1, "请选择右上角点:")</p><p>'crossing 方法选择所有内部对象<br/> Dim sset1 As AcadSelectionSet<br/> If Not IsNull(ThisDrawing.SelectionSets.Item("SS1")) Then<br/> Set sset1 = ThisDrawing.SelectionSets.Item("SS1")<br/> sset1.Delete<br/> End If<br/> Set sset1 = ThisDrawing.SelectionSets.Add("SS1")</p><p>'定义过滤规则<br/> Dim filterType1(0) As Integer<br/> Dim filterData1(0) As Variant</p><p> filterType1(0) = 0<br/> filterData1(0) = "TEXT"<br/> sset1.Select acSelectionSetCrossing, mypnt1, mypnt2, filterType1, filterData1 ' 使用Crossing选择模式,选择内部所有对象(包含边界本身)</p><p> Dim ADTEXT As AcadText<br/> Dim MINPT As Variant<br/> Dim MAXPT As Variant<br/> Dim RECPL As AcadLWPolyline<br/> For Each ADTEXT In sset1<br/> ADTEXT.GetBoundingBox MINPT, MAXPT<br/> Set RECPL = 绘制矩形(MINPT, MAXPT, 0)<br/> Next<br/> <br/>End Sub<br/></p> <p>给text和mtext文字同时加框程序演示如下:</p><p> </p> 绘制矩形的函数呢? 通过对角两点绘制矩形的函数函数内容:
Function AddRectangle(varPnt1 As Variant, varPnt2 As Variant) As AcadLWPolyline
On Error GoTo Err_Control
Dim objSpace As AcadBlock
If ThisDrawing.ActiveSpace = acModelSpace Then
Set objSpace = ThisDrawing.ModelSpace
Else
Set objSpace = ThisDrawing.PaperSpace
End If
Dim plineObj As AcadLWPolyline
Dim points(0 To 7) As Double
points(0) = varPnt1(0): points(1) = varPnt1(1)
points(2) = varPnt1(0): points(3) = varPnt2(1)
points(4) = varPnt2(0): points(5) = varPnt2(1)
points(6) = varPnt2(0): points(7) = varPnt1(1)
Set plineObj = objSpace.AddLightWeightPolyline(points)
plineObj.Closed = True
Set AddRectangle = plineObj
Exit_Here:
Exit Function
Err_Control:
Resume Exit_Here
End Function
加的方框角度是固定的0度,并不会随文字角度而变化
页:
[1]