.NET

Reply
Distinguished Contributor
mohnston
Posts: 184
Registered: ‎09-22-2006
Message 1 of 3 (142 Views)

eLockViolation of blocktable

142 Views, 2 Replies
01-08-2007 05:03 PM
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.
CAD Programming Solutions
*Bobby C. Jones
Message 2 of 3 (142 Views)

Re: eLockViolation of blocktable

01-09-2007 05:02 AM in reply to: mohnston
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.
Distinguished Contributor
mohnston
Posts: 184
Registered: ‎09-22-2006
Message 3 of 3 (142 Views)

Re: eLockViolation of blocktable

01-09-2007 07:47 AM in reply to: mohnston
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.
CAD Programming Solutions
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.