.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Invalid Object Array exception while calling CopyObjects

3 REPLIES 3
Reply
Message 1 of 4
pknerd
926 Views, 3 Replies

Invalid Object Array exception while calling CopyObjects

I am getting Invalid Object array error on following line:

 

 

oSourceFile.CopyObjects(objCollection, m_oActiveDoc.Blocks);

 

Code is given below

 

http://pastie.org/8304282

Tags (1)
3 REPLIES 3
Message 2 of 4
Balaji_Ram
in reply to: pknerd

Hi,

 

Here is a sample code that worked ok.

 

        If oAcadApp IsNot Nothing Then
            Dim oActiveDoc As AcadDocument
            oActiveDoc = oAcadApp.ActiveDocument

            Dim oSourceDoc As AcadDocument
            oSourceDoc = Nothing

            For Each oDoc As AcadDocument In oAcadApp.Documents
                If ("C:\Temp\Test.dwg").ToUpper() = oDoc.FullName.ToUpper() Then
                    oSourceDoc = oDoc
                    Exit For
                End If
            Next

            If oSourceDoc IsNot Nothing Then

                ' Get the block to copy
                Dim myBlock As AcadBlock
                myBlock = oSourceDoc.Blocks.Item("Test")

                ' Gather the entities in the block to copy
                Dim objects(0 To myBlock.Count - 1) As AcadEntity
                Dim i As Integer
                i = 0
                For Each obj In myBlock
                    objects(i) = obj
                    i = i + 1
                Next obj

                ' Copy the block from the source to the active drawing
                ' Add a new block
                Dim newBlock As AcadBlock
                newBlock = oActiveDoc.Blocks.Add(myBlock.Origin, myBlock.Name)

                ' Copy the objects to the new block
                oSourceDoc.CopyObjects(objects, newBlock)

            End If
        End If

 

Please note that the collection of objects to the "CopyObjects" method is a collection of AcadEntity.

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 3 of 4
pknerd
in reply to: Balaji_Ram

Dim myBlock As AcadBlock

 

 

You already binding it early. This is nto what I am looking for. The objective was to use both parameters of CopyObject as Late Binding.

 

And all this is required to detect INstalled AutoCad copy on Machine because I don't want to compile code for different versions of AutoCAD.

 

How can I make a single piece of code working for all versions of AutoCAD?

Message 4 of 4
Balaji_Ram
in reply to: pknerd

Sorry, I do not find any way to do that.

 

The "CopyObjects" method does not work with an Object array.

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost