Can not open BlockTableRecord as OpenMode.ForWrite

Can not open BlockTableRecord as OpenMode.ForWrite

nghiabt04
Advocate Advocate
484 Views
3 Replies
Message 1 of 4

Can not open BlockTableRecord as OpenMode.ForWrite

nghiabt04
Advocate
Advocate

Hi,

Currently, I write a program open WPF UserControl as ToolPalette. When I tried to GetObject BlockTableRecord as OpenMode.ForWrite by a button but AutoCAD always turns to be FATAL ERROR shutdown anyway. 

When I test this code again in command mode, the code works fine. Anyone have an idea about this situation, please help me.

Thanks a lot!

0 Likes
Accepted solutions (2)
485 Views
3 Replies
Replies (3)
Message 2 of 4

SENL1362
Advisor
Advisor
Accepted solution

did you lock the document?

try

{

using (var docLck = doc.LockDocument())
{

var db=doc.Database;

using (var tr=db.TransactionManager.StartTransaction())

{

var blk = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForWrite);

...

0 Likes
Message 3 of 4

_gile
Consultant
Consultant
Accepted solution

Hi,

From Kean Walmsley's blog:

"there’s our important rule of thumb when it comes to implementing a modeless UI: rather than manually locking the current document, it’s safer to define a command – which will implicitly lock the current document – and call that from the UI via SendStringToExecute()."



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 4

nghiabt04
Advocate
Advocate

Yes, I forgot to lock the document, thanks for your help

0 Likes