Error message when inserting blocks thru VBA routine

Error message when inserting blocks thru VBA routine

Anonymous
Not applicable
1,693 Views
7 Replies
Message 1 of 8

Error message when inserting blocks thru VBA routine

Anonymous
Not applicable

Using AutoCAD 2018 when inserting blocks thru a VBA routine I am getting the following error message at random times and it causes AutoCAD to shut down. 

 

Internal Error: !dbinsert.cpp@1349: eLockViolation

 

Can you help?

 

Felipe

1,694 Views
7 Replies
Replies (7)
Message 2 of 8

norman.yuan
Mentor
Mentor

There were a few discussions on this topic:

https://forums.autodesk.com/t5/visual-basic-customization/internal-error-dbinsert-cpp-1309elockviola...

https://forums.autodesk.com/t5/visual-basic-customization/acad-2015-vba-elockviolation-error/m-p/504...

 

However, if those discussions do not help, you may want to post your all relevant code and describe in detail how the code is executed that results this error (maybe, also the drawing and the block used to run your code).

 

Also, have you tried to simplify the code (so that only very necessary lines that leads to the error are included) and then try with different drawing, different block to reproduce it?

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 8

Anonymous
Not applicable

I would post the code but the problem is that I don't get the error every time.  I can execute the same section of code several times without a problem and then, for some reason, I get the error message and it shuts down.  Therefore, I don;t think that the code is the problem.  Would you agree?

0 Likes
Message 4 of 8

Anonymous
Not applicable

use the following code to insert block

 

dim filePath as String

dim insertionPoint as double

dim scale as integer

 

filePath = "the path of the block"

 Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(insertionPoint, filePath, scale(0), scale(1), scale(2), 0)

0 Likes
Message 5 of 8

Anonymous
Not applicable
I appreciate your reply but sometimes the code works fine and sometimes it
crashes when executing the same line of code. To me this means that there
is not a problem with the code because, if there was, it wouldn't execute at
all. Do you agree with me on this?
0 Likes
Message 6 of 8

Anonymous
Not applicable

Yes, I agree with you.

 

Even i was facing the similar problem but i solved the problem by saving the drawing file before executing the insert block code.

 

I used 

ThisDrawing.Save 

before the insert block code

 

filePath = "the path of the block"

 Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(insertionPoint, filePath, scale(0), scale(1), scale(2), 0)

Sometimes the inserting a block will give an error if the drawing file is not saved.

Please try it out

 

Please Checkout this page as well

https://forums.autodesk.com/t5/net/elockviolation-error-code-creating-a-new-layer-and-make-it-work/t...

0 Likes
Message 7 of 8

Anonymous
Not applicable
I'll give it a try sometime. And thanks for letting me know that my logic
about the code being correct at least made sense.
0 Likes
Message 8 of 8

Anonymous
Not applicable

Got the same issue here from AutoCAD 2019 onwards and only a few people with me have this error where on my side it does not occur.

 

Even trying to catch the error with the error trapping off does not work. I narrowed it down to the InsertBlock command and simplified the code, didn't work for me, same error.

 

i'm using the line in my VBA to import survey points from the Clipboard and then insert them in the drawing.

 

Unfortunately I cannot use the Drawing.Save method as the insertion might be invalid, save would overwrite the original drawing state. Could open the drawing, save it under a new, temp name, import the points and if OK, store the drawing back under its original name.....

 

One work round method does work: using the InsertBlock in a brand new. clean drawing works all the time fine without the error occurring, once I've used the import, the next time AutoCAD crashes at the next import run.

 

So: import the 1st time in a drawing goes well, open a new, clean drawing, import the points there, select them all, Clipboard => Copy, back to the 1st drawing, Clipboard => Paste to original coordinates and sorted.

 

I agree with the author here that it is not a programming error.

 

Hope someone at AutoDESK might have a direct solution to avoid the crash.

 

0 Likes