Invalid Object Array exception while calling CopyObjects

Invalid Object Array exception while calling CopyObjects

Anonymous
Not applicable
1,245 Views
3 Replies
Message 1 of 4

Invalid Object Array exception while calling CopyObjects

Anonymous
Not applicable

I am getting Invalid Object array error on following line:

 

 

oSourceFile.CopyObjects(objCollection, m_oActiveDoc.Blocks);

 

Code is given below

 

http://pastie.org/8304282

0 Likes
1,246 Views
3 Replies
Replies (3)
Message 2 of 4

Balaji_Ram
Alumni
Alumni

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

0 Likes
Message 3 of 4

Anonymous
Not applicable

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?

0 Likes
Message 4 of 4

Balaji_Ram
Alumni
Alumni

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

0 Likes