|
使用 ObjectARX 删除图层过滤器
我有一个客户,他在图层上使用许多 dwgs 和许多过滤器。如何使用程序删除过滤器?
图层筛选器作为 AcDbXRecord 条目存在于图层表的扩展字典中包含的两个字典(名称为"ACAD_LAYERFILTERS"和"ACLYDICTIONARY")中。要删除图层过滤器,您需要循环访问"ACAD_LAYERFILTERS"和"ACLYDICTIONARY"字典并删除所有 AcDbXRecords。
[code]static void ASDKLayerFilterDelete_DeleteLayerFilters(void)
{
// Set constructor parameter to kFalse so that the
// database will be constructed empty. This way only
// what is read in will be in the database.
AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse);
// The AcDbDatabase::readDwgFile() function
// automatically appends a DWG extension if it is not
// specified in the filename parameter.
pDb->readDwgFile(_T("c:\\drawing1.dwg"));
// ensure the whole dwg is read
pDb->closeInput(true);
// Get the Layer Table
AcDbLayerTablePointer pLyrTbl(pDb->layerTableId(), AcDb::kForRead);
if (pLyrTbl.openStatus() == Acad::eOk)
{
// Get Extention dictionary
AcDbObjectId pExtDicId = pLyrTbl->extensionDictionary();
if(pExtDicId.isValid())
{
AcDbDictionaryPointer pDict(pExtDicId,AcDb::kForRead);
if(Acad::eOk == pDict.openStatus())
{
// Get Layer Filter Dictionary from extension dictionary
AcDbObjectId pObjId;
pDict->getAt(_T("ACAD_LAYERFILTERS"),pObjId);
if(pObjId.isValid())
{
AcDbDictionaryPointer pFiltDict(pObjId,AcDb::kForRead);
if(Acad::eOk == pFiltDict.openStatus())
{
// Get objects in layer filter dictionary
AcDbObjectId filtObjId;
AcDbDictionaryIterator *pItr = pFiltDict->newIterator();
if (NULL != pItr)
{
for(;!pItr->done();pItr->next())
{
AcDbObjectPointer<AcDbXrecord> pLyrFltr(pItr->objectId(),AcDb::kForWrite);
if(Acad::eOk == pLyrFltr.openStatus())
{
pLyrFltr->erase();
}
}
delete pItr;
}
}
}
pDict->getAt(_T("ACLYDICTIONARY"),pObjId);
if(pObjId.isValid())
{
AcDbDictionaryPointer pFiltDict(pObjId,AcDb::kForRead);
if(Acad::eOk == pFiltDict.openStatus())
{
// Get objects in layer filter dictionary
AcDbObjectId filtObjId;
AcDbDictionaryIterator *pItr = pFiltDict->newIterator();
if(NULL != pItr)
{
for(;!pItr->done();pItr->next())
{
AcDbObjectPointer<AcDbXrecord> pLyrFltr(pItr->objectId(),AcDb::kForWrite);
if(Acad::eOk == pLyrFltr.openStatus())
{
pLyrFltr->erase();
}
}
delete pItr;
}
}
}
}
}
}
Acad::ErrorStatus es = pDb->saveAs(_T("c:\\drawing1.dwg"));
delete pDb;
}[/code] |
|