2 Star 4 Fork 3

danel996 / AutoCAD-ObjectArx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CLayerUtil.cpp 2.24 KB
一键复制 编辑 原始数据 按行查看 历史
lysjq 提交于 2018-07-15 15:21 . Some ObjectArx class
#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();
}
}
1
https://gitee.com/anheihb03dlj/AutoCAD-ObjectArx.git
git@gitee.com:anheihb03dlj/AutoCAD-ObjectArx.git
anheihb03dlj
AutoCAD-ObjectArx
AutoCAD-ObjectArx
master

搜索帮助