天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 16|回复: 0

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

[复制链接]
  • TA的每日心情
    开心
    前天 08:01
  • 签到天数: 82 天

    [LV.6]常住居民II

    1589

    主题

    204

    回帖

    214748万

    积分

    管理员

    积分
    2147483647
    发表于 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. }
    复制代码

     

     

     

     

    获取任意路径Dwg文件内所有块在控件中显示并能选择插入当前模型空间
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网_中国空间膜结构协会

    GMT+8, 2024-5-18 17:51 , Processed in 0.058553 second(s), 22 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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