Author Topic: SetBlockTableRecordId issue  (Read 12584 times)

0 Members and 1 Guest are viewing this topic.

RICVBA

  • Newt
  • Posts: 62
SetBlockTableRecordId issue
« 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 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

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: SetBlockTableRecordId issue
« Reply #1 on: November 23, 2019, 10:21:57 AM »
Have you tried using the SetBlockTableRecordId32 method in conjunction with the ObjectID32 property?

RICVBA

  • Newt
  • Posts: 62
Re: SetBlockTableRecordId issue
« Reply #2 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


roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: SetBlockTableRecordId issue
« Reply #3 on: November 30, 2019, 01:04:13 PM »
Maybe checking what GetBlockTableRecordId returns will shed some light?

RICVBA

  • Newt
  • Posts: 62
Re: SetBlockTableRecordId issue
« Reply #4 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

n.yuan

  • Bull Frog
  • Posts: 348
Re: SetBlockTableRecordId issue
« Reply #5 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.




roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: SetBlockTableRecordId issue
« Reply #6 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?

RICVBA

  • Newt
  • Posts: 62
Re: SetBlockTableRecordId issue
« Reply #7 on: December 09, 2019, 10:10:43 AM »
@roy_043
GetBlockTableRecordId "Returns the block table record ID of the cell"

So I have to first put a blockreference in the wanted cell in order to use it

But that is precisely my aim, so I guess I'm at a dead end

In any case I also tried to first manually put a blockreference in a cell and then use both GetBlockTableRecordI and GetBlockTableRecordI2 methods to retrieve the block Id in that cell, but in both cases Excel crashed silently...

RICVBA

  • Newt
  • Posts: 62
Re: SetBlockTableRecordId issue
« Reply #8 on: December 09, 2019, 10:27:28 AM »
thanks Norman for your time and insights

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()?


it was a typo of mine: no dots before "CLngPtr("



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

Of course it'd be possible but the AutocCAD part is a very small one in between many, and heavy, Excel ones. So I'd rather go for a workaround or even give up on table cell block insertion. Or wait for a 64 bit Excel...


roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: SetBlockTableRecordId issue
« Reply #9 on: December 11, 2019, 12:49:49 PM »
So I have to first put a blockreference in the wanted cell in order to use it
Can't you do this 'manually'?

RICVBA

  • Newt
  • Posts: 62
Re: SetBlockTableRecordId issue
« Reply #10 on: December 13, 2019, 10:21:14 AM »
So I have to first put a blockreference in the wanted cell in order to use it
Can't you do this 'manually'?

Yes I can. And I did, as per last lines of my very same post, which I hereby recall:

"In any case I also tried to first manually put a blockreference in a cell and then use both GetBlockTableRecordI and GetBlockTableRecordI2 methods to retrieve the block Id in that cell, but in both cases Excel crashed silently…"

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: SetBlockTableRecordId issue
« Reply #11 on: December 13, 2019, 12:33:12 PM »
Ah yes, sorry, I must have skipped that part. Your conclusion would then seem correct.