feixiong52 发表于 2010-12-28 00:33:44

新手求助 VBA插入CAD问题

我想先在VBA里程序做好块,然后在CAD 命令行提示 通过鼠标选取插入点,然后通过鼠标左键点击模型空间一下后, 在自己想要的插入点 插入块,这个功能怎么做到?可以发一个能达到类似功能的源码 让我学习下么?

wsccmm 发表于 2010-12-28 08:24:23

Sub Ch10_InsertingABlock()
' 定义块
Dim blockObj As AcadBlock
Dim insertionPnt(0 To 2) As Double
insertionPnt(0) = 0
insertionPnt(1) = 0
insertionPnt(2) = 0
Set blockObj = ThisDrawing.Blocks.Add (insertionPnt, "CircleBlock")
' 向块中添加圆
Dim circleObj As AcadCircle
Dim center(0 To 2) As Double
Dim radius As Double
center(0) = 0
center(1) = 0
center(2) = 0
radius = 1
Set circleObj = blockObj.Set circleObj = blockObj.AddCircle(center, radius)
'获取插入点
Dim returnPnt As Variant
returnPnt = ThisDrawing.Utility.GetPoint(, "Enter a point: ")
' 插入块
Dim blockRefObj As AcadBlockReference
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock (returnPnt, "CircleBlock", 1#, 1#, 1#, 0)
ZoomAll
End Sub

feixiong52 发表于 2010-12-28 21:02:58

回复 wsccmm 的帖子

谢谢您,可是为什么用了您拷贝的源码后,无法实现ZOOMALL的功能呢?我鼠标点后,自动回到VBA操作菜单,再回CAD里未出现zoomall后的效果

chmenf087 发表于 2010-12-28 22:44:12

本帖最后由 chmenf087 于 2010-12-28 22:44 编辑

thisdrawing.sendcommand("_zoom" & vbcr & "all" & vbcr)

fwsw1986 发表于 2011-1-27 22:15:44

此方法正在使用中,好用
页: [1]
查看完整版本: 新手求助 VBA插入CAD问题