Author Topic: Hatches being moved to back and transaction Abort causes AutoCAD crash  (Read 2429 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
I am working on something to explode blocks to a certain depth.  Once I have done that, I go to move all hatches in model space to the back through the DrawOrderTable object associated with the BlockTableRecord.  In a certain drawing it always cause the error "Error handler re-entered. Exiting now." where the message box is titled "AutoCAD Error-abort".  This leads me to assume the error is within AutoCAD's core, as I cannot trap the error with a Try/Catch block.  If I erase all the hatch entities, then the error goes away.  If I use Commit on the transaction, there is no issue.  But if I use Abort, which I have to to get all the items back to their original state, then the error happens every time.

I cannot post the code or drawing, but was wondering if I am thinking wrong? or if I should pass this one on to AutoDesk? or is there any way I can get the drawing back to it's original state before I started my command?

Thanks in advance.

Edit:  I should point out that the program works fine in all other drawings tested, just this one has issues with the hatch patterns.  Even if I Audit the file first.
« Last Edit: January 12, 2015, 12:49:42 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
I have another drawing that exhibits this characteristic.  I have narrowed down the problem to a selection of 3 hatches and some circles.   The code posted will crash Autocad every time in this drawing.  If I changed the call from 'dot.MoveToBottom()' to 'dot.MoveToTop()' then everything works as it should.

Passing true or false to aRemoveAssoc does not matter.

Any help is appreciated.

Thanks in advance,
Tim

Code - C: [Select]
  1. [ CommandMethod( "BackCrash" ) ]
  2. public void HatchBackCrash() {
  3.     Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  4.     Database db = doc.Database;
  5.     BlockTable bt;
  6.     using ( Transaction trans = db.TransactionManager.StartTransaction() ) {
  7.         bt = trans.GetObject( db.BlockTableId, OpenMode.ForRead, false, true ) as BlockTable;
  8.         moveHatchBack( trans, bt[ "*MODEL_SPACE" ], true );
  9.         trans.Abort();
  10.     }
  11. }
  12.  
  13. public static void moveHatchBack ( Transaction aTrans, ObjectId aBtrId, bool aRemoveAssoc ) {
  14.         DBObject obj;
  15.         DrawOrderTable dot;
  16.         BlockTableRecord btr;
  17.         Hatch hat;
  18.         ObjectIdCollection hatIds = new ObjectIdCollection();
  19.         btr = aTrans.GetObject( aBtrId, OpenMode.ForRead, false, false ) as BlockTableRecord;
  20.         foreach ( ObjectId oid in btr ) {
  21.             if ( oid.IsErased || oid.IsNull || oid.IsEffectivelyErased || !oid.IsValid ) continue;
  22.                 obj = aTrans.GetObject( oid, OpenMode.ForRead, false, false ) as Hatch;
  23.                 if ( obj == null ) continue;
  24.                 hatIds.Add( oid );
  25.                 hat = obj as Hatch;
  26.                 if ( aRemoveAssoc && hat.Associative ) {
  27.                     hat.UpgradeOpen();
  28.                     hat.Associative = false;
  29.                     hat.DowngradeOpen();
  30.                 }
  31.         }
  32.         if ( hatIds.Count > 0 ) {
  33.                 dot = aTrans.GetObject( btr.DrawOrderTableId, OpenMode.ForWrite, false, false ) as DrawOrderTable;
  34.                  dot.MoveToBottom( hatIds );
  35. //              dot.MoveToTop( hatIds );
  36.                 dot.DowngradeOpen();
  37.         }
  38.         hatIds.Dispose();
  39. }
  40.  
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Tim, what happens if you let the transaction fall through the using clause and go out of scope instead of aborting?
Revit 2019, AMEP 2019 64bit Win 10

T.Willey

  • Needs a day job
  • Posts: 5251
It stills crashes Autocad.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.