|
- //添加图层
- static void TESTaddlayercmd(){
- CString strLayerName;
- if(acedGetString(Adesk::kFalse,采用T("\n输入层名称"),strLayerName.GetBuffer()) != RTNORM){
- return;
- }
- ////获得当前图形的层表
- AcDbLayerTable* pLayerTbl;
- acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForWrite);
- ////是否已经包含制定的层表记录
- if(pLayerTbl->has(strLayerName)){
- pLayerTbl->close();
- return;
- }
- ////创建新的层表记录
- AcDbLayerTableRecord* pLayerTblRcd;
- pLayerTblRcd = new AcDbLayerTableRecord();
- pLayerTblRcd->setName(strLayerName);
- ////将新创建的层表记录添加到层表中
- AcDbObjectId layerTblRcdId;
- pLayerTbl->add(layerTblRcdId,pLayerTblRcd);
- acdbHostApplicationServices()->workingDatabase()->setClayer(layerTblRcdId);
- pLayerTblRcd->close();
- pLayerTbl->close();
- }
- //修改图层颜色============================
- static void TESTlayercolorcmd(){
- CString strLayerName;
- if(acedGetString(Adesk::kFalse,采用T("\n输入图层的名称:"),strLayerName.GetBuffer()) != RTNORM){
- return;
- }
- ////获得当前的图层列表
- AcDbLayerTable* pLayerTbl;
- acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForRead);
- ////判断是否包含指定名称的层表记录
- if(!pLayerTbl->has(strLayerName)){
- pLayerTbl->close();
- return;
- }
- ////获得制定层表记录的指针
- AcDbLayerTableRecord* pLayerTblRcd;
- pLayerTbl->getAt(strLayerName,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();
- }
- //删除图层
- static void TESTdellayercmd(){
- CString strLayerName;
- if(acedGetString(Adesk::kFalse,采用T("\n输入图层名称"),strLayerName.GetBuffer()) != RTNORM){
- return;
- }
- ////获得当前的图层列表
- AcDbLayerTable* pLayerTbl;
- acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForRead);
- ////判断是否包含指定名称的层表记录
- if(!pLayerTbl->has(strLayerName)){
- pLayerTbl->close();
- return;
- }
- ////获得制定层表记录的指针
- AcDbLayerTableRecord* pLayerTblRcd;
- pLayerTbl->getAt(strLayerName,pLayerTblRcd,AcDb::kForWrite);
- pLayerTblRcd->erase();
- pLayerTblRcd->close();
- pLayerTbl->close();
- }
- ////导出层的信息到文本文件中
- [it618postdisplay>0]
- static void TESTexportlayercmd(){
- //创建要导出的文本文件
- CStdioFile f;
- CFileException e;
- CString pFileName;
- pFileName = 采用T("D:\\layer.txt");
- if(!f.Open(pFileName.GetString(),CFile::modeCreate|CFile::modeWrite,&e)){
- acutPrintf(采用T("\n创建文件失败"));
- return;
- }
- ////获得层表指针
- AcDbLayerTable *pLayerTbl;
- AcDbLayerTableRecord* pLayerTblRcd;
- acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForRead);
- ////使用遍历器访问每条层表记录
- AcDbLayerTableIterator* pItr;
- pLayerTbl->newIterator(pItr);
- for(pItr->start();!pItr->done();pItr->step()){
- pItr->getRecord(pLayerTblRcd,AcDb::kForRead);
- ////输出图层的信息
- CString strLayerInfo;
- TCHAR* layerName;
- pLayerTblRcd->getName(layerName);
- ////名称
- strLayerInfo = layerName;
- free(layerName);
- strLayerInfo.Append(采用T(","));
- ////颜
- CString strColor;
- AcCmColor color = pLayerTblRcd->color();
复制代码 |
|