VB copyoBjects后期绑定

时间:2013-09-01 06:18:54

标签: vb.net vb.net-2010 autocad late-binding

我在VB中尝试以下代码。当我尝试复制对象时,NET给出了无效的对象数组。我在哪里做错了?

Option Strict Off

'Imports Autodesk
Imports System.Windows.Forms
Imports System.Data
'Imports Autodesk.AutoCAD
'Imports Autodesk.AutoCAD.Interop.Common
'Imports Autodesk.AutoCAD.Interop

Public Class Form1

    Private acadApp As Object 'AcadApplication
    Private m_oActiveDoc As Object 'AcadDocument

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim oSourceFile As Object = Nothing 'AcadDocument

        Try
            acadApp = GetObject(, "AutoCAD.Application.16")
            m_oActiveDoc = acadApp.ActiveDocument

            Dim oTempDoc As Object 'Autodesk.AutoCAD.Interop.AcadDocument
            For Each oTempDoc In acadApp.Documents

                If UCase("c:\d1.dwg") = UCase(oTempDoc.Path & "\" & oTempDoc.Name) Then
                    oSourceFile = oTempDoc
                    Exit For
                End If
            Next

            If oSourceFile IsNot Nothing Then

                Dim objCollection(0) As Object 'AcadBlock ' Object!!!!!!!!!!!

                objCollection(0) = Nothing

                Try
                    objCollection(0) = oSourceFile.Blocks.Item("b1")

                Catch ex As Exception
                    MsgBox(ex.Message)

                End Try

                If objCollection(0) IsNot Nothing Then

                    oSourceFile.CopyObjects(objCollection, m_oActiveDoc.Blocks) 'Invalid object array exception when objCollection is declared as Object.
                End If
            End If


        Catch ex As Exception
            MsgBox(ex.Message)

        End Try
    End Sub


End Class

0 个答案:

没有答案