1

我有以下代码,我正在 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
4

0 回答 0