找回密码
 立即注册

QQ登录

只需一步,快速开始

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

OBJECT ARX 插入块

[复制链接]

1

主题

0

回帖

37

积分

管理员

积分
37
发表于 2024-5-2 22:53:00 | 显示全部楼层 |阅读模式
  1. 添加块到块表中================
  2. static void TESTaddblkcmd(){
  3. AcDbBlockTable* pBlkTbl;
  4. acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite);
  5. 创建新块
  6. AcDbBlockTableRecord* pBlkTblRcd;
  7. pBlkTblRcd = new AcDbBlockTableRecord();
  8. 根据用户的输入设置块表记录的名称
  9. TCHAR blkName[256];
  10. if(acedGetString(Adesk::kFalse,采用T("\n输入块名称"),blkName) != RTNORM){
  11. pBlkTbl->close();
  12. delete pBlkTblRcd;
  13. return;
  14. }
  15. pBlkTblRcd->setName(blkName);
  16. 将块表记录添加到块表中
  17. AcDbObjectId blkDefId;
  18. pBlkTbl->add(blkDefId,pBlkTblRcd);
  19. pBlkTbl->close();
  20. 向块表记录中添加实体
  21. AcGePoint3d ptStart(-10,0,0),ptEnd(10,0,0);
  22. AcDbLine* pLine1 = new AcDbLine(ptStart,ptEnd);
  23. ptStart.set(0,-10,0);
  24. ptEnd.set(0,10,0);
  25. AcDbLine *pLine2 = new AcDbLine(ptStart,ptEnd);
  26. AcGeVector3d vecNormal(0,0,1);
  27. AcDbCircle *pCircle = new AcDbCircle(AcGePoint3d::kOrigin,vecNormal,6);
  28. AcDbObjectId entId;
  29. pBlkTblRcd->appendAcDbEntity(entId,pLine1);
  30. pBlkTblRcd->appendAcDbEntity(entId,pLine2);
  31. pBlkTblRcd->appendAcDbEntity(entId,pCircle);
  32. 关闭实体块表记录
  33. pLine1->close();
  34. pLine2->close();
  35. pCircle->close();
  36. pBlkTblRcd->close();
  37. }
  38. 插入块参照
  39. static void TESTaddblkrefcmd(){
  40. 获得用户输入的块定义名称
  41. CString strBlkDef;
  42. if(acedGetString(Adesk::kFalse,采用T("\n输入块名称\n"),strBlkDef.GetBuffer()) != RTNORM){
  43. return;
  44. }
  45. acutPrintf(strBlkDef);
  46. 获得当前数据库的块表
  47. AcDbBlockTable* pBlkTbl;
  48. acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite);
  49. 查找用户指定的块定义是否存在
  50. if(!pBlkTbl->has(strBlkDef)){
  51. acutPrintf(采用T("\n当前图形中未包含块定义"));
  52. pBlkTbl->close();
  53. return;
  54. }
  55. 获得用户输入的块参照的插入点
  56. ads采用point pt;
  57. if(acedGetPoint(NULL,采用T("\n输入块参照的插入点"),pt) != RTNORM){
  58. pBlkTbl->close();
  59. return;
  60. }
  61. AcGePoint3d ptInsert = asPnt3d(pt);
  62. 获得用户制定的块表记录
  63. AcDbObjectId blkDefId;
  64. pBlkTbl->getAt(strBlkDef,blkDefId);
  65. 创建块参照对象
  66. AcDbBlockReference* pBlkRef = new AcDbBlockReference(ptInsert,blkDefId);
  67. 将块参照添加到模型空间
  68. AcDbBlockTableRecord* pBlkTblRcd;
  69. pBlkTbl->getAt(ACDB采用MODEL采用SPACE,pBlkTblRcd,AcDb::kForWrite);
  70. AcDbObjectId entId;
  71. pBlkTblRcd->appendAcDbEntity(entId,pBlkRef);
  72. 关闭数据库对象
  73. pBlkTbl->close();
  74. pBlkTblRcd->close();
  75. pBlkTbl->close();
  76. }
  77. ===================================================插入带有属性的块定义
  78. static void TESTaddblk2cmd(){
  79. 获得当前图形的数据库块表
  80. AcDbBlockTable* pBlkTbl;
  81. acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite);
  82. 创建新的块表记录
  83. AcDbBlockTableRecord* pBlkTblRcd;
  84. pBlkTblRcd = new AcDbBlockTableRecord();
  85. 根据用户的输入设置块表记录的名称
  86. CString blkName;
  87. if(acedGetString(Adesk::kFalse,采用T("\n输入块表记录名称:"),blkName.GetBuffer()) != RTNORM){
  88. pBlkTbl->close();
  89. delete pBlkTblRcd;
  90. return;
  91. }
  92. pBlkTblRcd->setName(blkName);
  93. 将块表记录添加到块表中
  94. AcDbObjectId blkDefId;
  95. pBlkTbl->add(blkDefId,pBlkTblRcd);
  96. pBlkTbl->close();
  97. 向块表记录添加实体
  98. AcGePoint3d ptStart(-10,0,0);
  99. AcGePoint3d ptEnd(10,0,0);
  100. AcDbLine* pLine1 = new AcDbLine(ptStart,ptEnd);
  101. ptStart.set(0,-10,0);
  102. ptEnd.set(0,10,0);
  103. AcDbLine* pLine2 = new AcDbLine(ptStart,ptEnd);
  104. AcGeVector3d vecNormal(0,0,1);
  105. AcDbCircle* pCircle = new AcDbCircle(AcGePoint3d::kOrigin,vecNormal,6);
  106. 创建一个属性,输入直径
  107. AcDbAttributeDefinition* pAttDef = new AcDbAttributeDefinition(ptEnd,采用T("20"),采用T("直径"),采用T("输入直径"));
  108. AcDbObjectId entId;
  109. pBlkTblRcd->appendAcDbEntity(entId,pLine1);
  110. pBlkTblRcd->appendAcDbEntity(entId,pLine2);
  111. pBlkTblRcd->appendAcDbEntity(entId,pCircle);
  112. pBlkTblRcd->appendAcDbEntity(entId,pAttDef);
  113. 关闭实体和块表记录
  114. pLine1->close();
  115. pLine2->close();
  116. pCircle->close();
  117. pAttDef->close();
  118. pBlkTblRcd->close();
  119. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-1-4 13:08 , Processed in 0.121469 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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