.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

eLockViolation of blocktable

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
292 Views, 2 Replies

eLockViolation of blocktable

Why would I get an error that says eLockViolation on the line "BlockTable bt = (BlockTable)thisDB.BlockTableId.GetObject(OpenMode.ForWrite);"
???
----------------------
private void StampDrawing(string fullDwgPath, string stampString, bool FullSize)
{
Document ThisDrawing = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(fullDwgPath);
Database thisDB = ThisDrawing.Database;
Autodesk.AutoCAD.ApplicationServices.TransactionManager tm = ThisDrawing.TransactionManager;
using (Transaction trans = tm.StartTransaction())
{
BlockTable bt = (BlockTable)thisDB.BlockTableId.GetObject(OpenMode.ForWrite);
BlockTableRecord modelsp = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
DBText stampText = new DBText();
stampText.TextString = stampString;
stampText.Height = 12;
stampText.HorizontalMode = TextHorizontalMode.TextRight;
stampText.Rotation = 0;
modelsp.AppendEntity(stampText);
trans.TransactionManager.AddNewlyCreatedDBObject(stampText, true);
trans.Commit();
}
tm.Dispose();
ThisDrawing.CloseAndSave(fullDwgPath);
thisDB.Dispose();
}
----------------------

The file opens fine but I am unable to get the blocktable.
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

Hey Mark,
Are you calling this code from the Application context, like from a palette?
If so, then you'll need to lock the document first.
--
Bobby C. Jones

wrote in message news:5444860@discussion.autodesk.com...
Why would I get an error that says eLockViolation on the line "BlockTable bt
= (BlockTable)thisDB.BlockTableId.GetObject(OpenMode.ForWrite);"
???
----------------------
private void StampDrawing(string fullDwgPath, string stampString, bool
FullSize)
{
Document ThisDrawing =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(fullDwgPath);
Database thisDB = ThisDrawing.Database;
Autodesk.AutoCAD.ApplicationServices.TransactionManager tm =
ThisDrawing.TransactionManager;
using (Transaction trans = tm.StartTransaction())
{
BlockTable bt =
(BlockTable)thisDB.BlockTableId.GetObject(OpenMode.ForWrite);
BlockTableRecord modelsp =
(BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],
OpenMode.ForWrite);
DBText stampText = new DBText();
stampText.TextString = stampString;
stampText.Height = 12;
stampText.HorizontalMode = TextHorizontalMode.TextRight;
stampText.Rotation = 0;
modelsp.AppendEntity(stampText);
trans.TransactionManager.AddNewlyCreatedDBObject(stampText,
true);
trans.Commit();
}
tm.Dispose();
ThisDrawing.CloseAndSave(fullDwgPath);
thisDB.Dispose();
}
----------------------

The file opens fine but I am unable to get the blocktable.
Message 3 of 3
Anonymous
in reply to: Anonymous

I'm calling it from a dialog button event.

I added:
ThisDrawing.LockDocument();
right after I open the Document.

The eLockViolation error went away but when I open the drawing the text is not added.

Maybe I should start another thread for that problem.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost