Author Topic: eLockViolation of blocktable  (Read 7453 times)

0 Members and 1 Guest are viewing this topic.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
eLockViolation of blocktable
« 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.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: eLockViolation of blocktable
« Reply #1 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
« Last Edit: January 08, 2007, 08:41:52 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: eLockViolation of blocktable
« Reply #2 on: January 08, 2007, 08:40:45 PM »


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

same issue !
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: eLockViolation of blocktable
« Reply #3 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.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions