TA的每日心情 | 开心 6 小时前 |
---|
签到天数: 20 天 [LV.4]偶尔看看III
管理员
- 积分
- 1393
|
-
- //添加图层
- 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();
-
-
-
-
-
-
-
- }
-
-
- 导出层的信息到文本文件中
- 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();
- strColor.Format(采用T("%d"),color.colorIndex());
- strLayerInfo.Append(strColor);
- 线型
- CString strLineType;
- AcDbLinetypeTableRecord* pLinetypeTblRcd;
- acdbOpenObject(pLinetypeTblRcd,pLayerTblRcd->linetypeObjectId(),AcDb::kForRead);
- TCHAR* linetypeName;
- pLinetypeTblRcd->getName(linetypeName);
- pLinetypeTblRcd->close();
- strLineType = linetypeName;
- free(linetypeName);
-
-
- strLayerInfo.Append(strLineType);
- strLayerInfo.Append(采用T(","));
-
-
- 线宽
- CString strLineWeight;
- AcDb::LineWeight lineWeight = pLayerTblRcd->lineWeight();
- strLineWeight.Format(采用T("%d"),lineWeight);
- strLayerInfo.Append(strLineWeight);
-
-
- /写文件
- f.WriteString(strLayerInfo);
- f.WriteString(采用T("\n"));
- pLayerTblRcd->close();
-
-
-
-
- }
-
-
- delete pItr;
- pLayerTbl->close();
-
-
- }
-
-
-
复制代码 |
|