TheSwamp

Code Red => .NET => Topic started by: T.Willey on January 12, 2015, 11:57:12 AM

Title: Hatches being moved to back and transaction Abort causes AutoCAD crash
Post by: T.Willey on January 12, 2015, 11:57:12 AM
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.
Title: Re: Hatches being moved to back and transaction Abort causes AutoCAD crash
Post by: T.Willey on May 10, 2015, 10:31:17 PM
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.  
Title: Re: Hatches being moved to back and transaction Abort causes AutoCAD crash
Post by: MexicanCustard on May 11, 2015, 08:00:45 AM
Tim, what happens if you let the transaction fall through the using clause and go out of scope instead of aborting?
Title: Re: Hatches being moved to back and transaction Abort causes AutoCAD crash
Post by: T.Willey on May 11, 2015, 08:59:06 AM
It stills crashes Autocad.