Author Topic: DGN Purge for 2012  (Read 27275 times)

0 Members and 1 Guest are viewing this topic.

Birdy

  • Guest
DGN Purge for 2012
« on: July 30, 2013, 05:10:06 PM »
Kean has posted this fix for purging DGN linetypes here, but it works for acad 2013 and above.
We are having serious problems with massive amounts of linetypes from DGN drawings, but are on acad 2012.
(see my comment in the link posted)
He suggests you can build the code (found here) to work for 2012, but I have no idea or experience with this.
Can any of you help?
Thanks in advance.

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: DGN Purge for 2012
« Reply #1 on: July 30, 2013, 05:34:06 PM »
AFAIK, you have to have the dev tools to compile the code for the desired ACAD version.
I bet someone here at the swamp can do it  ;)


See also, the comments in this thread: http://through-the-interface.typepad.com/through_the_interface/2012/12/purging-unwanted-dgn-linestyle-data-from-an-autocad-drawing-using-net.html

BlackBox

  • King Gator
  • Posts: 3770
Re: DGN Purge for 2012
« Reply #2 on: July 30, 2013, 05:38:07 PM »
Here's an Autoloader .bundle compiled to .NET 3.5 for 2012 products... Tested here using Civil 3D 2012 just fine... Just download, unblock, unzip to:

Code - C#: [Select]
  1. %AppData%\Autodesk\ApplicationPlugins\
  2.  

... And restart your session. Lemon squeezy.

Cheers
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: DGN Purge for 2012
« Reply #3 on: July 30, 2013, 05:42:14 PM »
Also... For those who'd rather compile themselves, here's the source code (C#)....

Commands.cs

** Note the change from using Autodesk.AutoCAD.ApplicationServices.Core to using Autodesk.AutoCAD.ApplicationServices, and from acdb19.dll to acdb18.dll for the DllImport call.

Code - C#: [Select]
  1. using System;
  2. using System.Runtime.InteropServices;
  3. //using Autodesk.AutoCAD.ApplicationServices.Core;
  4. using Autodesk.AutoCAD.ApplicationServices;
  5. using Autodesk.AutoCAD.DatabaseServices;
  6. using Autodesk.AutoCAD.Runtime;
  7. using System.Collections.ObjectModel;
  8.  
  9. namespace DgnPurger
  10. {
  11.     public class Commands
  12.     {
  13.         const string dgnLsDefName = "DGNLSDEF";
  14.         const string dgnLsDictName = "ACAD_DGNLINESTYLECOMP";
  15.  
  16.         public struct ads_name
  17.         {
  18.             public IntPtr a;
  19.             public IntPtr b;
  20.         };
  21.  
  22.         //[DllImport("acdb19.dll",
  23.         [DllImport("acdb18.dll",
  24.           CharSet = CharSet.Unicode,
  25.           CallingConvention = CallingConvention.Cdecl,
  26.           EntryPoint = "acdbHandEnt")]
  27.         public static extern int acdbHandEnt(string h, ref ads_name n);
  28.  
  29.         [CommandMethod("DGNPURGE")]
  30.         public void PurgeDgnLinetypes()
  31.         {
  32.             var doc =
  33.               Application.DocumentManager.MdiActiveDocument;
  34.             var db = doc.Database;
  35.             var ed = doc.Editor;
  36.  
  37.             using (var tr = doc.TransactionManager.StartTransaction())
  38.             {
  39.                 // Start by getting all the "complex" DGN linetypes
  40.                 // from the linetype table
  41.  
  42.                 var linetypes = CollectComplexLinetypeIds(db, tr);
  43.  
  44.                 // Store a count before we start removing the ones
  45.                 // that are referenced
  46.  
  47.                 var ltcnt = linetypes.Count;
  48.  
  49.                 // Remove any from the "to remove" list that need to be
  50.                 // kept (as they have references from objects other
  51.                 // than anonymous blocks)
  52.  
  53.                 var ltsToKeep =
  54.                   PurgeLinetypesReferencedNotByAnonBlocks(db, tr, linetypes);
  55.  
  56.                 // Now we collect the DGN stroke entries from the NOD
  57.  
  58.                 var strokes = CollectStrokeIds(db, tr);
  59.  
  60.                 // Store a count before we start removing the ones
  61.                 // that are referenced
  62.  
  63.                 var strkcnt = strokes.Count;
  64.  
  65.                 // Open up each of the "keeper" linetypes, and go through
  66.                 // their data, removing any NOD entries from the "to
  67.                 // remove" list that are referenced
  68.  
  69.                 PurgeStrokesReferencedByLinetypes(tr, ltsToKeep, strokes);
  70.  
  71.                 // Erase each of the NOD entries that are safe to remove
  72.  
  73.                 int erasedStrokes = 0;
  74.  
  75.                 foreach (ObjectId id in strokes)
  76.                 {
  77.                     try
  78.                     {
  79.                         var obj = tr.GetObject(id, OpenMode.ForWrite);
  80.                         obj.Erase();
  81.                         if (
  82.                           obj.GetRXClass().Name.Equals("AcDbLSSymbolComponent")
  83.                         )
  84.                         {
  85.                             EraseReferencedAnonBlocks(tr, obj);
  86.                         }
  87.                         erasedStrokes++;
  88.                     }
  89.                     catch (System.Exception ex)
  90.                     {
  91.                         ed.WriteMessage(
  92.                           "\nUnable to erase stroke ({0}): {1}",
  93.                           id.ObjectClass.Name,
  94.                           ex.Message
  95.                         );
  96.                     }
  97.                 }
  98.  
  99.                 // And the same for the complex linetypes
  100.  
  101.                 int erasedLinetypes = 0;
  102.  
  103.                 foreach (ObjectId id in linetypes)
  104.                 {
  105.                     try
  106.                     {
  107.                         var obj = tr.GetObject(id, OpenMode.ForWrite);
  108.                         obj.Erase();
  109.                         erasedLinetypes++;
  110.                     }
  111.                     catch (System.Exception ex)
  112.                     {
  113.                         ed.WriteMessage(
  114.                           "\nUnable to erase linetype ({0}): {1}",
  115.                           id.ObjectClass.Name,
  116.                           ex.Message
  117.                         );
  118.                     }
  119.                 }
  120.  
  121.                 // Remove the DGN stroke dictionary from the NOD if empty
  122.  
  123.                 var nod =
  124.                   (DBDictionary)tr.GetObject(
  125.                     db.NamedObjectsDictionaryId, OpenMode.ForRead
  126.                   );
  127.  
  128.                 ed.WriteMessage(
  129.                   "\nPurged {0} unreferenced complex linetype records" +
  130.                   " (of {1}).",
  131.                   erasedLinetypes, ltcnt
  132.                 );
  133.  
  134.                 ed.WriteMessage(
  135.                   "\nPurged {0} unreferenced strokes (of {1}).",
  136.                   erasedStrokes, strkcnt
  137.                 );
  138.  
  139.                 if (nod.Contains(dgnLsDictName))
  140.                 {
  141.                     var dgnLsDict =
  142.                       (DBDictionary)tr.GetObject(
  143.                         (ObjectId)nod[dgnLsDictName],
  144.                         OpenMode.ForRead
  145.                       );
  146.  
  147.                     if (dgnLsDict.Count == 0)
  148.                     {
  149.                         dgnLsDict.UpgradeOpen();
  150.                         dgnLsDict.Erase();
  151.  
  152.                         ed.WriteMessage(
  153.                           "\nRemoved the empty DGN linetype stroke dictionary."
  154.                         );
  155.                     }
  156.                 }
  157.  
  158.                 tr.Commit();
  159.             }
  160.         }
  161.  
  162.         // Collect the complex DGN linetypes from the linetype table
  163.  
  164.         private static ObjectIdCollection CollectComplexLinetypeIds(
  165.           Database db, Transaction tr
  166.         )
  167.         {
  168.             var ids = new ObjectIdCollection();
  169.  
  170.             var lt =
  171.               (LinetypeTable)tr.GetObject(
  172.                 db.LinetypeTableId, OpenMode.ForRead
  173.               );
  174.             foreach (var ltId in lt)
  175.             {
  176.                 // Complex DGN linetypes have an extension dictionary
  177.                 // with a certain record inside
  178.  
  179.                 var obj = tr.GetObject(ltId, OpenMode.ForRead);
  180.                 if (obj.ExtensionDictionary != ObjectId.Null)
  181.                 {
  182.                     var exd =
  183.                       (DBDictionary)tr.GetObject(
  184.                         obj.ExtensionDictionary, OpenMode.ForRead
  185.                       );
  186.                     if (exd.Contains(dgnLsDefName))
  187.                     {
  188.                         ids.Add(ltId);
  189.                     }
  190.                 }
  191.             }
  192.             return ids;
  193.         }
  194.  
  195.         // Collect the DGN stroke entries from the NOD
  196.  
  197.         private static ObjectIdCollection CollectStrokeIds(
  198.           Database db, Transaction tr
  199.         )
  200.         {
  201.             var ids = new ObjectIdCollection();
  202.  
  203.             var nod =
  204.               (DBDictionary)tr.GetObject(
  205.                 db.NamedObjectsDictionaryId, OpenMode.ForRead
  206.               );
  207.  
  208.             // Strokes are stored in a particular dictionary
  209.  
  210.             if (nod.Contains(dgnLsDictName))
  211.             {
  212.                 var dgnDict =
  213.                   (DBDictionary)tr.GetObject(
  214.                     (ObjectId)nod[dgnLsDictName],
  215.                     OpenMode.ForRead
  216.                   );
  217.  
  218.                 foreach (var item in dgnDict)
  219.                 {
  220.                     ids.Add(item.Value);
  221.                 }
  222.             }
  223.  
  224.             return ids;
  225.         }
  226.  
  227.         // Remove the linetype IDs that have references from objects
  228.         // other than anonymous blocks from the list passed in,
  229.         // returning the ones removed in a separate list
  230.  
  231.         private static ObjectIdCollection
  232.           PurgeLinetypesReferencedNotByAnonBlocks(
  233.             Database db, Transaction tr, ObjectIdCollection ids
  234.           )
  235.         {
  236.             var keepers = new ObjectIdCollection();
  237.  
  238.             // To determine the references from objects in the database,
  239.             // we need to open every object. One reasonably efficient way
  240.             // to do so is to loop through all handles in the possible
  241.             // handle space for this drawing (starting with 1, ending with
  242.             // the value of "HANDSEED") and open each object we can
  243.  
  244.             // Get the last handle in the db
  245.  
  246.             var handseed = db.Handseed;
  247.  
  248.             // Copy the handseed total into an efficient raw datatype
  249.  
  250.             var handseedTotal = handseed.Value;
  251.  
  252.             // Loop from 1 to the last handle (could be a big loop)
  253.  
  254.             var ename = new ads_name();
  255.  
  256.             for (long i = 1; i < handseedTotal; i++)
  257.             {
  258.                 // Get a handle from the counter
  259.  
  260.                 var handle = Convert.ToString(i, 16);
  261.  
  262.                 // Get the entity name using acdbHandEnt()
  263.  
  264.                 var res = acdbHandEnt(handle, ref ename);
  265.  
  266.                 if (res != 5100) // RTNORM
  267.                     continue;
  268.  
  269.                 // Convert the entity name to an ObjectId
  270.  
  271.                 var id = new ObjectId(ename.a);
  272.  
  273.                 // Open the object and check its linetype
  274.  
  275.                 var obj = tr.GetObject(id, OpenMode.ForRead, true);
  276.                 var ent = obj as Entity;
  277.                 if (ent != null && !ent.IsErased)
  278.                 {
  279.                     if (ids.Contains(ent.LinetypeId))
  280.                     {
  281.                         // If the owner does not belong to an anonymous
  282.                         // block, then we take it seriously as a reference
  283.  
  284.                         var owner =
  285.                           (BlockTableRecord)tr.GetObject(
  286.                             ent.OwnerId, OpenMode.ForRead
  287.                           );
  288.                         if (
  289.                           !owner.Name.StartsWith("*") ||
  290.                           owner.Name.ToUpper() == BlockTableRecord.ModelSpace ||
  291.                           owner.Name.ToUpper().StartsWith(
  292.                             BlockTableRecord.PaperSpace
  293.                           )
  294.                         )
  295.                         {
  296.                             // Move the linetype ID from the "to remove" list
  297.                             // to the "to keep" list
  298.  
  299.                             ids.Remove(ent.LinetypeId);
  300.                             keepers.Add(ent.LinetypeId);
  301.                         }
  302.                     }
  303.                 }
  304.             }
  305.             return keepers;
  306.         }
  307.  
  308.         // Remove the stroke objects that have references from
  309.         // complex linetypes (or from other stroke objects, as we
  310.         // recurse) from the list passed in
  311.  
  312.         private static void PurgeStrokesReferencedByLinetypes(
  313.           Transaction tr,
  314.           ObjectIdCollection tokeep,
  315.           ObjectIdCollection nodtoremove
  316.         )
  317.         {
  318.             foreach (ObjectId id in tokeep)
  319.             {
  320.                 PurgeStrokesReferencedByObject(tr, nodtoremove, id);
  321.             }
  322.         }
  323.  
  324.         // Remove the stroke objects that have references from this
  325.         // particular complex linetype or stroke object from the list
  326.         // passed in
  327.  
  328.         private static void PurgeStrokesReferencedByObject(
  329.           Transaction tr, ObjectIdCollection nodIds, ObjectId id
  330.         )
  331.         {
  332.             var obj = tr.GetObject(id, OpenMode.ForRead);
  333.             if (obj.ExtensionDictionary != ObjectId.Null)
  334.             {
  335.                 // Get the extension dictionary
  336.  
  337.                 var exd =
  338.                   (DBDictionary)tr.GetObject(
  339.                     obj.ExtensionDictionary, OpenMode.ForRead
  340.                   );
  341.  
  342.                 // And the "DGN Linestyle Definition" object
  343.  
  344.                 if (exd.Contains(dgnLsDefName))
  345.                 {
  346.                     var lsdef =
  347.                       tr.GetObject(
  348.                         exd.GetAt(dgnLsDefName), OpenMode.ForRead
  349.                       );
  350.  
  351.                     // Use a DWG filer to extract the references
  352.  
  353.                     var refFiler = new ReferenceFiler();
  354.                     lsdef.DwgOut(refFiler);
  355.  
  356.                     // Loop through the references and remove any from the
  357.                     // list passed in
  358.  
  359.                     foreach (ObjectId refid in refFiler.HardPointerIds)
  360.                     {
  361.                         if (nodIds.Contains(refid))
  362.                         {
  363.                             nodIds.Remove(refid);
  364.                         }
  365.  
  366.                         // We need to recurse, as linetype strokes can reference
  367.                         // other linetype strokes
  368.  
  369.                         PurgeStrokesReferencedByObject(tr, nodIds, refid);
  370.                     }
  371.                 }
  372.             }
  373.             else if (
  374.               obj.GetRXClass().Name.Equals("AcDbLSCompoundComponent") ||
  375.               obj.GetRXClass().Name.Equals("AcDbLSPointComponent")
  376.             )
  377.             {
  378.                 // We also need to consider compound components, which
  379.                 // don't use objects in their extension dictionaries to
  380.                 // manage references to strokes...
  381.  
  382.                 // Use a DWG filer to extract the references from the
  383.                 // object itself
  384.  
  385.                 var refFiler = new ReferenceFiler();
  386.                 obj.DwgOut(refFiler);
  387.  
  388.                 // Loop through the references and remove any from the
  389.                 // list passed in
  390.  
  391.                 foreach (ObjectId refid in refFiler.HardPointerIds)
  392.                 {
  393.                     if (nodIds.Contains(refid))
  394.                     {
  395.                         nodIds.Remove(refid);
  396.                     }
  397.  
  398.                     // We need to recurse, as linetype strokes can reference
  399.                     // other linetype strokes
  400.  
  401.                     PurgeStrokesReferencedByObject(tr, nodIds, refid);
  402.                 }
  403.             }
  404.         }
  405.  
  406.         // Erase the anonymous blocks referenced by an object
  407.  
  408.         private static void EraseReferencedAnonBlocks(
  409.           Transaction tr, DBObject obj
  410.         )
  411.         {
  412.             var refFiler = new ReferenceFiler();
  413.             obj.DwgOut(refFiler);
  414.  
  415.             // Loop through the references and erase any
  416.             // anonymous block definitions
  417.             //
  418.             foreach (ObjectId refid in refFiler.HardPointerIds)
  419.             {
  420.                 BlockTableRecord btr =
  421.                   tr.GetObject(refid, OpenMode.ForRead) as BlockTableRecord;
  422.                 if (btr != null && btr.IsAnonymous)
  423.                 {
  424.                     btr.UpgradeOpen();
  425.                     btr.Erase();
  426.                 }
  427.             }
  428.         }
  429.     }
  430. }
  431.  

"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: DGN Purge for 2012
« Reply #4 on: July 30, 2013, 05:42:30 PM »
... And dependent ReferenceFiler.cs

Code - C#: [Select]
  1. using System;
  2. using Autodesk.AutoCAD.DatabaseServices;
  3. using Autodesk.AutoCAD.Geometry;
  4. using Autodesk.AutoCAD.Runtime;
  5.  
  6. namespace DgnPurger
  7. {
  8.     public class ReferenceFiler : DwgFiler
  9.     {
  10.         public ObjectIdCollection HardPointerIds;
  11.         public ObjectIdCollection SoftPointerIds;
  12.         public ObjectIdCollection HardOwnershipIds;
  13.         public ObjectIdCollection SoftOwnershipIds;
  14.  
  15.         public ReferenceFiler()
  16.         {
  17.             HardPointerIds = new ObjectIdCollection();
  18.             SoftPointerIds = new ObjectIdCollection();
  19.             HardOwnershipIds = new ObjectIdCollection();
  20.             SoftOwnershipIds = new ObjectIdCollection();
  21.         }
  22.  
  23.         public override ErrorStatus FilerStatus
  24.         {
  25.             get { return ErrorStatus.OK; }
  26.  
  27.             set { }
  28.         }
  29.  
  30.         public override FilerType FilerType
  31.         {
  32.             get { return FilerType.IdFiler; }
  33.         }
  34.  
  35.         public override long Position
  36.         {
  37.             get { return 0; }
  38.         }
  39.  
  40.         public override IntPtr ReadAddress() { return new IntPtr(); }
  41.         public override byte[] ReadBinaryChunk() { return null; }
  42.         public override bool ReadBoolean() { return true; }
  43.         public override byte ReadByte() { return new byte(); }
  44.         public override void ReadBytes(byte[] value) { }
  45.         public override double ReadDouble() { return 0.0; }
  46.         public override Handle ReadHandle() { return new Handle(); }
  47.         public override ObjectId ReadHardOwnershipId()
  48.         {
  49.             return ObjectId.Null;
  50.         }
  51.         public override ObjectId ReadHardPointerId()
  52.         {
  53.             return ObjectId.Null;
  54.         }
  55.         public override short ReadInt16() { return 0; }
  56.         public override int ReadInt32() { return 0; }
  57.         public override long ReadInt64() { return 0; }
  58.         public override Point2d ReadPoint2d() { return new Point2d(); }
  59.         public override Point3d ReadPoint3d() { return new Point3d(); }
  60.         public override Scale3d ReadScale3d() { return new Scale3d(); }
  61.         public override ObjectId ReadSoftOwnershipId()
  62.         {
  63.             return ObjectId.Null;
  64.         }
  65.         public override ObjectId ReadSoftPointerId()
  66.         {
  67.             return ObjectId.Null;
  68.         }
  69.         public override string ReadString() { return null; }
  70.         public override ushort ReadUInt16() { return 0; }
  71.         public override uint ReadUInt32() { return 0; }
  72.         public override ulong ReadUInt64() { return 0; }
  73.         public override Vector2d ReadVector2d()
  74.         {
  75.             return new Vector2d();
  76.         }
  77.         public override Vector3d ReadVector3d()
  78.         {
  79.             return new Vector3d();
  80.         }
  81.  
  82.         public override void ResetFilerStatus() { }
  83.         public override void Seek(long offset, int method) { }
  84.  
  85.         public override void WriteAddress(IntPtr value) { }
  86.         public override void WriteBinaryChunk(byte[] chunk) { }
  87.         public override void WriteBoolean(bool value) { }
  88.         public override void WriteByte(byte value) { }
  89.         public override void WriteBytes(byte[] value) { }
  90.         public override void WriteDouble(double value) { }
  91.         public override void WriteHandle(Handle handle) { }
  92.         public override void WriteInt16(short value) { }
  93.         public override void WriteInt32(int value) { }
  94.         public override void WriteInt64(long value) { }
  95.         public override void WritePoint2d(Point2d value) { }
  96.         public override void WritePoint3d(Point3d value) { }
  97.         public override void WriteScale3d(Scale3d value) { }
  98.         public override void WriteString(string value) { }
  99.         public override void WriteUInt16(ushort value) { }
  100.         public override void WriteUInt32(uint value) { }
  101.         public override void WriteUInt64(ulong value) { }
  102.         public override void WriteVector2d(Vector2d value) { }
  103.         public override void WriteVector3d(Vector3d value) { }
  104.  
  105.         public override void WriteHardOwnershipId(ObjectId value)
  106.         {
  107.             HardOwnershipIds.Add(value);
  108.         }
  109.  
  110.         public override void WriteHardPointerId(ObjectId value)
  111.         {
  112.             HardPointerIds.Add(value);
  113.         }
  114.  
  115.         public override void WriteSoftOwnershipId(ObjectId value)
  116.         {
  117.             SoftOwnershipIds.Add(value);
  118.         }
  119.  
  120.         public override void WriteSoftPointerId(ObjectId value)
  121.         {
  122.             SoftPointerIds.Add(value);
  123.         }
  124.  
  125.         public void reset()
  126.         {
  127.             HardPointerIds.Clear();
  128.             SoftPointerIds.Clear();
  129.             HardOwnershipIds.Clear();
  130.             SoftOwnershipIds.Clear();
  131.         }
  132.     }
  133. }
  134.  
"How we think determines what we do, and what we do determines what we get."

Birdy

  • Guest
Re: DGN Purge for 2012
« Reply #5 on: July 30, 2013, 06:00:25 PM »
Here's an Autoloader .bundle compiled to .NET 3.5 for 2012 products... Tested here using Civil 3D 2012 just fine... Just download, unblock, unzip to:

Code - C#: [Select]
  1. %AppData%\Autodesk\ApplicationPlugins\
  2.  

... And restart your session. Lemon squeezy.

Cheers
DENIM!!!  :-)
about 10,000 linetypes gone from one problem file!  (ok, I may be exaggerating a little.  But probably over a thousand)
easy peasy. :wink:
Thanks BB.

When it comes to .net:
Quote from: Gandalf
I have no knowledge of this place

BlackBox

  • King Gator
  • Posts: 3770
Re: DGN Purge for 2012
« Reply #6 on: July 30, 2013, 06:14:54 PM »
Here's an Autoloader .bundle compiled to .NET 3.5 for 2012 products... Tested here using Civil 3D 2012 just fine... Just download, unblock, unzip to:

Code - C#: [Select]
  1. %AppData%\Autodesk\ApplicationPlugins\
  2.  

... And restart your session. Lemon squeezy.

Cheers
DENIM!!!  :-)
about 10,000 linetypes gone from one problem file!  (ok, I may be exaggerating a little.  But probably over a thousand)
easy peasy. :wink:
Thanks BB.

When it comes to .net:
Quote from: Gandalf
I have no knowledge of this place

You're welcome; Kean (and others) did the all the work, I just put it together in a saweet looking package.  :mrgreen:
"How we think determines what we do, and what we do determines what we get."

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: DGN Purge for 2012
« Reply #7 on: July 30, 2013, 06:19:54 PM »
I knew someone blackbox would come through quickly!

BlackBox

  • King Gator
  • Posts: 3770
Re: DGN Purge for 2012
« Reply #8 on: July 30, 2013, 06:56:54 PM »
I knew someone blackbox would come through quickly!

That is kind of you to say, R.K. :beer:
"How we think determines what we do, and what we do determines what we get."

jan.gregorica

  • Guest
Re: DGN Purge for 2012
« Reply #9 on: August 02, 2013, 03:27:35 AM »
Hi BlackBox

I downloaded "Autodesk DGN Purge.bundle.zip" file and it works perfectly. I finally managed to remove the thousands of linetypes.

Thank you for your help.

Regards

Jan

BlackBox

  • King Gator
  • Posts: 3770
Re: DGN Purge for 2012
« Reply #10 on: August 02, 2013, 01:54:25 PM »
I downloaded "Autodesk DGN Purge.bundle.zip" file and it works perfectly. I finally managed to remove the thousands of linetypes.

Thank you for your help.

Welcome to TheSwamp, and congrats on your first post!

I didn't do much :oops:, but I'm glad you found this useful nonetheless.

Cheers
"How we think determines what we do, and what we do determines what we get."

Birdy

  • Guest
Re: DGN Purge for 2012
« Reply #11 on: September 20, 2013, 07:44:39 AM »
Ok, so I noticed that autodesk has put out a hotfix for 2012 products HERE.

The difference seems to be they added code to prevent files from becoming re-corrupted whey copying objects from a 'bad' file, which is really nice.

problem is, I need to netload it every time I start a new session of autocad. Is there a way to fix this so I only need to load it once?  Seems like a logical thing for them to do for a 'hotfix'.
Any help is appreciated.

BlackBox

  • King Gator
  • Posts: 3770
Re: DGN Purge for 2012
« Reply #12 on: September 20, 2013, 08:06:34 AM »
Is there a way to fix this so I only need to load it once?  Seems like a logical thing for them to do for a 'hotfix'.

Particularly so, considering any product 2012 or newer... Just use Autoloader.

You can modify the .bundle I attached to my earlier post here... Just place the assembly in the appropriate folder, and modify PackageContents.xml accordingly. Lemon squeezy.
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: DGN Purge for 2012
« Reply #13 on: September 20, 2013, 08:35:33 AM »
Alright, I downloaded the HotFix, see that they've added COM (which now requires different assemblies for each 32-Bit, and 64-Bit, etc.), so I've updated the .bundle and attached it to the bottom of this post.

... Seems to work just fine here in some limited testing.



I also attempted to add the ReadMe PDF as the HelpFile, given that the Autoloader White Paper says both HTML, and PDF are supported, but I keep getting a 404 error... Not sure what that's about... In any event, the ReadMe is located in ./Contents/Resources/ should anyone want to read through it, along with a shortcut to the HotFix page online.

Cheers
"How we think determines what we do, and what we do determines what we get."

Birdy

  • Guest
Re: DGN Purge for 2012
« Reply #14 on: September 20, 2013, 10:16:54 AM »
Thanks BB, that helps.  Works here as well so far.

Cheers!


BlackBox

  • King Gator
  • Posts: 3770
Re: DGN Purge for 2012
« Reply #15 on: September 20, 2013, 11:15:08 AM »
Thanks BB, that helps.  Works here as well so far.

Cheers!

You're welcome, Jim; I'm happy to help.

Cheers
"How we think determines what we do, and what we do determines what we get."

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: DGN Purge for 2012
« Reply #16 on: September 30, 2013, 11:02:48 AM »
.....I need to netload it every time I start a new session of autocad. Is there a way to fix this so I only need to load it once?

I'm still old school, so....

Code: [Select]
;;;
;;; LOAD DGN PURGE COMMAND
(if (setq dgnp (findfile "DgnLsPurge.dll"))
  (command "._NETLOAD" dgnp)
)

 :kewl:

max

  • Guest
Re: DGN Purge for 2012
« Reply #17 on: February 27, 2015, 05:38:10 AM »
Hi there,
I get a null object ID sometimes in the PurgeLinetypesReferencedNotByAnonBlock Method. The following if clause can fix this:
[...]
// If the owner does not belong to an anonymous
// block, then we take it seriously as a reference
//
// Chek the OwnerId first!
if (ent.OwnerId != ObjectId.Null)
{
var owner = (BlockTableRecord)tr.GetObject(ent.OwnerId, OpenMode.ForRead);
[...]