.NET

.NET

Reply
New Member
pknerd
Posts: 2
Registered: ‎09-06-2013
Message 1 of 4 (216 Views)

Invalid Object Array exception while calling CopyObjects

216 Views, 3 Replies
09-06-2013 02:01 PM

I am getting Invalid Object array error on following line:

 

 

oSourceFile.CopyObjects(objCollection, m_oActiveDoc.Blocks);

 

Code is given below

 

http://pastie.org/8304282

ADN Support Specialist
Balaji_Ram
Posts: 691
Registered: ‎03-21-2011
Message 2 of 4 (158 Views)

Re: Invalid Object Array exception while calling CopyObjects

09-11-2013 05:26 AM 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

New Member
pknerd
Posts: 2
Registered: ‎09-06-2013
Message 3 of 4 (147 Views)

Re: Invalid Object Array exception while calling CopyObjects

09-11-2013 07:47 AM 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?

ADN Support Specialist
Balaji_Ram
Posts: 691
Registered: ‎03-21-2011
Message 4 of 4 (135 Views)

Re: Invalid Object Array exception while calling CopyObjects

09-11-2013 09:47 PM 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

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.