您好,
我找到了一个解决方案,它可能不是最好的,但它的工作和普通AutoCAD读取dwg没有代理错误。
- public static Boolean cleanCivilObjects()
- {
- Boolean result = false;
- Database acDatabase = HostApplicationServices.WorkingDatabase;
- using (Transaction acTransaction = acDatabase.TransactionManager.StartTransaction())
- {
- // 1. clean Named Object Dictionary
- // Namepattern for search StartsWith
- List badNamedObjPattern = new List() { "{24de2741", "ade_", "aec_", "autodesk_map", "gwsundorecorder", "root" };
- List deleteDictEntry = new List();
- DBDictionary acNamedObjectDict = (DBDictionary)acTransaction.GetObject(acDatabase.NamedObjectsDictionaryId, OpenMode.ForWrite);
- foreach (DBDictionaryEntry acNamedItem in acNamedObjectDict)
- {
- foreach (String namePattern in badNamedObjPattern)
- {
- if (acNamedItem.Key.ToLower().StartsWith(namePattern))
- {
- deleteDictEntry.Add(acNamedItem.Key);
- break;
- }
- }
- }
- if (deleteDictEntry.Count > 0)
- {
- foreach (String delName in deleteDictEntry)
- {
- acNamedObjectDict.Remove(delName);
- }
- }
- // 2. clean RegAppTable
- // Namepattern for search StartsWith
- List badNamePattern = new List() { "acmap", "ade", "aecc", "acaec", "dco", "map" };
- RegAppTable acRegAppTable = (RegAppTable)transaction.GetObject(acDatabase.RegAppTableId, OpenMode.ForRead);
- ObjectIdCollection objectIdsToDelete = new ObjectIdCollection();
- foreach (ObjectId acRATRId in acRegAppTable)
- {
- RegAppTableRecord acRegAppTableRecord = (RegAppTableRecord)acTransaction.GetObject(acRATRId, OpenMode.ForRead);
- if (acRegAppTableRecord != null)
- {
- foreach (String namePattern in badNamePattern)
- {
- if (acRegAppTableRecord.Name.ToLower().StartsWith(namePattern))
- {
- if (!objectIdsToDelete.Contains(acRegAppTableRecord.Id))
- objectIdsToDelete.Add(acRegAppTableRecord.Id);
- break;
- }
- }
- }
- }
- // delete all Objects
- if (objectIdsToDelete.Count > 0)
- {
- DBObject acDBObject;
- foreach (ObjectId acObjectId in objectIdsToDelete)
- {
- acDBObject = acTransaction.GetObject(acObjectId, OpenMode.ForWrite);
- acDBObject.Erase(true);
- }
- }
- acTransaction.Commit()
- result = true;
- }
- return result;
- }
重要!
您没有保存包含文档的数据库。CloseAndSave(fileName)" 该函数再次包括“bad-civil-Objects”。
如果使用“数据库”保存数据库。SaveAs(filename)“工作正常。问候马里奥 |