- UID
- 267748
- 积分
- 1223
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-5-27
- 最后登录
- 1970-1-1
|
发表于 2006-7-22 19:49:47
|
显示全部楼层
删除 'DIM' 图层中的所有图形
(vl-cmdf "erase" (ssget "X" '((8 . "DIM"))) "")
http://discussion.autodesk.com/thread.jspa?threadID=105862
Re: AcDbObject::erase()
I couldn't really see anything that sticks out except a
memory leak, and the suspect AcDb::kForWrite on
pEntity. Here's your code back with comments and
changes.
Paul Kohut
bool CSCArxEntityDM::DeleteEntitiesByLayer(CString strLayerName, bool bIncludeModelSpace)
{
Acad::ErrorStatus eStatus;
AcDbBlockTable* pBlockTable;
eStatus =acdbHostApplicationServices()->workingDatabase()->getSymbolTable (pBlockTable
, AcDb::kForRead);
if(eStatus != eOk)
return false;
AcDbBlockTableIterator * pBlockTableIterator;
eStatus = pBlockTable->newIterator(pBlockTableIterator);
pBlockTable->close();
if(eStatus != eOk)
return false;
AcDbBlockTableRecord* pBlockTableRecord;
for(; !pBlockTableIterator->done(); pBlockTableIterator->step())
{
eStatus = pBlockTableIterator->getRecord(pBlockTableRecord,
AcDb::kForRead);
if(eStatus != eOk)
return false;
//if not layout continue
if(!pBlockTableRecord->isLayout())
{
pBlockTableRecord->close();
continue;
}
//if exclude model space true and is model space, continue
if(!bIncludeModelSpace)
{
// make it a const, or remember to delete the memory
const char* szBlockName;
pBlockTableRecord->getName(szBlockName);
if(!strcmp(szBlockName, "*Model_Space"))
{
pBlockTableRecord->close();
continue;
}
}
AcDbBlockTableRecordIterator* pBlockTableRecordIterator;
eStatus = pBlockTableRecord->newIterator(pBlockTableRecordIterator);
pBlockTableRecord->close();
if(eStatus != eOk)
return false;
AcDbEntity* pEntity;
// not needed, variable name is confusing (IMO)
// const char* szLayerName = (LPCTSTR)strLayerName;
char* szEntityLayer;
for(; !pBlockTableRecordIterator->done();
pBlockTableRecordIterator->step())
{
//eStatus = pBlockTableRecordIterator->getEntity(pEntity,
AcDb::kForWrite);
// Since layer() is a query function, should entity be opened for read?
eStatus = pBlockTableRecordIterator->getEntity(pEntity, AcDb::kForRead);
if(eStatus != eOk)
return false;
szEntityLayer = pEntity->layer();
// strcmp is declared as
// int strcmp( const char *string1, const char *string2 );
// notice the const, the compiler will take care of converting
// the CString to LPCTSTR
if(!strcmp(szEntityLayer, strLayerName))
{
// now change pEntity to AcDb::kForWrite
pEntity->upgradeOpen();
pEntity->erase();
}
// Probably doesn't matter, but docs recommend acutDelString
acutDelString(szEntityLayer);
// delete [] szEntityLayer;
pEntity->close();
}
delete pBlockTableRecordIterator;
}
delete pBlockTableIterator;
return true;
} |
|