ObjectArx图层操作总结

您所在的位置:网站首页 cad怎么换图层操作 ObjectArx图层操作总结

ObjectArx图层操作总结

2024-07-10 09:45| 来源: 网络整理| 查看: 265

ObjectArx图层操作总结

参考了网上收集资料,经过实测,ObjectArx2014和2018也可以用的,应该其他版本也没有问题的。文中的很多注释很详细,希望可以帮到新人。

1. 新建一个图层

CLayerOperator定义了NewLayer函数,用于完成图层的新建操作,NewLayer的完整代码如下:

// 新建一个图层 void CLayerOperator::NewLayer(ACHAR* layerName) { //获得当前图形的层表 AcDbLayerTable *pLayerTbl; acdbHostApplicationServices() ->workingDatabase() ->getLayerTable(pLayerTbl,AcDb::kForWrite); //是否已经包含指定的层表记录 if(pLayerTbl->has(layerName)){ pLayerTbl->close(); acedPrompt(_T("对应名称的图层已经存在!")); return; } //创建层表记录 AcDbLayerTableRecord *pLayerTblRcd; pLayerTblRcd=new AcDbLayerTableRecord(); pLayerTblRcd->setName(layerName); //这里的layerName需要用(_T("?"))这种格式来命名 //将新建的层表记录添加到层表中 AcDbObjectId layerTblRcdId; pLayerTbl->add(layerTblRcdId,pLayerTblRcd); //设置图形的当前图层 acdbHostApplicationServices() ->workingDatabase() ->setClayer(layerTblRcdId); //关闭层表 pLayerTblRcd->close(); pLayerTbl->close(); }

NewLayer的具体实现注释已经非常详尽,首先获得当前图形的层表,然后判断层表中是否已经存在指定名称的图层,如果是,则直接返回,否则创建层表记录并将新建的层表记录添加到层表中,最后通过AcDbDatabase类的setClayer函数将新建的图层设置成当前图层。

2.使用图形对话框设置指定图层的颜色 // 使用图形对话框设置指定图层的颜色 void CLayerOperator::SetLayerColor(ACHAR* layerName) { //获得当前图形的层表 AcDbLayerTable *pLayerTbl; acdbHostApplicationServices() ->workingDatabase() ->getLayerTable(pLayerTbl,AcDb::kForRead); //判断是否包含指定名称的层表记录 if(!pLayerTbl->has(layerName)){ pLayerTbl->close(); return; } //获得指定层表记录的指针 AcDbLayerTableRecord *pLayerTblRcd; pLayerTbl->getAt(layerName,pLayerTblRcd,AcDb::kForWrite); //弹出“颜色”对话框 AcCmColor oldColor=pLayerTblRcd->color(); //图层修改前的颜色 int nCurColor=oldColor.colorIndex(); //用户选择的颜色 int nNewColor=oldColor.colorIndex(); if(acedSetColorDialog(nNewColor,Adesk::kFalse,nCurColor)){ AcCmColor color; color.setColorIndex(nNewColor); pLayerTblRcd->setColor(color); } //关闭层表 pLayerTblRcd->close(); pLayerTbl->close(); } 3.删除一个图层 // 删除一个图层 void CLayerOperator::DelLayer(ACHAR* layerName) { //获得当前图形的层表 AcDbLayerTable *pLayerTbl; acdbHostApplicationServices() ->workingDatabase() ->getLayerTable(pLayerTbl,AcDb::kForRead); //判断是否包含指定名称的层表记录 if(!pLayerTbl->has(layerName)){ pLayerTbl->close(); return; } //获得指定层表记录的指针 AcDbLayerTableRecord *pLayerTblRcd; pLayerTbl->getAt(layerName,pLayerTblRcd,AcDb::kForWrite); //为其设置“删除”标记 pLayerTblRcd->erase(); pLayerTblRcd->close(); //关闭层表 pLayerTbl->close(); }

感谢以下文章: http://vcsos.com/article/pageSource/120413/20120413103600_1.shtml



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3