ObjectARX编程(五) ---------符号表中层表的操作

来源:互联网 发布:c语言for循环语句 编辑:程序博客网 时间:2024/06/16 01:01
创建新的图层,实际上就是创建一个新的层表的记录,并将其添加到层表中。

修改一个图层的颜色,可以从层表中获取指定的记录,然后使用ACDBLayerTableRecord类的setColor函数设置层表记录的颜色。

删除一个图层,需要首先从层表中获取指定的层表记录,然后将层表记录设置一个删除的标记。

1. 新建图层
szLayerName;
//第一步首先获取数据库
//获取层表
AcDbLayerTable* pLayerTable = NULL
addbHostApplicationServices()->workingDatabase()->getSymbomTable(pLayerTable ,AcDb::kForWrite);
//判断是否已经存在同名的层表
if(pLayerTable->has(szLayerName))
return ;
//创建层表记录
AcDbLayerTableRecord *pLayerTableRcd = new AcDbLayerTableRecord();
pLayerTableRcd->setName(szLayerName);
//修改层表记录属性 设置颜色等。
AcCmColor color;
color->setColorIndex(colorIndex);
pLayerTableRcd->setColor(color);
//把层表记录添加到层表中
pLayerTable->add(pLayerTableRcd );
//关闭表和表记录
pLayerTableRcd ->close();
pLayerTable->close();

2. 删除图层
szLayerName;
//获取层表
AcDbLayerTable* pLayerTable = NULL
addbHostApplicationServices()->workingDatabase()->getSymbomTable(pLayerTable ,AcDb::kForWrite);
//获取图层表记录的ID
AcDbObjectID layerId = AcDbObjectId::kNull;
if(!pLayerTable->has(szLayerName))
pLayerTable ->getAt(szLayerName,layerId );
pLayerTable ->close();
//判断ID是否无效
//通过ID获取图层表记录
AcDbLayerTableRecord *pLayerTableRcd = NULL;
if(layerId.isValid())
acdbOpenObject(pLayerTableRcd ,layerId,AcDb::kForWrite);
//删除图层表记录
pLayerTableRcd ->erase();
pLayerTableRcd ->close();

3. 遍历图层表记录

//获取层表
AcDbLayerTable* pLayerTable = NULL
addbHostApplicationServices()->workingDatabase()->getSymbomTable(pLayerTable ,AcDb::kForWrite);
//获取层表记录的浏览器
AcDbLayerTableIterator *it = NULL;
pLayerTable ->newIterator(it);
//循环遍历
AcDbLayerTableRecord *pLayerTableRcd = NULL;
for(it->start();!it->done();iter->step())
{
it->getRecord(pLayerTableRcd ,AcDb::kForRead);
//TODO 处理
pLayerTableRcd ->close();
}
delete if;
pLayerTable ->close();
阅读全文
0 0
原创粉丝点击