70002880 Remove duplicated entities from a document by using GetCompareHash method

Article 70002880
Type HowTo
Product Engine
Date Added 5/13/2026 12:00:00 AM
Fixed 12.0.03 (5/13/2026 12:00:00 AM)
Submitted by VectorDraw Team

Summary

Remove duplicated entities from a document by using GetCompareHash method

Solution

Remove duplicated entities from a document by using GetCompareHash method


         doc.Open("C:\\mydrawing.vdcl");
         System.Collections.Generic.Dictionary<int, vdArray<vdFigure>> hashtbl = new System.Collections.Generic.Dictionary<int, vdArray<vdFigure>>();
         foreach (vdFigure item in doc.Model.Entities)
         {
             int hash = item.GetCompareHash();
             if(hash == 0) continue;// if the object is not comparable continue
             if (!hashtbl.ContainsKey(hash)) hashtbl.Add(hash, new vdArray<vdFigure>());
             hashtbl[hash].AddItem(item);
         }
         int deletedCount = 0;
         foreach (var item in hashtbl)
         {
             //keep the first remove the others
             for (int i = 1; i <item.Value.Count; i++)
             {
                 item.Value[i].Deleted = true;
                 deletedCount++;
             }
         }
         doc.Prompt("\r\nDeleted " + deletedCount + " duplicate entities"); doc.Prompt(null);
         doc.ZoomExtents();
         doc.Redraw(false);

Send comments on this topic.