找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 818|回复: 3

[求助]:如何写程序读取CAD数据库中的属性值

[复制链接]
发表于 2006-1-17 16:31:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
如下边的图,怎么样读取DM01,MD02a里面的数据属性值.里面保存的是图纸的作成年月日,名称,绘图单位等信息,分写在DM01a,DM02a,DM02b,DM02和DM02DEF01中.请问怎么把这么属性读出来.请大家帮忙想想.
下图是我从晓东CAD论坛上下载了"CAD数据库查看器"程序.

C:\Documents and Settings\lihongbo\My Documents\My Pictures\kkkk.jpg

附件:   TEST.rar中有DWG文件和CAD数据查看器程序.
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2006-1-17 19:16:38 | 显示全部楼层

  1.   [FONT=courier new]
  2. void
  3. createXrecord()
  4. {
  5.     AcDbDictionary *pNamedobj, *pDict;
  6.     acdbHostApplicationServices()->workingDatabase()
  7.         ->getNamedObjectsDictionary(pNamedobj, AcDb::kForWrite);

  8.     // Check to see if the dictionary we want to create is
  9.     // already present. If not, then create it and add
  10.     // it to the named object dictionary.
  11.     //
  12.     if (pNamedobj->getAt("ASDK_DICT", (AcDbObject*&) pDict,
  13.         AcDb::kForWrite) == Acad::eKeyNotFound)
  14.     {
  15.         pDict = new AcDbDictionary;
  16.         AcDbObjectId DictId;
  17.         pNamedobj->setAt("ASDK_DICT", pDict, DictId);
  18.     }
  19.     pNamedobj->close();

  20.     // Add a new xrecord to the ASDK_DICT dictionary.
  21.     //
  22.     AcDbXrecord *pXrec = new AcDbXrecord;
  23.     AcDbObjectId xrecObjId;
  24.     pDict->setAt("XREC1", pXrec, xrecObjId);
  25.     pDict->close();

  26.     // Create a resbuf list to add to the xrecord.
  27.     //
  28.     struct resbuf *pHead;
  29.     ads_point testpt = {1.0, 2.0, 0.0};
  30.     pHead = acutBuildList(AcDb::kDxfText,
  31.         "This is a test Xrecord list",
  32.         AcDb::kDxfXCoord, testpt,
  33.         AcDb::kDxfReal, 3.14159,
  34.         AcDb::kDxfAngle, 3.14159,
  35.         AcDb::kDxfColor, 1,
  36.         AcDb::kDxfInt16, 180,
  37.         0);

  38.     // Add the data list to the xrecord.  Notice that this
  39.     // member function takes a reference to resbuf, NOT a
  40.     // pointer to resbuf, so you must dereference the
  41.     // pointer before sending it.
  42.     //
  43.     pXrec->setFromRbChain(*pHead);
  44.     acutRelRb(pHead);
  45.     pXrec->close();
  46. }

  47. // Gets the xrecord associated with the key XREC1 and
  48. // lists out its contents by passing the resbuf list to the
  49. // function printList.
  50. //
  51. void
  52. listXrecord()
  53. {
  54.     AcDbDictionary *pNamedobj;
  55.     acdbHostApplicationServices()->workingDatabase()
  56.         ->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead);

  57.     // Get the dictionary object associated with the key ASDK_DICT.
  58.     //
  59.     AcDbDictionary *pDict;
  60.     pNamedobj->getAt("ASDK_DICT", (AcDbObject*&)pDict,
  61.         AcDb::kForRead);
  62.     pNamedobj->close();

  63.     // Get the xrecord associated with the key XREC1.
  64.     //
  65.     AcDbXrecord *pXrec;
  66.     pDict->getAt("XREC1", (AcDbObject*&) pXrec,
  67.         AcDb::kForRead);
  68.     pDict->close();

  69.     struct resbuf *pRbList;
  70.     pXrec->rbChain(&pRbList);
  71.     pXrec->close();

  72.     printList(pRbList);
  73.     acutRelRb(pRbList);
  74. }

  75.   [/FONT]
复制代码




上面代码仅供参考 :(
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2006-1-18 13:03:23 | 显示全部楼层
You are welcome for providing thus good source code,especially no meney
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-1-18 14:22:06 | 显示全部楼层
帮忙修改以下程序代码.

  1.   [FONT=courier new]
  2. #include <stdlib.h>
  3. #include <rxobject.h>
  4. #include <rxregsvc.h>
  5. #include <aced.h>
  6. #include <dbsymtb.h>
  7. #include <adslib.h>
  8. #include <dbxrecrd.h>
  9. #include <acestext.h>

  10. void                        createXrecord ();
  11. void                        listXrecord ();
  12. AcDbObject*                 selectObject(AcDb::OpenMode);
  13. void                        printList(struct resbuf* pBuf);
  14. void                        initApp();
  15. void                        unloadApp();
  16. extern "C"
  17. AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*);


  18. // The createXrecord() functions creates an xrecord object,
  19. // adds data to it, and then adds the xrecord to the extension
  20. // dictionary of a user selected object.
  21. //
  22. // THE FOLLOWING CODE APPEARS IN THE SDK DOCUMENT.
  23. //
  24. void
  25. createXrecord()
  26. {
  27.     AcDbXrecord *pXrec = new AcDbXrecord;
  28.     AcDbObject *pObj;
  29.     AcDbObjectId dictObjId, xrecObjId;
  30.     AcDbDictionary* pDict;

  31.     pObj = selectObject(AcDb::kForWrite);
  32.     if (pObj == NULL) {
  33.         return;
  34.     }

  35.     // Try to create an extension dictionary for this
  36.     // object.  If the extension dictionary already exists,
  37.     // this will be a no-op.
  38.     //
  39.     pObj->createExtensionDictionary();

  40.     // Get the object ID of the extension dictionary for the
  41.     // selected object.
  42.     //
  43.     dictObjId = pObj->extensionDictionary();
  44.     pObj->close();

  45.     // Open the extension dictionary and add the new
  46.     // xrecord to it.
  47.     //
  48.     acdbOpenObject(pDict, dictObjId, AcDb::kForWrite);
  49.     pDict->setAt("ASDK_XREC1", pXrec, xrecObjId);
  50.     pDict->close();

  51.     // Create a resbuf list to add to the xrecord.
  52.     //
  53.     struct resbuf* head;
  54.     ads_point testpt = {1.0, 2.0, 0.0};
  55.     head = acutBuildList(AcDb::kDxfText,
  56.         "This is a test Xrecord list",
  57.         AcDb::kDxfXCoord, testpt,
  58.         AcDb::kDxfReal, 3.14159,
  59.         AcDb::kDxfAngle, 3.14159,
  60.         AcDb::kDxfColor, 1,
  61.         AcDb::kDxfInt16, 180,
  62.         0);

  63.     // Add the data list to the xrecord.  Notice that this
  64.     // member function takes a reference to a resbuf NOT a
  65.     // pointer to a resbuf, so you must dereference the
  66.     // pointer before sending it.
  67.     //
  68.     pXrec->setFromRbChain(*head);
  69.     pXrec->close();
  70.     acutRelRb(head);
  71. }


  72. // The listxrecord() functions gets the xrecord associated with the
  73. // key "ASDK_XREC1" and lists out its contents by passing the resbuf
  74. // list to the function printList().
  75. //
  76. void
  77. listXrecord()
  78. {
  79.     AcDbObject *pObj;
  80.     AcDbXrecord *pXrec;
  81.     AcDbObjectId dictObjId;
  82.     AcDbDictionary *pDict;

  83.     pObj = selectObject(AcDb::kForRead);
  84.     if (pObj == NULL) {
  85.         return;
  86.     }
  87.     // Get the object ID of the object's extension dictionary.
  88.     //
  89.     dictObjId = pObj->extensionDictionary();
  90.     pObj->close();

  91.     // Open the extension dictionary and get the xrecord
  92.     // associated with the key ASDK_XREC1.
  93.     //
  94.     acdbOpenObject(pDict, dictObjId, AcDb::kForRead);
  95.     pDict->getAt("ASDK_XREC1", (AcDbObject*&)pXrec,
  96.         AcDb::kForRead);
  97.     pDict->close();

  98.     // Get the xrecord's data list and then close the xrecord.
  99.     //
  100.     struct resbuf *pRbList;
  101.     pXrec->rbChain(&pRbList);
  102.     pXrec->close();

  103.     printList(pRbList);
  104.     acutRelRb(pRbList);
  105. }

  106. // END CODE APPEARING IN SDK DOCUMENT.

  107. // The selectObject() function prompts the user to select an
  108. // entity or enter an object's handle.  It then proceeds to
  109. // open the object/entity and return a pointer to it.
  110. //
  111. AcDbObject*
  112. selectObject(AcDb::OpenMode openMode)
  113. {
  114.     ads_name en;
  115.     ads_point pt;
  116.     char handleStr[132];
  117.     AcDbObjectId eId;

  118.     Acad::ErrorStatus retStat;
  119.     int ss;

  120.     // Allow user to either pick an entity,
  121.     // or type in the object handle.
  122.     //
  123.     acedInitGet(RSG_OTHER, "_Handle Handle");
  124.     ss = acedEntSel("\nSelect an Entity or enter"
  125.         " 'H' to enter its handle:  ", en, pt);

  126.     switch (ss) {
  127.     case RTNORM:   // got it!
  128.         break;
  129.     case RTKWORD:
  130.         if ((acedGetString(Adesk::kFalse,
  131.             "Enter Valid Object Handle: ",
  132.             handleStr) == RTNORM)
  133.             && (acdbHandEnt(handleStr, en) == RTNORM))
  134.         {
  135.             break;
  136.         }
  137.     // Fall-through intentional
  138.     //
  139.     default:
  140.         acutPrintf("Nothing Selected, Return Code==%d\n",
  141.             ss);
  142.         return NULL;
  143.     }

  144.     // Now, exchange the ads_name for the object Id...
  145.     //
  146.     retStat = acdbGetObjectId(eId, en);
  147.     if (retStat != Acad::eOk) {
  148.         acutPrintf("\nacdbGetObjectId failed");
  149.         acutPrintf("\nen==(%lx,%lx), retStat==%d\n",
  150.             en[0], en[1], eId);
  151.         return NULL;
  152.     }

  153.     AcDbObject* pObj;

  154.     if ((retStat = acdbOpenObject(pObj, eId, openMode))
  155.         != Acad::eOk)
  156.     {
  157.         acutPrintf("acdbOpenEntity failed: ename:"
  158.             "(%lx,%lx), mode:%d retStat:%d", en[0],
  159.             en[1], openMode, retStat);
  160.         return NULL;
  161.     }
  162.     return pObj;
  163. }


  164. // The printList() function takes a linked list of resbufs
  165. // as an argument.  Walks the list printing out the restypes
  166. // and resval values one set per line.
  167. //
  168. void
  169. printList(struct resbuf* pBuf)
  170. {
  171.     int rt, i;
  172.     char buf[133];

  173.     for (i = 0;pBuf != NULL;i++, pBuf = pBuf->rbnext) {
  174.         if (pBuf->restype < 0)
  175.             rt = pBuf->restype;
  176.         else if (pBuf->restype < 10)
  177.             rt = RTSTR;
  178.         else if (pBuf->restype < 38)
  179.             rt = RT3DPOINT;
  180.         else if (pBuf->restype < 60)
  181.             rt = RTREAL;
  182.         else if (pBuf->restype < 80)
  183.             rt = RTSHORT;
  184.         else if (pBuf->restype < 100)
  185.             rt = RTLONG;
  186.         else if (pBuf->restype < 106)
  187.             rt = RTSTR;
  188.         else if (pBuf->restype < 148)
  189.             rt = RTREAL;
  190.         else if (pBuf->restype < 290)
  191.             rt = RTSHORT;
  192.         else if (pBuf->restype < 320)
  193.             rt = RTSTR;
  194.         else if (pBuf->restype < 370)
  195.             rt = RTENAME;
  196.         else if (pBuf->restype < 999)
  197.             rt = RT3DPOINT;
  198.         else
  199.             rt = pBuf->restype;

  200.         switch (rt) {
  201.         case RTSHORT:
  202.             if (pBuf->restype == RTSHORT)
  203.                 acutPrintf("RTSHORT : %d\n",
  204.                     pBuf->resval.rint);
  205.             else
  206.                 acutPrintf("(%d . %d)\n", pBuf->restype,
  207.                     pBuf->resval.rint);
  208.             break;
  209.         case RTREAL:
  210.             if (pBuf->restype == RTREAL)
  211.                 acutPrintf("RTREAL : %0.3f\n",
  212.                     pBuf->resval.rreal);
  213.             else
  214.                 acutPrintf("(%d . %0.3f)\n", pBuf->restype,
  215.                     pBuf->resval.rreal);
  216.             break;
  217.         case RTSTR:
  218.             if (pBuf->restype == RTSTR)
  219.                 acutPrintf("RTSTR : %s\n",
  220.                    pBuf->resval.rstring);
  221.             else
  222.                 acutPrintf("(%d . "%s")\n", pBuf->restype,
  223.                     pBuf->resval.rstring);
  224.             break;
  225.         case RT3DPOINT:
  226.             if (pBuf->restype == RT3DPOINT)
  227.                 acutPrintf(
  228.                     "RT3DPOINT : %0.3f, %0.3f, %0.3f\n",
  229.                     pBuf->resval.rpoint[X],
  230.                     pBuf->resval.rpoint[Y],
  231.                     pBuf->resval.rpoint[Z]);
  232.             else
  233.                 acutPrintf(
  234.                    "(%d %0.3f %0.3f %0.3f)\n",
  235.                     pBuf->restype,
  236.                     pBuf->resval.rpoint[X],
  237.                     pBuf->resval.rpoint[Y],
  238.                     pBuf->resval.rpoint[Z]);
  239.             break;
  240.         case RTLONG:
  241.             acutPrintf("RTLONG : %dl\n",
  242.                 pBuf->resval.rlong);
  243.             break;
  244.         case -1:
  245.         case RTENAME:
  246.             acutPrintf("(%d . <Entity name: %8lx>)\n",
  247.                 pBuf->restype, pBuf->resval.rlname[0]);
  248.             break;
  249.         case -3:
  250.             acutPrintf("(-3)\n");
  251.         }

  252.         if ((i == 23) && (pBuf->rbnext != NULL)) {
  253.             i = 0;
  254.             acedGetString(0,
  255.                 "Press <ENTER> to continue...", buf);
  256.         }
  257.     }
  258.     return;
  259. }


  260. // Initialization function called in acrxEntryPoint
  261. // during the kInitAppMsg case.  This is where commands
  262. // are added to the AcEd command stack.
  263. //
  264. void
  265. initApp()
  266. {
  267.     acedRegCmds->addCommand("ASDK_EXTDICT_COMMANDS",
  268.         "ASDK_CREATE", "CREATE", ACRX_CMD_MODAL,
  269.         createXrecord);
  270.     acedRegCmds->addCommand("ASDK_EXTDICT_COMMANDS",
  271.         "ASDK_LISTXREC", "LISTXREC", ACRX_CMD_MODAL,
  272.         listXrecord);
  273. }

  274. // Clean up function called in acrxEntryPoint during the
  275. // kUnloadAppMsg case.  This app's command group is
  276. // removed from the AcEd command stack.
  277. //
  278. void
  279. unloadApp()
  280. {
  281.     acedRegCmds->removeGroup("ASDK_EXTDICT_COMMANDS");
  282. }


  283. // ARX entry point.
  284. //
  285. AcRx::AppRetCode
  286. acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
  287. {
  288.     switch (msg) {
  289.     case AcRx::kInitAppMsg:
  290.         acrxDynamicLinker->unlockApplication(appId);
  291.                 acrxDynamicLinker->registerAppMDIAware(appId);
  292.         initApp();
  293.         break;
  294.     case AcRx::kUnloadAppMsg:
  295.         unloadApp();
  296.     }
  297.     return AcRx::kRetOK;
  298. }

  299.   [/FONT]
复制代码
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-15 16:49 , Processed in 0.209699 second(s), 37 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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