Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to delete a layer( in ARX )

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
398 Views, 4 Replies

How to delete a layer( in ARX )

Hi
I already know how to add layers to AcDbLayerTable by Add() function. But,
How to delete the layer ?
Any help would be appreciated.
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Hi. When AcDbObject has been added to the database, you can’t delete it. I think You can do it only by use acedCommand() function because AutoCAD manages the deletion of all resident objects.
VVV
Message 3 of 5
Anonymous
in reply to: Anonymous

Hi Jeff,
just call AcDbObject::erase(). Naturaly there should be no objects
referencing that layer.

"Jeff" wrote in message
news:F25246CDCCF94515C468B8EB2907EEAA@in.WebX.maYIadrTaRb...
> Hi
> I already know how to add layers to AcDbLayerTable by Add() function. But,
> How to delete the layer ?
> Any help would be appreciated.
>
>
>
>
Message 4 of 5
forARX
in reply to: Anonymous

void iterateEntitiesOnLayer(const char *sName, void *pFunction(AcDbEntity *))
{
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
// Open the model space block table record.
AcDbBlockTable *pBlkTbl;
pDb->getSymbolTable(pBlkTbl, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcd;

const char* psSpaceName = ACDB_MODEL_SPACE;
int iIsPaper = 0;

Lpaper:
pBlkTbl->getAt(psSpaceName, pBlkTblRcd, AcDb::kForRead);
pBlkTbl->close();
AcDbBlockTableRecordIterator *pBlkTblRcdItr;
pBlkTblRcd->newIterator(pBlkTblRcdItr);
AcDbEntity *pEnt;
for (pBlkTblRcdItr->start(); !pBlkTblRcdItr->done(); pBlkTblRcdItr->step())
{
pBlkTblRcdItr->getEntity(pEnt, AcDb::kForWrite);
if(0 == strcmp(pEnt->layer(), sName)) pFunction(pEnt);
pEnt->close();
}
pBlkTblRcd->close();
delete pBlkTblRcdItr;

if(iIsPaper == 0)
{
psSpaceName = ACDB_PAPER_SPACE;
iIsPaper = 1;
goto Lpaper;
}
}

void eraseEntity(AcDbEntity *pEnt)
{
pEnt->erase();
}

// Deletes ALL (!!!) objects on the corresponding to sName layer
void eraseEntitiesOnLayer(const char *sName)
{
iterateEntitiesOnLayer(sName, (void *(__cdecl *)(class AcDbEntity *))eraseEntity);
}


eraseEntitiesOnLayer(sLayerName); // The layer is now empty - it's safe to delete it.

AcDbLayerTable *pLayerTable;
db->getSymbolTable(pLayerTable, AcDb::kForWrite);
AcDbLayerTableRecord *pLayerTableRec;
if(Acad::eOk == pLayerTable->getAt(pEnt->layer(), pLayerTableRec, AcDb::kForWrite));// acutPrintf("\nOK!");

pLayerTableRec->erase();

pLayerTableRec->close();
pLayerTable->close();
Message 5 of 5
Anonymous
in reply to: Anonymous

Another necessary condition - erased layer should not be current layer.
VVV

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost