TheSwamp

Code Red => VB(A) => Topic started by: RICVBA on November 23, 2019, 09:25:51 AM

Title: SetBlockTableRecordId issue
Post by: RICVBA on November 23, 2019, 09:25:51 AM
I submit a post I already posted in https://forums.autodesk.com/t5/visual-basic-customization/setblocktablerecordid-issue/td-p/9157637 (https://forums.autodesk.com/t5/visual-basic-customization/setblocktablerecordid-issue/td-p/9157637) without, up to now, any solution


I'm coding from within Excel for Office 365 32Bit VBA Application Edition 7.1 and using in a W10 laptop

I'm referencing AutoCAD 2018 Type Library and trying to use the SetBlockTableRecordId  method to insert a block into a Table cell with the following codeline:
 
Code: [Select]
myTable.SetBlockTableRecordId j + 1, 0, myDoc.Blocks("blockName").ObjectID, True
However I'm getting a compiling error with "Compiler error: not corresponding type" as the (hoepfully) closest translation

The very same statement doesn't error out if I code in AutoCAD 2018 VBA 7.1 environment

I know (or, at least, I think) this has to do with the 32/64 bit thing, and blindly tried both
Code: [Select]
myTable.SetBlockTableRecordId j + 1, 0, myDoc.Blocks("blockName").ObjectID32 , True
Code: [Select]
myTable.SetBlockTableRecordId j + 1, 0, CLngPtr(myDoc.Blocks("blockName").ObjectID)but to no avail

It may be of interest that:
- without "CLngPtr", the compile error would highlight the ".ObjectID" part of the statement
- with the "CLngPtr"  the compile error would highlight ".CLngPtr" part

I'm thinking that my Excel 32 bit would never handle a call to a method (SetBlockTableRecordId) that is requiring some 64 bit argument

 

Is anybody aware of a solution?

 

thank you
Title: Re: SetBlockTableRecordId issue
Post by: Lee Mac on November 23, 2019, 10:21:57 AM
Have you tried using the SetBlockTableRecordId32 method in conjunction with the ObjectID32 property?
Title: Re: SetBlockTableRecordId issue
Post by: RICVBA on November 28, 2019, 12:57:00 PM
Thank you Lee for your time

"SetBlockTableRecordId32" method wasn't listed by intellisense

anyway I tried it and, as a confirmation of it, I got the run-time error '438' property or method not suppported by the object

Title: Re: SetBlockTableRecordId issue
Post by: roy_043 on November 30, 2019, 01:04:13 PM
Maybe checking what GetBlockTableRecordId returns will shed some light?
Title: Re: SetBlockTableRecordId issue
Post by: RICVBA on December 01, 2019, 09:24:33 AM
Hy Roy

If you mean I have to deal with a LongPtr value, then I already tried the CLngPtr() conversion, but with no success.

Or did you mean something else?

Thank you
Title: Re: SetBlockTableRecordId issue
Post by: n.yuan on December 05, 2019, 10:23:25 AM
Just a bit extra info, which may not be much of help:

You say

<QUOTE>
- with the "CLngPtr"  the compile error would highlight ".CLngPtr" part
</QUOTE>

I am bit confused: CLngPtr() is a global function, not a function of an Object. So, why the ".", which would obviously cause compiling error for sure. If the "." is simply typing error in your post, then are you saying the code like this:

myTable.SetBlockTableRecordId j + 1, 0, CLngPtr(myDoc.Blocks("blockName").ObjectID)

still gives compiling error by highlight ClngPtr()?

Here is what I get with my stand-alone Excel 2016 from MS Office 2016 suite (also VBA7.1 32 bit)

I wrote a few line of code to set up an AcadTable with one line calling

myTable.SetBlockTableRecordId(..., [BlockId],..)

Regardless [BlockId] is wrapped with ClngPtr or not, as soon as I compile the code (menu=>Debug->Compile...), VBA IDE freezes, I have to kill AutoCAD.
If I comment out that line of code, compiling/running is OK.

You see the difference here: you could at least compile with your Excel in Office 365, even it does not pass; On my side, compiling itself would crash AutoCAD VBA when that particular line of code exists.

So, I'd likely give up the idea of running Excel VBA code to automate AutoCAD because of this, if I were you.



Title: Re: SetBlockTableRecordId issue
Post by: roy_043 on December 06, 2019, 02:49:37 AM
Or did you mean something else?
Sorry for the delayed response. Have you tried using the return from GetBlockTableRecordId in SetBlockTableRecordId?