TheSwamp

Code Red => .NET => Topic started by: mohnston on January 08, 2007, 08:08:43 PM

Title: eLockViolation of blocktable
Post by: mohnston on January 08, 2007, 08:08:43 PM
Why would I get an error that says eLockViolation on the line "BlockTable bt = (BlockTable)thisDB.BlockTableId.GetObject(OpenMode.ForWrite);"
???
Code: [Select]
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.
Title: Re: eLockViolation of blocktable
Post by: Kerry on January 08, 2007, 08:39:33 PM
What is your
[CommandMethod(..... CommandFlags.XXXX

.. is it set to .Session ??    IE Application context

changing the database in Session mode without locking the database may be the issue


/// kwb
Title: Re: eLockViolation of blocktable
Post by: Kerry on January 08, 2007, 08:40:45 PM


... or is this called from a modeless dialog ? ?

same issue !
Title: Re: eLockViolation of blocktable
Post by: mohnston on January 09, 2007, 10:50:16 AM
You are correct. The code was being launched from a dialog button.

I added the Document.LockDocument() and the error went away.

Thank you!

Sadly, my text does not appear on that drawing.