|
#include "StdAfx.h"
#include "StdArx.h"
#include <dbsymtb.h>// This is command 'DELLAYER'
void DelLayer()
{
char pcBuffer [133] ;
if (acedGetString (0, "\nLayer name to delete: ", pcBuffer) == RTNORM) {
if (strcmp (pcBuffer, "0") == 0 ) {
acutPrintf ("\nCannot erase layer (0) !") ;
return ;
}
struct resbuf result ;
acedGetVar ("CLAYER", &result) ;
if (stricmp (pcBuffer, result.resval.rstring) == 0 ) {
free (result.resval.rstring) ;
acutPrintf ("\nCannot erase current layer !") ;
return ;
}
free (result.resval.rstring) ;
AcDbLayerTable *pLayerTable =NULL ;
if (acdbHostApplicationServices()->workingDatabase()->
getSymbolTable (pLayerTable, AcDb::kForRead)== Acad::eOk ) {
if (pLayerTable->has (pcBuffer)) {
AcDbObjectId id ;
pLayerTable->getAt (pcBuffer, id) ;
AcDbObjectIdArray idArray ;
idArray.append (id) ;
if (acdbHostApplicationServices()->
workingDatabase()->purge (idArray) == Acad::eOk) {
if (idArray.contains (id) ) {
AcDbLayerTableRecord *pLayer ;
pLayerTable->getAt (pcBuffer,pLayer, AcDb::kForWrite) ;
pLayer->erase (Adesk::kTrue) ;
pLayer->close () ;
acutPrintf ("\nLayer (%s)deleted !", pcBuffer) ;
}
else {
acutPrintf ("\nLayer (%s) is referenced !", pcBuffer) ;
}
}
else {
acutPrintf ("\nLayer (%s) cannot be deleted !", pcBuffer) ;
}
}
else {
acutPrintf ("\nLayer (%s) does not exist !",pcBuffer) ;
}
pLayerTable->close () ;
}
}
} |
|