找回密码
 立即注册

QQ登录

只需一步,快速开始

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

获取任意路径Dwg文件内所有块在控件中显示并能选择插入当前模型空间

[复制链接]

1

主题

0

回帖

37

积分

管理员

积分
37
发表于 2024-5-4 18:40:13 | 显示全部楼层 |阅读模式
  1. 主对话框CPP内代码:
  2. #include "StdAfx.h"
  3. #include "resource.h"
  4. #include "BlockDialog.h"
  5. #include "..\..\Common\我的类\file.h"
  6. #include "..\..\Common\Document\DwgDatabaseUtil.h"
  7. #include <dbents.h>
  8. #include <dbmain.h>
  9. #include "..\..\Chapter11\PreviewControl\GsPreviewCtrl.h"
  10. #include "GsPreviewCtrl.h"
  11. #include <gepnt3d.h>
  12. #include <geassign.h>
  13. CString filepatha;
  14. CString filepath;
  15. void CBlockDialog::OnButton1()
  16. {
  17. m采用combo1.ResetContent();
  18. m采用combo2.ResetContent();
  19. m采用combo3.ResetContent();
  20. m采用list.ResetContent();
  21. vector<CString> filename;
  22. Cfile::getFiles(filepath,filename);
  23. int i;
  24. for (i=0;i<filename.size()-2;i++)
  25. {
  26. m采用combo1.AddString(filename[i+2]);
  27. }
  28. if (m采用combo1.GetCount()>0)
  29. {
  30. m采用combo1.SetCurSel(0);
  31. filepatha=filepath.Left(filepath.GetLength()-1);
  32. CString ca;
  33. m采用combo1.GetWindowText(ca);
  34. CString filepathaa=filepatha+ca;
  35. vector<CString> filenamea;
  36. Cfile::getFiles(filepathaa,filenamea);
  37. for (i=0;i<filenamea.size()-2;i++)
  38. {
  39. m采用combo2.AddString(filenamea[i+2]);
  40. }
  41. if (m采用combo2.GetCount()>0)
  42. {
  43. m采用combo2.SetCurSel(0);
  44. CString filepathb=filepathaa.Left(filepathaa.GetLength()-1);
  45. m采用combo2.GetWindowText(ca);
  46. CString filepathbb=filepathb+ca;
  47. vector<CString> filenameb;
  48. Cfile::getFiles(filepathbb,filenameb);
  49. for (i=0;i<filenameb.size()-2;i++)
  50. {
  51. m采用combo3.AddString(filenameb[i+2]);
  52. }
  53. if (m采用combo3.GetCount()>0)
  54. {
  55. m采用combo3.SetCurSel(0);
  56. CString filepathc=filepathbb.Left(filepathbb.GetLength()-1);
  57. m采用combo3.GetWindowText(ca);
  58. CString filepathcc=filepathc+ca;
  59. AcDbDatabase *pDb=new AcDbDatabase(false);
  60. pDb->readDwgFile(filepathcc,采用SH采用DENYWR);
  61. AcDbObjectIdArray allEntIds = CDwgDatabaseUtil::GetAllEntityIds(NULL,pDb);
  62. for (i=0;i<allEntIds.length();i++)
  63. {
  64. AcDbEntity *pEnt=NULL;
  65. if (acdbOpenObject(pEnt,allEntIds[i],AcDb::kForRead)==Acad::eOk)
  66. {
  67. if (pEnt->isKindOf(AcDbBlockReference::desc()))
  68. {
  69. AcDbBlockReference *pBlkRef=NULL;
  70. pBlkRef=AcDbBlockReference::cast(pEnt);
  71. pEnt->close();
  72. AcDbObjectId blkDefId=pBlkRef->blockTableRecord();
  73. pBlkRef->close();
  74. AcDbBlockTableRecord *pBlkDef=NULL;
  75. char *blkDefName;
  76. if (acdbOpenObject(pBlkDef,blkDefId,AcDb::kForRead)==Acad::eOk)
  77. {
  78. pBlkDef->getName(blkDefName);
  79. m采用list.AddString(blkDefName);
  80. pBlkDef->close();
  81. }
  82. }
  83. }
  84. }
  85. pDb->closeInput();
  86. delete pDb;
  87. }
  88. }
  89. }
  90. filepath=filepath.Left(filepath.GetLength()-2);
  91. }
  92. void CBlockDialog::OnSelchangeCombo1()
  93. {
  94. m采用combo2.ResetContent();
  95. CString ca;
  96. m采用combo1.GetLBText(m采用combo1.GetCurSel(),ca);
  97. CString filepa=filepatha+ca;
  98. vector<CString>filename;
  99. Cfile::getFiles(filepa,filename);
  100. int i;
  101. for (i=0;i<filename.size()-2;i++)
  102. {
  103. m采用combo2.AddString(filename[i+2]);
  104. }
  105. if (m采用combo2.GetCount()>0)
  106. {
  107. m采用combo2.SetCurSel(0);
  108. m采用combo3.ResetContent();
  109. m采用combo2.GetWindowText(ca);
  110. filepa=filepa.Left(filepa.GetLength()-1);
  111. filepa+=ca;
  112. vector<CString>filenamea;
  113. Cfile::getFiles(filepa,filenamea);
  114. for (i=0;i<filenamea.size()-2;i++)
  115. {
  116. m采用combo3.AddString(filenamea[i+2]);
  117. }
  118. if (m采用combo3.GetCount()>0)
  119. {
  120. m采用combo3.SetCurSel(0);
  121. m采用list.ResetContent();
  122. m采用combo3.GetWindowText(ca);
  123. filepa=filepa.Left(filepa.GetLength()-1);
  124. filepa+=ca;
  125. AcDbDatabase *pDb=new AcDbDatabase(false);
  126. pDb->readDwgFile(filepa,采用SH采用DENYWR);
  127. AcDbObjectIdArray allEntIds = CDwgDatabaseUtil::GetAllEntityIds(NULL,pDb);
  128. for (int i=0;i<allEntIds.length();i++)
  129. {
  130. AcDbEntity *pEnt=NULL;
  131. if (acdbOpenObject(pEnt,allEntIds[i],AcDb::kForRead)==Acad::eOk)
  132. {
  133. if (pEnt->isKindOf(AcDbBlockReference::desc()))
  134. {
  135. AcDbBlockReference *pBlkRef=NULL;
  136. pBlkRef=AcDbBlockReference::cast(pEnt);
  137. pEnt->close();
  138. AcDbObjectId blkDefId=pBlkRef->blockTableRecord();
  139. pBlkRef->close();
  140. AcDbBlockTableRecord *pBlkDef=NULL;
  141. char *blkDefName;
  142. if (acdbOpenObject(pBlkDef,blkDefId,AcDb::kForRead)==Acad::eOk)
  143. {
  144. pBlkDef->getName(blkDefName);
  145. m采用list.AddString(blkDefName);
  146. pBlkDef->close();
  147. }
  148. }
  149. }
  150. }
  151. delete pDb;
  152. filepa="";
  153. }
  154. }
  155. }
  156. void CBlockDialog::OnSelchangeCombo2()
  157. {
  158. m采用combo3.ResetContent();
  159. CString ca;
  160. CString cb;
  161. m采用combo2.GetLBText(m采用combo2.GetCurSel(),ca);
  162. m采用combo1.GetWindowText(cb);
  163. CString filepa=filepatha+cb;
  164. filepa+="\";
  165. filepa=filepa+ca;
  166. vector<CString>filename;
  167. Cfile::getFiles(filepa,filename);
  168. for (int i=0;i<filename.size()-2;i++)
  169. {
  170. m采用combo3.AddString(filename[i+2]);
  171. }
  172. if (m采用combo3.GetCount()>0)
  173. {
  174. m采用combo3.SetCurSel(0);
  175. m采用list.ResetContent();
  176. m采用combo3.GetWindowText(ca);
  177. filepa=filepa.Left(filepa.GetLength()-1);
  178. filepa+=ca;
  179. AcDbDatabase *pDb=new AcDbDatabase();
  180. pDb->readDwgFile(filepa,采用SH采用DENYWR);
  181. AcDbObjectIdArray allEntIds = CDwgDatabaseUtil::GetAllEntityIds(NULL,pDb);
  182. for (i=0;i<allEntIds.length();i++)
  183. {
  184. AcDbEntity *pEnt=NULL;
  185. if (acdbOpenObject(pEnt,allEntIds[i],AcDb::kForRead)==Acad::eOk)
  186. {
  187. if (pEnt->isKindOf(AcDbBlockReference::desc()))
  188. {
  189. AcDbBlockReference *pBlkRef=NULL;
  190. pBlkRef=AcDbBlockReference::cast(pEnt);
  191. pEnt->close();
  192. AcDbObjectId blkDefId=pBlkRef->blockTableRecord();
  193. pBlkRef->close();
  194. AcDbBlockTableRecord *pBlkDef=NULL;
  195. char *blkDefName;
  196. if (acdbOpenObject(pBlkDef,blkDefId,AcDb::kForRead)==Acad::eOk)
  197. {
  198. pBlkDef->getName(blkDefName);
  199. m采用list.AddString(blkDefName);
  200. pBlkDef->close();
  201. }
  202. }
  203. }
  204. }
  205. delete pDb;
  206. filepa="";
  207. }
  208. }
  209. void CBlockDialog::OnSelchangeCombo3()
  210. {
  211. CString ca;
  212. CString cb;
  213. CString cc;
  214. m采用list.ResetContent();
  215. m采用combo1.GetWindowText(ca);
  216. m采用combo2.GetWindowText(cb);
  217. m采用combo3.GetLBText(m采用combo3.GetCurSel(),cc);
  218. CString filepa=filepatha+ca;
  219. filepa+="\";
  220. filepa=filepa+cb;
  221. filepa+="\";
  222. filepa=filepa+cc;
  223. AcDbDatabase *pDb=new AcDbDatabase();
  224. pDb->readDwgFile(filepa,采用SH采用DENYWR);
  225. AcDbObjectIdArray allEntIds = CDwgDatabaseUtil::GetAllEntityIds(NULL,pDb);
  226. for (int i=0;i<allEntIds.length();i++)
  227. {
  228. AcDbEntity *pEnt=NULL;
  229. if (acdbOpenObject(pEnt,allEntIds[i],AcDb::kForRead)==Acad::eOk)
  230. {
  231. if (pEnt->isKindOf(AcDbBlockReference::desc()))
  232. {
  233. AcDbBlockReference *pBlkRef=NULL;
  234. pBlkRef=AcDbBlockReference::cast(pEnt);
  235. pEnt->close();
  236. AcDbObjectId blkDefId=pBlkRef->blockTableRecord();
  237. pBlkRef->close();
  238. AcDbBlockTableRecord *pBlkDef=NULL;
  239. char *blkDefName;
  240. if (acdbOpenObject(pBlkDef,blkDefId,AcDb::kForRead)==Acad::eOk)
  241. {
  242. pBlkDef->getName(blkDefName);
  243. m采用list.AddString(blkDefName);
  244. pBlkDef->close();
  245. }
  246. }
  247. }
  248. }
  249. delete pDb;
  250. filepa="";
  251. }
  252. BOOL CBlockDialog::OnInitDialog()
  253. {
  254. CAcUiDialog::OnInitDialog();
  255. m采用edit.SetWindowText("E:\\ARX\\资源");
  256. m采用edit.GetWindowText(filepath);
  257. return TRUE; // return TRUE unless you set the focus to a control
  258. // EXCEPTION: OCX Property Pages should return FALSE
  259. }
  260. void CBlockDialog::OnKillfocusEdit1()
  261. {
  262. m采用edit.Convert();
  263. m采用edit.GetWindowText(filepath);
  264. }
  265. void CBlockDialog::OnSelchangeList3()
  266. {
  267. // TODO: Add your control notification handler code here
  268. CString blockName;
  269. m采用list.GetText(m采用list.GetCurSel(),blockName);
  270. CString ca,cb,cc;
  271. CString fileName;
  272. m采用combo1.GetWindowText(ca);
  273. m采用combo2.GetWindowText(cb);
  274. m采用combo3.GetWindowText(cc);
  275. fileName=filepatha+ca;
  276. fileName+="\";
  277. fileName=fileName+cb;
  278. fileName+="\";
  279. fileName=fileName+cc;
  280. AcDbDatabase *m采用pDb=new AcDbDatabase();
  281. m采用pDb->readDwgFile(fileName,采用SH采用DENYWR);
  282. AcDbBlockTable *pBlkTbl=NULL;
  283. m采用pDb->getSymbolTable(pBlkTbl,AcDb::kForRead);
  284. AcDbObjectId blkDefId;
  285. pBlkTbl->getAt(blockName,blkDefId);
  286. pBlkTbl->close();
  287. AcDbBlockReference *pBlkRef=new AcDbBlockReference(AcGePoint3d::kOrigin,blkDefId);
  288. AcDbDatabase *pDb=new AcDbDatabase();
  289. CDwgDatabaseUtil::PostToModelSpace(pBlkRef,pDb);
  290. m采用gsPreviewCtrl.SubclassDlgItem(IDC采用PREVIEW,this);
  291. m采用gsPreviewCtrl.Init(PreviewControlDLL.ModuleResourceInstance(),true);
  292. m采用gsPreviewCtrl.SetDatabase(pDb);
  293. }
  294. void CBlockDialog::OnButton()
  295. {
  296. CString blockName;
  297. m采用list.GetText(m采用list.GetCurSel(),blockName);
  298. CString ca,cb,cc;
  299. CString fileName;
  300. m采用combo1.GetWindowText(ca);
  301. m采用combo2.GetWindowText(cb);
  302. m采用combo3.GetWindowText(cc);
  303. fileName=filepatha+ca;
  304. fileName+="\";
  305. fileName=fileName+cb;
  306. fileName+="\";
  307. fileName=fileName+cc;
  308. AcDbDatabase *m采用pDb=new AcDbDatabase();
  309. m采用pDb->readDwgFile(fileName,采用SH采用DENYWR);
  310. AcDbBlockTable *pBlkTbl=NULL;
  311. m采用pDb->getSymbolTable(pBlkTbl,AcDb::kForRead);
  312. AcDbObjectId blkDefId;
  313. pBlkTbl->getAt(blockName,blkDefId);
  314. pBlkTbl->close();
  315. BeginEditorCommand();
  316. ads采用point pt;
  317. if (acedGetPoint(NULL,"\n输入一个点:",pt)!=RTNORM)
  318. {
  319. CompleteEditorCommand();
  320. }
  321. else
  322. {
  323. AcGePoint3d pt3d=asPnt3d(pt);
  324. AcDbBlockReference *pBlkRef=new AcDbBlockReference(pt3d,blkDefId);
  325. AcDbDatabase *pDb=acdbHostApplicationServices()->workingDatabase();
  326. CDwgDatabaseUtil::PostToModelSpace(pBlkRef,pDb);
  327. pBlkRef->close();
  328. CompleteEditorCommand();
  329. }
  330. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-1-4 13:04 , Processed in 0.134462 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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