本文主要是介绍获取CAD图形边界框(getboundingbox和getvariable)及字外加圆实例应用——vba实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
获取某个实体的边界框可用getboundingbox方法(注意:坐标需定义为变体变量variant)
Obj.GetBoundingBox minExt, maxExt
获取整图的边界框可用获取系统变量方法
youshang = ThisDrawing.GetVariable("extmax") '获取系统变量取得整图的边界
zuoxia = ThisDrawing.GetVariable("extmin")
代码如下:
Sub 获取边界框boundingbox()'yngqq443440204@2024年4月18日10:55:10' 画条线获取边界框并取得边界框的左下角和右上角坐标(三维)Dim startPoint(0 To 2) As Double, endPoint(0 To 2) As DoubleDim lineObj As AcadLine, youshang As Variant, zuoxia As VariantstartPoint(0) = 2#: startPoint(1) = 2#: startPoint(2) = 0#endPoint(0) = 4#: endPoint(1) = 4#: endPoint(2) = 0#Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)ZoomExtents '缩放到范围Dim minExt As Variant, maxExt As VariantlineObj.GetBoundingBox minExt, maxExt' 获取最小和最大范围MsgBox "线的边界范围是:" & vbCrLf _& "最小范围: " & minExt(0) & "," & minExt(1) & "," & minExt(2) _& vbCrLf & "最大范围: " & maxExt(0) & "," & maxExt(1) & "," & maxExt(2), vbInformation, "qq443440204"youshang = ThisDrawing.GetVariable("extmax") '获取系统变量取得整图的边界zuoxia = ThisDrawing.GetVariable("extmin")Stop
End Sub
结果如下:
通过系统变量的方法获取范围比getboundingbox方法获取范围略微大点。
以下为循环字外加圆实例:
Public Sub 循环字外加圆()
'yngqq443440204@2024年4月18日11:48:49
On Error GoTo errorcontrol
Do
Dim objText As AcadText, ptPick As Variant
ThisDrawing.Utility.GetEntity objText, ptPick, "拾取文字:"
Dim ptMin As Variant, ptMax As Variant
objText.GetBoundingBox ptMin, ptMax
Dim ptCenter(0 To 2) As Double
ptCenter(0) = (ptMin(0) + ptMax(0)) / 2
ptCenter(1) = (ptMin(1) + ptMax(1)) / 2
ptCenter(2) = 0
Dim radius As Double
radius = Sqr((ptMin(0) - ptMax(0)) ^ 2 + (ptMin(1) - ptMax(1)) ^ 2) / 2
Dim objCircle As AcadCircle
Set objCircle = ThisDrawing.ModelSpace.AddCircle(ptCenter, radius)
Loop
errorcontrol:
Err.Clear
Exit Sub
End Sub
这篇关于获取CAD图形边界框(getboundingbox和getvariable)及字外加圆实例应用——vba实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!