请问怎样修改此段程序?VB中做CAD外部引用
<p>我按照国防工业出版社的《AUTOCAD ACTIVEX/VBA二次开发技术基础及应用实例》的VB编一个例子:外部引用</p><p>但是一编译就是出错,请看看怎么回事?</p><p>Private Sub Command3_Click()<br/> Dim xrefInserted As AcadExternalReference<br/> Dim insertionPnt(0 To 2) As Double<br/> Dim PathName As String<br/> insertionPnt(0) = 10: insertionPnt(1) = 100: insertionPnt(2) = 0<br/> PathName = "D:\Personal\My Documents\My eBooks\border60.dwg"<br/> <font color="#ff0000"> Set xrefInserted = ThisDrawing.ModelSpace.AttachExternalReference(PathName, "WXREF", insertionPnt, 1, 1, 1, 0, False)<br/></font>End Sub</p><p>一编译红色区域就讲出错,望高手看看。</p> <p>给你完整代码<br/>Private Sub Command1_Click()<br/>'AutoCAD与visual basic连接<br/>On Error Resume Next<br/>Set obj_Acad = GetObject(, "autocad.application")<br/>If Err Then<br/> Err.Clear<br/> On Error Resume Next<br/> Set obj_Acad = CreateObject("autocad.application")<br/> If Err Then<br/> Err.Clear<br/> MsgBox "不能运行AutoCAD,请检查是否安装!", vbOKCancel, "警告!"<br/> Exit Sub<br/> End If<br/>End If<br/>obj_Acad.Visible = True<br/>Set obj_Doc = obj_Acad.ActiveDocument<br/>Set obj_ModelSpace = obj_Doc.ModelSpace</p><p><br/> Dim xrefInserted As Object<br/> Dim insertionPnt(0 To 2) As Double<br/> Dim PathName As String<br/> Dim tempBlock As Object<br/> Dim msg As String<br/> insertionPnt(0) = 10: insertionPnt(1) = 100: insertionPnt(2) = 0<br/> PathName = "D:\Personal\My Documents\My eBooks\border60.dwg"<br/> Set xrefInserted = obj_ModelSpace.AttachExternalReference(PathName, "WXREF", insertionPnt, 1, 1, 1, 0, False)<br/> GoSub ListBlocks<br/> Exit Sub</p><p>ListBlocks:<br/> msg = vbCrLf <br/> For Each tempBlock In obj_Doc.Blocks<br/> msg = msg & tempBlock.Name & vbCrLf <br/> Next<br/> MsgBox "图中包含的块有: " & msg<br/> Return<br/>End Sub</p><p></p><p></p><p>*************************************************************</p><p>西北凡人-----http://www.abofanyi.com/blog</p> 不错,谢谢 azjmjsj 发表于 2008-3-30 19:45 static/image/common/back.gif给你完整代码Private Sub Command1_Click()'AutoCAD与visual basic连接On Error Resume NextSet obj_Acad = ...
调试了下怎么不行?其它人可以吗?
xrefInserted的返回值是nothing图片没显示出来
望指教 谢谢 在VB中调用CAD,ThisDrawing.不可用,应该用acitvedocument 完整代码应该没问题啊 geabus 发表于 2011-12-8 10:14 static/image/common/back.gif
完整代码应该没问题啊
是没用ThisDrawing 可是我调试了很多次了
AttachExternalReference这句总是不成功,返回错误:访问额文件失败 它的对象值是nothing
这跟版本有关系吗?用的是autocad2007
你调试通过了?
页:
[1]