代码拉取完成,页面将自动刷新
#include "stdafx.h"
#include "CLayerUtil.h"
CLayerUtil::CLayerUtil()
{
}
CLayerUtil::~CLayerUtil()
{
}
void CLayerUtil::add(TCHAR * LayerName, int colorindex)
{
assert(LayerName != NULL);
assert(colorindex >= 1 && colorindex <= 255);
AcDbLayerTable *pLayerTable = NULL;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTable, AcDb::kForWrite);
if (!pLayerTable->has(LayerName))
{
AcDbLayerTableRecord *pLayerTableRecord = new AcDbLayerTableRecord();
pLayerTableRecord->setName(LayerName);
AcCmColor color;
color.setColorIndex(colorindex);
pLayerTableRecord->setColor(color);
pLayerTable->add(pLayerTableRecord);
pLayerTableRecord->close();
}
pLayerTable->close();
}
AcDbObjectId CLayerUtil::GetLayerID(TCHAR * LayerName)
{
assert(LayerName);
AcDbLayerTable *pLayerTable = NULL;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTable);
AcDbObjectId Layerid = AcDbObjectId::kNull;
if (pLayerTable->has(LayerName))
{
pLayerTable->getAt(LayerName, Layerid);
}
pLayerTable->close();
return Layerid;
}
bool CLayerUtil::SetLayerColor(TCHAR * layerName, int colorindex)
{
bool result = false;
AcDbObjectId layerid = GetLayerID(layerName);
AcDbLayerTableRecord *pLayerTableRecord = NULL;
if (acdbOpenObject(pLayerTableRecord,layerid,AcDb::kForWrite)==Acad::eOk)
{
AcCmColor color;
color.setColorIndex(colorindex);
pLayerTableRecord->setColor(color);
result = true;
pLayerTableRecord->close();
}
return result;
}
void CLayerUtil::GetAllLayerIDList(AcDbObjectIdArray & layerids)
{
AcDbLayerTable *pLayerTable = NULL;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTable);
AcDbLayerTableIterator *it;
pLayerTable->newIterator(it);
for (it->start();!it->done();it->step())
{
AcDbLayerTableRecord *pLayerTableRecord = NULL;
if (it->getRecord(pLayerTableRecord) == Acad::eOk)
{
layerids.append(pLayerTableRecord->objectId());
pLayerTableRecord->close();
}
}
delete it;
pLayerTable->close();
}
void CLayerUtil::DeleteLayer(TCHAR * LayerName)
{
AcDbObjectId Layerid = GetLayerID(LayerName);
AcDbLayerTableRecord *pLayerRecord = NULL;
if (acdbOpenObject(pLayerRecord,Layerid,AcDb::kForWrite)==Acad::eOk)
{
pLayerRecord->erase();
pLayerRecord->close();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。