szj612 发表于 2007-1-19 23:27:00

求教

本帖最后由 作者 于 2007-1-19 23:41:10 编辑 <br /><br /> <p>我是刚开始学习AUTOCAD VBA,想试着编一段,结果总是出错,因为没有老师,全靠自学,困难程度可想而知,幸好我找到了这个网站,看着这里高手如云,心里很是激动,又担心距离相差太大,没人愿意指点我.如有哪位老师不计较我的肤浅可笑,愿意指点我,在下万分感谢,愿择良日行拜师大礼.</p><p>下面是我的一段代码,可能有许多处低级错误,烦请老师们看看,帮我指正一下,谢谢了.</p><p>Sub dor()<br/>Dim cir As AcadCircle&nbsp; '我的想法是遍历选择集中的圆,标出圆心的x坐标</p><p>Dim cen(0 To 2) As Double&nbsp; '定义圆心<br/>Dim sset As AcadSelectionSet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '定义选择集<br/>Set sset = ThisDrawing.SelectionSets.Add("ss2") '<br/>sset.SelectOnScreen '<br/>On Error Resume Next '<br/>For Each cir In sset '<br/>cen(0) = cir.Center(0) '找出圆心坐标<br/>cen(1) = cir.Center(1)<br/>cen(2) = cir.Center(2)<br/>Dim pt(0 To 2) As Double<br/>pt(0) = cen(0): pt(1) = cen(1) - 5: pt(3) = 0 '&nbsp;&nbsp; 定义尺寸线,向下拉5单位</p><p><br/>Dim line As AcadLine</p><p>Set line = ThisDrawing.ModelSpace.AddLine(cen, pt) '画尺寸线</p><p><br/>Call ThisDrawing.ModelSpace.AddText(CStr(cen(0)), pt, 3) '标出坐标值</p><p>Next<br/>sset.Delete<br/>End Sub</p>

wyj7485 发表于 2007-1-22 08:48:00

Sub dor()
Dim cir As AcadCircle'我的想法是遍历选择集中的圆,标出圆心的x坐标
Dim cen(0 To 2) As Double'定义圆心
Dim sset As AcadSelectionSet '定义选择集
On Error Resume Next '程序只需要一个就可以了
Set sset = ThisDrawing.SelectionSets.Add("ss2") '
'建立圆的选择集最快了
Dim FilterType(0) As Integer
Dim FilterData(0) As Variant
FilterType(0) = 0: FilterData(0) = "circle" '过滤条件
sset.SelectOnScreen FilterType, FilterData
Dim pt(0 To 2) As Double '变量定义尽量放到循环外
Dim line As AcadLine
For Each cir In sset '
cen(0) = cir.Center(0) '找出圆心坐标
cen(1) = cir.Center(1)
cen(2) = cir.Center(2)
pt(0) = cen(0): pt(1) = cen(1) - 5: pt(3) = 0 '   定义尺寸线,向下拉5单位

Set line = ThisDrawing.ModelSpace.AddLine(cen, pt) '画尺寸线

Call ThisDrawing.ModelSpace.AddText(CStr(cen(0)), pt, 3) '标出坐标值
Next
sset.Delete
End Sub

szj612 发表于 2007-1-28 21:00:00

谢谢楼上老师,你的指点让我进步不少.
页: [1]
查看完整版本: 求教