关于用VB.NET通过COM连接AUTOCAD2010读取块的问题请教。
各位,有个关于COM连接AUTOCAD的问题请教。之前我用VB6写了个针对AUTOCAD2010从DWG文件中读取块的程序,现在想升级到VB.NET2010,经过一番折腾后,目前这个问题无法解决,不知道在VB.NET中如何从其他的DWG文件中导入块,然后再加入现在的绘图中。
我使用如下命令调用子程序:
Call GetBlocksFromDwg("d:\abc.dwg", obj_Doc)
obj_Doc的定义如下:
Dim obj_Doc As Autodesk.AutoCAD.Interop.AcadDocument
之前的VB6部分代码:
Private Sub GetBlocksFromDwg(DwgName As String, Target As Object)
Set DbxDoc = obj_Acad.GetInterfaceObject("ObjectDBX.AxDbDocument.18")
DbxDoc.Open DwgName
Dim Objects(0 To 0) As Object
'Set Objects(0) = DbxDoc.Blocks(BlkName)
For Each entry In DbxDoc.Blocks
Set Objects(0) = DbxDoc.Blocks(entry.Name)
DbxDoc.CopyObjects Objects, Target.Blocks
Next
End Sub
现在的VB.NET2010的部分代码:
Private Sub GetBlocksFromDwg(ByRef DwgName As String, ByRef Target As Object)
Dim entry As Object
Dim DbxDoc As Object
'On Error GoTo Failed
DbxDoc = obj_Acad.GetInterfaceObject("ObjectDBX.AxDbDocument.18")
DbxDoc.Open(DwgName)
Dim Objects(0) As Object
For Each entry In DbxDoc.Blocks
Objects(0) = DbxDoc.Blocks(entry.Name)
DbxDoc.CopyObjects(Objects, DbxDoc.Blocks, Type.Missing)
Next entry
End Sub
请告知我该怎么处理呢?多谢了。
发错板块了,支持下
页:
[1]