Author Topic: Automation Error - Catastrophic Error - VBA Excel create new block in ACAD 2015  (Read 2297 times)

0 Members and 1 Guest are viewing this topic.

Yosso

  • Newt
  • Posts: 33
Scenario:

I'm in Excel 2010 (32 bit, Win  7 64 bit).

Trying to create a block using an existing entity (a table)

AutoCAD 2015, running.

Code came from Fixo - http://forums.augi.com/showthread.php?137159-how-to-create-a-own-block-from-vba-programming

Code: [Select]
Dim blkDef As AcadBlock, _
    blkRef As AcadBlockReference, _
    oSset As AcadSelectionSet, _
    tempBlkName As String, _
    objColl(1) As Object, _
    tempObj As Object

tempBlkName = "_archive-Table" & Format(Now(), "hms")

origTblHndl = acadtbl.Handle
Set objColl(0) = adoc.HandleToObject(origTblHndl)
Set blkDef = adoc.Blocks.Add(tablept, tempBlkName)

AcadApp.ActiveDocument.CopyObjects objColl, blkDef

Code gives the Automation Error Catastraphic Error at the last line in the code excerpt above.

Anyone have any ideas (switch to dot.net?)  :-D

Thanks.

Mike
« Last Edit: December 09, 2015, 08:10:44 am by Yosso »

57gmc

  • Newt
  • Posts: 58
I don't see where acadtbl gets set.

Yosso

  • Newt
  • Posts: 33
I don't see where acadtbl gets set.

The acadtbl comes in as an argument for the subroutine.

Code: [Select]
Sub PushRelayTable(AcadApp As AcadApplication, acadDoc As AcadDocument, acadtbl As AcadTable, datasheet As Worksheet, blnRelayCategory As Boolean)

I can see the table being added to the object collection while debugging.



57gmc

  • Newt
  • Posts: 58
What's the status of blkdef? I don't see where that gets set either.

Yosso

  • Newt
  • Posts: 33
What's the status of blkdef? I don't see where that gets set either.

The very first line of the code block is where blkDef is dim'ed and the second line from the bottom is where the blkDef is set.

tablept is also set earlier in the module.  No error with any of the lines except the very last line.

Update (12/10/15)

Relocated the block creating routine back to the previous routine, now there is no error, but the newly created block does not contain the table.

The mystery deepens...



« Last Edit: December 10, 2015, 08:05:40 am by Yosso »

57gmc

  • Newt
  • Posts: 58
The CopyObjects method only has two args, so the problem has to be one of them. You might not get an error, but blkDef could still be null. That's why I asked what is its status. Set a breakpoint on the CopyObjects line and see if blkdef is set or is null. Also, you might not get an error if you have used On Error Resume Next somewhere in your sub.

Yosso

  • Newt
  • Posts: 33
The CopyObjects method only has two args, so the problem has to be one of them. You might not get an error, but blkDef could still be null. That's why I asked what is its status. Set a breakpoint on the CopyObjects line and see if blkdef is set or is null. Also, you might not get an error if you have used On Error Resume Next somewhere in your sub.
You were so right, I didn't reset the error handler in that module.  Sigh.

Added the error handler back into that module (at the appropriate location) and ended up with the same error.

Based on the variable watch, both of the arguments have values. 

Pulling my hair on this one. 

I  even purchased an Autocad VBA book by Lee Ambrosius (AutoCAD Platform Customization) that was more up to date than my other ACAD VBA book. 

Based on his book my code should work.

Cathy

  • Bull Frog
  • Posts: 251
Quote
Note You cannot execute this method while simultaneously iterating through a collection. An iteration will open the work space for a read-only operation, while this method attempts to perform a read-write operation. Complete any iteration before you call this method.


Just a WAG. 

Yosso

  • Newt
  • Posts: 33
Quote
Note You cannot execute this method while simultaneously iterating through a collection. An iteration will open the work space for a read-only operation, while this method attempts to perform a read-write operation. Complete any iteration before you call this method.


Just a WAG.

Appreciate the feedback, but I do not think I'm not iterating through any collections, am I? 

M.


57gmc

  • Newt
  • Posts: 58
Quote
Note You cannot execute this method while simultaneously iterating through a collection. An iteration will open the work space for a read-only operation, while this method attempts to perform a read-write operation. Complete any iteration before you call this method.


Just a WAG.

Appreciate the feedback, but I do not think I'm not iterating through any collections, am I? 

M.


Not at the time you are calling the method.

Perhaps if you uploaded your spreadsheet and a sample dwg with the steps to reproduce the problem, someone could troubleshoot it. There's not much info here.

Yosso

  • Newt
  • Posts: 33
Quote
Note You cannot execute this method while simultaneously iterating through a collection. An iteration will open the work space for a read-only operation, while this method attempts to perform a read-write operation. Complete any iteration before you call this method.


Just a WAG.

Appreciate the feedback, but I do not think I'm not iterating through any collections, am I? 

M.


Not at the time you are calling the method.

Perhaps if you uploaded your spreadsheet and a sample dwg with the steps to reproduce the problem, someone could troubleshoot it. There's not much info here.

Code: [Select]
Dim blkDef As AcadBlock, _
    blkRef As AcadBlockReference, _
    tempBlkName As String, _
    origTblHndl As String, _
    objColl(0) As Object, _
    retObj As Object
   
tempBlkName = "archive-Table" & Format(Now(), "hms")

' Set tempEntity = ListTable
origTblHndl = ListTable.Handle
Set objColl(0) = adoc.HandleToObject(origTblHndl)
Set blkDef = adoc.Blocks.Add(tablept, tempBlkName)

' Copy old table to block
adoc.CopyObjects objColl, blkDef

The open collection was objColl.  Once objColl was dim'ed to objColl(0) everything worked.

Thank you Cathy for the assistance.




« Last Edit: December 22, 2015, 09:01:25 am by Yosso »

Yosso

  • Newt
  • Posts: 33
Problem solved, thanks to Cathy's WAG.

Set the array size to 0 and all was good.

Thanks again.
« Last Edit: January 06, 2016, 07:39:37 am by Yosso »