VBA中如何获得CAD modelspace中坐标
<p>Hi every master,</p><p>我是VBA编程新手,现有一问题要向高手请教,VBA中如何获得AutoCAD modelspace中所有circle和块的中心坐标,</p><p>我试了很久,都没实现,不知道可以用什么方法实现?thanks.</p><p> </p> <p>使用选择集,选择圆和块。</p><p>如果是圆,则可直接读到圆心。</p><p>如果是块,则使用GetBoundingBox来取得对角点后计算中心点。</p> <p>谢谢版主的解答 ,</p><p>只不过我还是不知道用哪个命令来获取圆心,我的目的是这样的,我想遍历图形中所有的circle and block and polyline的中心位置,然后把它们中心坐标写到一个文本文件中去,不知道要用到哪几个command来实现,我买了版主二次开发的一本书,可书上也没有这方面的教材,还望版主不吝赐教。Thanks.</p> 书上没有的找帮助Sub Example_Center()
Dim circObj As AcadCircle
Dim currCenterPt(0 To 2) As Double
Dim newCenterPt(0 To 2) As Double
Dim radius As Double
' Define the initial center point and radius for the circle
currCenterPt(0) = 20: currCenterPt(1) = 30: currCenterPt(2) = 0
radius = 3
' Create the circle in model space
Set circObj = ThisDrawing.ModelSpace.AddCircle(currCenterPt, radius)
ZoomAll
MsgBox "The center point of the circle is " & currCenterPt(0) & ", " & currCenterPt(1) & ", " & currCenterPt(2), vbInformation, "Center Example"
' Change the center point of the circle
newCenterPt(0) = 25: newCenterPt(1) = 25: newCenterPt(2) = 0
circObj.center = newCenterPt
circObj.Update
' Query the results of the new center position
' Notice the output from the center property is a variant
Dim centerPoint As Variant
centerPoint = circObj.center
MsgBox "The center point of the circle is " & centerPoint(0) & ", " & centerPoint(1) & ", " & centerPoint(2), vbInformation, "Center Example"
End Sub
页:
[1]