找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 138|回复: 0

OBJECT ARX 操作图层

[复制链接]

1

主题

0

回帖

37

积分

管理员

积分
37
发表于 2024-5-2 22:52:44 | 显示全部楼层 |阅读模式
  1. //添加图层
  2. static void TESTaddlayercmd(){
  3. CString strLayerName;
  4. if(acedGetString(Adesk::kFalse,采用T("\n输入层名称"),strLayerName.GetBuffer()) != RTNORM){
  5. return;
  6. }
  7. 获得当前图形的层表
  8. AcDbLayerTable* pLayerTbl;
  9. acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForWrite);
  10. 是否已经包含制定的层表记录
  11. if(pLayerTbl->has(strLayerName)){
  12. pLayerTbl->close();
  13. return;
  14. }
  15. 创建新的层表记录
  16. AcDbLayerTableRecord* pLayerTblRcd;
  17. pLayerTblRcd = new AcDbLayerTableRecord();
  18. pLayerTblRcd->setName(strLayerName);
  19. 将新创建的层表记录添加到层表中
  20. AcDbObjectId layerTblRcdId;
  21. pLayerTbl->add(layerTblRcdId,pLayerTblRcd);
  22. acdbHostApplicationServices()->workingDatabase()->setClayer(layerTblRcdId);
  23. pLayerTblRcd->close();
  24. pLayerTbl->close();
  25. }
  26. //修改图层颜色============================
  27. static void TESTlayercolorcmd(){
  28. CString strLayerName;
  29. if(acedGetString(Adesk::kFalse,采用T("\n输入图层的名称:"),strLayerName.GetBuffer()) != RTNORM){
  30. return;
  31. }
  32. 获得当前的图层列表
  33. AcDbLayerTable* pLayerTbl;
  34. acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForRead);
  35. 判断是否包含指定名称的层表记录
  36. if(!pLayerTbl->has(strLayerName)){
  37. pLayerTbl->close();
  38. return;
  39. }
  40. 获得制定层表记录的指针
  41. AcDbLayerTableRecord* pLayerTblRcd;
  42. pLayerTbl->getAt(strLayerName,pLayerTblRcd,AcDb::kForWrite);
  43. 弹出颜色对话框
  44. AcCmColor oldColor = pLayerTblRcd->color();
  45. int nCurColor = oldColor.colorIndex();//旧的颜色
  46. int nNewColor = oldColor.colorIndex();//用户选择的颜色
  47. if(acedSetColorDialog(nNewColor,Adesk::kFalse,nCurColor)){
  48. AcCmColor color;
  49. color.setColorIndex(nNewColor);
  50. pLayerTblRcd->setColor(color);
  51. }
  52. pLayerTblRcd->close();
  53. pLayerTbl->close();
  54. }
  55. //删除图层
  56. static void TESTdellayercmd(){
  57. CString strLayerName;
  58. if(acedGetString(Adesk::kFalse,采用T("\n输入图层名称"),strLayerName.GetBuffer()) != RTNORM){
  59. return;
  60. }
  61. 获得当前的图层列表
  62. AcDbLayerTable* pLayerTbl;
  63. acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForRead);
  64. 判断是否包含指定名称的层表记录
  65. if(!pLayerTbl->has(strLayerName)){
  66. pLayerTbl->close();
  67. return;
  68. }
  69. 获得制定层表记录的指针
  70. AcDbLayerTableRecord* pLayerTblRcd;
  71. pLayerTbl->getAt(strLayerName,pLayerTblRcd,AcDb::kForWrite);
  72. pLayerTblRcd->erase();
  73. pLayerTblRcd->close();
  74. pLayerTbl->close();
  75. }
  76. 导出层的信息到文本文件中
  77. static void TESTexportlayercmd(){
  78. //创建要导出的文本文件
  79. CStdioFile f;
  80. CFileException e;
  81. CString pFileName;
  82. pFileName = 采用T("D:\\layer.txt");
  83. if(!f.Open(pFileName.GetString(),CFile::modeCreate|CFile::modeWrite,&e)){
  84. acutPrintf(采用T("\n创建文件失败"));
  85. return;
  86. }
  87. 获得层表指针
  88. AcDbLayerTable *pLayerTbl;
  89. AcDbLayerTableRecord* pLayerTblRcd;
  90. acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForRead);
  91. 使用遍历器访问每条层表记录
  92. AcDbLayerTableIterator* pItr;
  93. pLayerTbl->newIterator(pItr);
  94. for(pItr->start();!pItr->done();pItr->step()){
  95. pItr->getRecord(pLayerTblRcd,AcDb::kForRead);
  96. 输出图层的信息
  97. CString strLayerInfo;
  98. TCHAR* layerName;
  99. pLayerTblRcd->getName(layerName);
  100. 名称
  101. strLayerInfo = layerName;
  102. free(layerName);
  103. strLayerInfo.Append(采用T(","));
  104. CString strColor;
  105. AcCmColor color = pLayerTblRcd->color();
  106. strColor.Format(采用T("%d"),color.colorIndex());
  107. strLayerInfo.Append(strColor);
  108. 线型
  109. CString strLineType;
  110. AcDbLinetypeTableRecord* pLinetypeTblRcd;
  111. acdbOpenObject(pLinetypeTblRcd,pLayerTblRcd->linetypeObjectId(),AcDb::kForRead);
  112. TCHAR* linetypeName;
  113. pLinetypeTblRcd->getName(linetypeName);
  114. pLinetypeTblRcd->close();
  115. strLineType = linetypeName;
  116. free(linetypeName);
  117. strLayerInfo.Append(strLineType);
  118. strLayerInfo.Append(采用T(","));
  119. 线宽
  120. CString strLineWeight;
  121. AcDb::LineWeight lineWeight = pLayerTblRcd->lineWeight();
  122. strLineWeight.Format(采用T("%d"),lineWeight);
  123. strLayerInfo.Append(strLineWeight);
  124. /写文件
  125. f.WriteString(strLayerInfo);
  126. f.WriteString(采用T("\n"));
  127. pLayerTblRcd->close();
  128. }
  129. delete pItr;
  130. pLayerTbl->close();
  131. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2025-1-4 12:53 , Processed in 0.122278 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表