Hello,
i have found a solution, it is perhaps not the best, but it works and plain AutoCAD read the dwg without proxyerror.
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<String> badNamedObjPattern = new List<String>() { "{24de2741", "ade_", "aec_", "autodesk_map", "gwsundorecorder", "root" };
List<String> deleteDictEntry = new List<String>();
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<String> badNamePattern = new List<String>() { "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;
}
Important!
You don't save the database with "document.CloseAndSave(fileName)" this function include again the 'bad-civil-Objects'.
If you save database with "database.SaveAs(filename)" works fine.
regards
Mario