예제 #1
0
        public void RemoveProxy()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            ObjectId id = EntProxy.ObjectId;

            using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

                foreach (ObjectId btrId in bt)
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);

                    foreach (ObjectId entId in btr)
                    {
                        if (entId.ObjectClass.Name == "AcDbZombieEntity" && entId == id)
                        {
                            ProxyEntity ent = (ProxyEntity)tr.GetObject(entId, OpenMode.ForRead);

                            ent.UpgradeOpen();

                            using (DBObject newEnt = new Line())
                            {
                                ent.HandOverTo(newEnt, false, false);
                                newEnt.Erase();
                            }
                        }
                    }
                }

                tr.Commit();
            }
        }
예제 #2
0
        public static void RemoveProxiesFromBlocks()
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr =
                       db.TransactionManager.StartOpenCloseTransaction())
            {
                BlockTable bt =
                    (BlockTable)tr.GetObject(
                        db.BlockTableId, OpenMode.ForRead);

                foreach (ObjectId btrId in bt)
                {
                    BlockTableRecord btr =
                        (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);

                    foreach (ObjectId entId in btr)
                    {
                        if (entId.ObjectClass.Name == "AcDbZombieEntity")
                        {
                            ProxyEntity ent =
                                (ProxyEntity)tr.GetObject(entId, OpenMode.ForRead);

                            // If you want to check what exact proxy it is
                            if (ent.ApplicationDescription != "ProxyToRemove")
                            {
                                return;
                            }

                            ent.UpgradeOpen();

                            using (DBObject newEnt = new Line())
                            {
                                ent.HandOverTo(newEnt, false, false);
                                newEnt.Erase();
                            }
                        }
                    }
                }

                tr.Commit();
            }
        }