Author Topic: Busted the dwg  (Read 2263 times)

0 Members and 1 Guest are viewing this topic.

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Busted the dwg
« on: July 18, 2016, 03:24:38 PM »
Somehow I've busted this dwg file; probably with my .NET code and I'd like to figure out why/how. It recovers, but a bunch of entities get erased.

My postmortem skills are lacking though. Can someone either look at for me, or tell me the best way to figure out what I done gone dropped?

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Busted the dwg
« Reply #1 on: July 18, 2016, 07:31:46 PM »
EWW Groups,  sorry can not help

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Busted the dwg
« Reply #2 on: July 18, 2016, 08:38:18 PM »
Thanks for taking a look Bryco.

Are you eww-ing at the groups because they're gross? I'm guessing you don't suspect they're the problem.

It looks like the drawing is throwing two types of errors, Error 34 (eWrongObjectType) and Error 53 (eFilerError). I'm beginning to suspect my implementation for xdata is the problem, based on this discussion between Yuan and Tony a decade ago. A decade! :wideeyed: This is why people should post solutions even if they solved it themselves.

Here's my xData code, though I can't see any issues with it. I am calling addNewlyCreatedDBObject after adding to the registeredAppTable. Unfortunately I can't duplicate the problem, this code seems to work 98.782% of the time..

Code - C#: [Select]
  1. /// <summary>
  2. /// Writes given Xdata to the obj given, keeping existing xData. If the given registered app exists,
  3. /// the existing xData for that registered app is replaced with the new xData
  4. /// </summary>
  5. /// <param name="objID">The id of the DBObject to write the xdata to.</param>
  6. /// <param name="newXData">The xdata, can only contain xdata for a single registered app</param>
  7. public static bool WriteXData(ObjectId objID, ResultBuffer newXData)
  8. {
  9.         if (newXData.AsArray().Length < 1) return false;
  10.         if (objID.IsNull) return false;
  11.         TypedValue v = newXData.AsArray()[0];
  12.         if (v.TypeCode!=CODE_APPNAME) return false;
  13.        
  14.         string appName=v.Value.ToString();
  15.         AddRegAppTableRecord(appName);
  16.         ResultBuffer updatedXdata = new ResultBuffer();
  17.         using (LockedTransaction tr = Active.Document.TransactionManager.StartLockedTransaction())
  18.         {
  19.                 // remove any xdata for the given appname
  20.                 DBObject obj = tr.GetObject(objID, OpenMode.ForWrite);
  21.                 ResultBuffer existingData = obj.XData;
  22.                 if (existingData!=null)
  23.                 {
  24.                         bool included = true;
  25.                         // Get all values NOT with our Registered App
  26.                         foreach (TypedValue tv in existingData)
  27.                         {
  28.                                 if (tv.TypeCode == CODE_APPNAME)
  29.                                 {
  30.                                         if (appName.Equals(tv.Value.ToString()))
  31.                                         {
  32.                                                 included = false;
  33.                                         }
  34.                                         else
  35.                                         {
  36.                                                 included = true;
  37.                                         }
  38.                                 }
  39.                                 if (included)
  40.                                 {
  41.                                         updatedXdata.Add(tv);
  42.                                 }
  43.                         }
  44.  
  45.                 }
  46.                 foreach (TypedValue tv in newXData)
  47.                 {
  48.                         updatedXdata.Add(tv);
  49.                 }
  50.                 RegisterApps(updatedXdata);
  51.                 obj.XData = updatedXdata;
  52.                 tr.Commit();
  53.         }
  54.         return true;
  55. }
  56.  
  57.  
  58. /// <summary>
  59. /// Registers all appnames in the given xdata.
  60. /// </summary>
  61. /// <param name="xData">The XData.</param>
  62. public static void RegisterApps(ResultBuffer xData)
  63. {
  64.         foreach (TypedValue val in xData)
  65.         {
  66.                 if (val.TypeCode==CODE_APPNAME)
  67.                 {
  68.                         AddRegAppTableRecord(val.Value.ToString());
  69.                 }
  70.         }
  71. }
  72.  
  73. /// <summary>
  74. /// Adds the given appname to the RegisteredAppTable if it's not there
  75. /// </summary>
  76. /// <param name="regAppName">appname to register</param>
  77. private static void AddRegAppTableRecord(string regAppName)
  78. {
  79.         using (LockedTransaction tr = Active.Document.TransactionManager.StartLockedTransaction())
  80.         {
  81.                 RegAppTable rat = (RegAppTable)tr.GetObject(Active.Database.RegAppTableId, OpenMode.ForRead, false);
  82.                 if (!rat.Has(regAppName))
  83.                 {
  84.                         // add the registered app
  85.                         rat.UpgradeOpen();
  86.                         RegAppTableRecord ratr = new RegAppTableRecord();
  87.                         ratr.Name = regAppName;
  88.                         tr.AddNewlyCreatedDBObject(ratr, true);
  89.                         rat.Add(ratr);
  90.                 }
  91.                 tr.Commit();
  92.         }
  93. }
  94.  

If anything jumps out at you experts out there, please let me know.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Busted the dwg
« Reply #3 on: July 19, 2016, 05:06:26 AM »
In BricsCAD the file can be opened without resorting to the _RECOVER command.
_AUDIT reports 36 errors:
Code: [Select]
: AUDIT
Fix any errors detected? Yes/<No>: y

Name: AcDbMLeader(3C7A)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(3C7D)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(3C81)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(547B)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(5488)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(5495)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(54A2)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(54AF)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(54BC)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(54C9)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(54D6)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(54E3)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(54F0)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(54FD)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(550A)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(5517)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(5524)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(5531)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(553E)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(554B)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(5558)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(5565)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(5596)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(55A3)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(55B0)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(55BD)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(55CA)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(55D7)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(55E4)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(55F1)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(55FE)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(560B)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(5618)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(5625)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(5632)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

Name: AcDbMLeader(563F)
Value: LineType Id (0)
Validation: Invalid
Replaced by: Set to default LineType "ByLayer"

2207 objects audited
Total errors found during audit 36, fixed 36

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Busted the dwg
« Reply #4 on: July 19, 2016, 07:15:49 AM »
Is it the nested LockTransactions?  Have you tried it with a single Transaction?  Better yet have you tried it with a normal StartTransaction?
Revit 2019, AMEP 2019 64bit Win 10

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Busted the dwg
« Reply #5 on: July 19, 2016, 02:10:42 PM »
Is it the nested LockTransactions?  Have you tried it with a single Transaction?  Better yet have you tried it with a normal StartTransaction?

Unfortunately, I can't recreate the problem, so I can't test these.

Are nested transactions a problem? I thought I researched that before I started putting this together. I've seen other's code that passes transactions , but haven't implemented my code that way.