找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 86|回复: 0

如何设置扩展字典的数据AcDbDictionary

[复制链接]

1

主题

0

回帖

55

积分

管理员

积分
55
发表于 2024-9-25 13:32:42 | 显示全部楼层 |阅读模式
  1. //扩展字典xtsndict
  2. // (C) Copyright 1996-2006 by Autodesk, Inc.
  3. //
  4. // Permission to use, copy, modify, and distribute this software in
  5. // object code form for any purpose and without fee is hereby granted,
  6. // provided that the above copyright notice appears in all copies and
  7. // that both that copyright notice and the limited warranty and
  8. // restricted rights notice below appear in all supporting
  9. // documentation.
  10. //
  11. // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
  12. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
  13. // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  14. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
  15. // UNINTERRUPTED OR ERROR FREE.
  16. //
  17. // Use, duplication, or disclosure by the U.S. Government is subject to
  18. // restrictions set forth in FAR 52.227-19 (Commercial Computer
  19. // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
  20. // (Rights in Technical Data and Computer Software), as applicable.
  21. //
  22. // Description:
  23. //
  24. // This program demonstrates using extension dictionaries.
  25. // Two commands are defined in this program:  CREATE, and
  26. // LISTXREC.
  27. //
  28. // The CREATE command calls the function createXrecord()
  29. // which instantiates an xrecord object and adds it to the
  30. // extension dictionary of a user selected object.
  31. //
  32. // The LISTXREC command calls the listXrecord() function
  33. // which opens the extension dictionary of a user selected
  34. // object, looks for the xrecord created by the CREATE
  35. // command and then calls the printList() function to print
  36. // out the data stored in the xrecord.
  37. #if defined(_DEBUG) && !defined(AC_FULL_DEBUG)
  38. #error _DEBUG should not be defined except in internal Adesk debug builds
  39. #endif
  40. #include <stdlib.h>
  41. #include <rxobject.h>
  42. #include <rxregsvc.h>
  43. #include <aced.h>
  44. #include <dbsymtb.h>
  45. #include <adslib.h>
  46. #include <dbxrecrd.h>
  47. #include <acestext.h>
  48. #include "tchar.h"
  49. void                        createXrecord();
  50. void                        listXrecord();
  51. AcDbObject*                 selectObject(AcDb::OpenMode);
  52. void                        printList(struct resbuf* pBuf);
  53. void                        initApp();
  54. void                        unloadApp();
  55. extern "C"
  56. AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*);
  57. // The createXrecord() functions creates an xrecord object,
  58. // adds data to it, and then adds the xrecord to the extension
  59. // dictionary of a user selected object.
  60. //
  61. // THE FOLLOWING CODE APPEARS IN THE SDK DOCUMENT.
  62. //
  63. void
  64. createXrecord()
  65. {
  66.     AcDbXrecord *pXrec = new AcDbXrecord;
  67.     AcDbObject *pObj;
  68.     AcDbObjectId dictObjId, xrecObjId;
  69.     AcDbDictionary* pDict;
  70.     pObj = selectObject(AcDb::kForWrite);
  71.     if (pObj == NULL) {
  72.         return;
  73.     }
  74.     // Try to create an extension dictionary for this
  75.     // object.  If the extension dictionary already exists,
  76.     // this will be a no-op.
  77.     //
  78.     pObj->createExtensionDictionary();
  79.     // Get the object ID of the extension dictionary for the
  80.     // selected object.
  81.     //
  82.     dictObjId = pObj->extensionDictionary();
  83.     pObj->close();
  84.     // Open the extension dictionary and add the new
  85.     // xrecord to it.
  86.     //
  87.     acdbOpenObject(pDict, dictObjId, AcDb::kForWrite);
  88.     pDict->setAt(_T("ASDK_XREC1"), pXrec, xrecObjId);
  89.     pDict->close();
  90.     // Create a resbuf list to add to the xrecord.
  91.     //
  92.     struct resbuf* head;
  93.     ads_point testpt = {1.0, 2.0, 0.0};
  94.     head = acutBuildList(AcDb::kDxfText,
  95.         _T("This is a test Xrecord list"),
  96.         AcDb::kDxfXCoord, testpt,
  97.         AcDb::kDxfReal, 3.14159,
  98.         AcDb::kDxfAngle, 3.14159,
  99.         AcDb::kDxfColor, 1,
  100.         AcDb::kDxfInt16, 180,
  101.         0);
  102.     // Add the data list to the xrecord.  Notice that this
  103.     // member function takes a reference to a resbuf NOT a
  104.     // pointer to a resbuf, so you must dereference the
  105.     // pointer before sending it.
  106.     //
  107.     pXrec->setFromRbChain(*head);
  108.     pXrec->close();
  109.     acutRelRb(head);
  110. }
  111. // The listxrecord() functions gets the xrecord associated with the
  112. // key "ASDK_XREC1" and lists out its contents by passing the resbuf
  113. // list to the function printList().
  114. //
  115. void
  116. listXrecord()
  117. {
  118.     AcDbObject *pObj;
  119.     AcDbXrecord *pXrec;
  120.     AcDbObjectId dictObjId;
  121.     AcDbDictionary *pDict;
  122.     pObj = selectObject(AcDb::kForRead);
  123.     if (pObj == NULL) {
  124.         return;
  125.     }
  126.     // Get the object ID of the object's extension dictionary.
  127.     //
  128.     dictObjId = pObj->extensionDictionary();
  129.     pObj->close();
  130.     // Open the extension dictionary and get the xrecord
  131.     // associated with the key ASDK_XREC1.
  132.     //
  133.     acdbOpenObject(pDict, dictObjId, AcDb::kForRead);
  134.     pDict->getAt(_T("ASDK_XREC1"), (AcDbObject*&)pXrec,
  135.         AcDb::kForRead);
  136.     pDict->close();
  137.     // Get the xrecord's data list and then close the xrecord.
  138.     //
  139.     struct resbuf *pRbList;
  140.     pXrec->rbChain(&pRbList);
  141.     pXrec->close();
  142.     printList(pRbList);
  143.     acutRelRb(pRbList);
  144. }
  145. // END CODE APPEARING IN SDK DOCUMENT.
  146. // The selectObject() function prompts the user to select an
  147. // entity or enter an object's handle.  It then proceeds to
  148. // open the object/entity and return a pointer to it.
  149. //
  150. AcDbObject*
  151. selectObject(AcDb::OpenMode openMode)
  152. {
  153.     ads_name en;
  154.     ads_point pt;
  155.     TCHAR handleStr[132];
  156.     AcDbObjectId eId;
  157.     Acad::ErrorStatus retStat;
  158.     int ss;
  159.     // Allow user to either pick an entity,
  160.     // or type in the object handle.
  161.     //
  162.     acedInitGet(RSG_OTHER, _T("Handle _Handle"));
  163.     ss = acedEntSel(_T("\nSelect an Entity or enter")
  164.         _T(" 'H' to enter its handle:  "), en, pt);
  165.     switch (ss) {
  166.     case RTNORM:   // got it!
  167.         break;
  168.     case RTKWORD:
  169.         if ((acedGetString(Adesk::kFalse,
  170.             _T("Enter Valid Object Handle: "),
  171.             handleStr) == RTNORM)
  172.             && (acdbHandEnt(handleStr, en) == RTNORM))
  173.         {
  174.             break;
  175.         }
  176.     // Fall-through intentional
  177.     //
  178.     default:
  179.         acutPrintf(_T("Nothing Selected, Return Code==%d\n"),
  180.             ss);
  181.         return NULL;
  182.     }
  183.     // Now, exchange the ads_name for the object Id...
  184.     //
  185.     retStat = acdbGetObjectId(eId, en);
  186.     if (retStat != Acad::eOk) {
  187.         acutPrintf(_T("\nacdbGetObjectId failed"));
  188.         acutPrintf(_T("\nen==(%lx,%lx), retStat==%d\n"),
  189.             en[0], en[1], eId);
  190.         return NULL;
  191.     }
  192.     AcDbObject* pObj;
  193.     if ((retStat = acdbOpenObject(pObj, eId, openMode))
  194.         != Acad::eOk)
  195.     {
  196.         acutPrintf(_T("acdbOpenEntity failed: ename:")
  197.             _T("(%lx,%lx), mode:%d retStat:%d"), en[0],
  198.             en[1], openMode, retStat);
  199.         return NULL;
  200.     }
  201.     return pObj;
  202. }
  203. // The printList() function takes a linked list of resbufs
  204. // as an argument.  Walks the list printing out the restypes
  205. // and resval values one set per line.
  206. //
  207. void
  208. printList(struct resbuf* pBuf)
  209. {
  210.     int rt, i;
  211.     TCHAR buf[133];
  212.     for (i = 0;pBuf != NULL;i++, pBuf = pBuf->rbnext) {
  213.         if (pBuf->restype < 0)
  214.             rt = pBuf->restype;
  215.         else if (pBuf->restype < 10)
  216.             rt = RTSTR;
  217.         else if (pBuf->restype < 38)
  218.             rt = RT3DPOINT;
  219.         else if (pBuf->restype < 60)
  220.             rt = RTREAL;
  221.         else if (pBuf->restype < 80)
  222.             rt = RTSHORT;
  223.         else if (pBuf->restype < 100)
  224.             rt = RTLONG;
  225.         else if (pBuf->restype < 106)
  226.             rt = RTSTR;
  227.         else if (pBuf->restype < 148)
  228.             rt = RTREAL;
  229.         else if (pBuf->restype < 290)
  230.             rt = RTSHORT;
  231.         else if (pBuf->restype < 330)
  232.             rt = RTSTR;
  233.         else if (pBuf->restype < 370)
  234.             rt = RTENAME;
  235.         else if (pBuf->restype < 999)
  236.             rt = RT3DPOINT;
  237.         else
  238.             rt = pBuf->restype;
  239.         switch (rt) {
  240.         case RTSHORT:
  241.             if (pBuf->restype == RTSHORT)
  242.                 acutPrintf(_T("RTSHORT : %d\n"),
  243.                     pBuf->resval.rint);
  244.             else
  245.                 acutPrintf(_T("(%d . %d)\n"), pBuf->restype,
  246.                     pBuf->resval.rint);
  247.             break;
  248.         case RTREAL:
  249.             if (pBuf->restype == RTREAL)
  250.                 acutPrintf(_T("RTREAL : %0.3f\n"),
  251.                     pBuf->resval.rreal);
  252.             else
  253.                 acutPrintf(_T("(%d . %0.3f)\n"), pBuf->restype,
  254.                     pBuf->resval.rreal);
  255.             break;
  256.         case RTSTR:
  257.             if (pBuf->restype == RTSTR)
  258.                 acutPrintf(_T("RTSTR : %s\n"),
  259.                    pBuf->resval.rstring);
  260.             else
  261.                 acutPrintf(_T("(%d . "%s")\n"), pBuf->restype,
  262.                     pBuf->resval.rstring);
  263.             break;
  264.         case RT3DPOINT:
  265.             if (pBuf->restype == RT3DPOINT)
  266.                 acutPrintf(
  267.                 _T("RT3DPOINT : %0.3f, %0.3f, %0.3f\n"),
  268.                     pBuf->resval.rpoint[X],
  269.                     pBuf->resval.rpoint[Y],
  270.                     pBuf->resval.rpoint[Z]);
  271.             else
  272.                 acutPrintf(
  273.                    _T("(%d %0.3f %0.3f %0.3f)\n"),
  274.                     pBuf->restype,
  275.                     pBuf->resval.rpoint[X],
  276.                     pBuf->resval.rpoint[Y],
  277.                     pBuf->resval.rpoint[Z]);
  278.             break;
  279.         case RTLONG:
  280.             acutPrintf(_T("RTLONG : %dl\n"),
  281.                 pBuf->resval.rlong);
  282.             break;
  283.         case -1:
  284.         case RTENAME:
  285.             acutPrintf(_T("(%d . <Entity name: %8lx>)\n"),
  286.                 pBuf->restype, pBuf->resval.rlname[0]);
  287.             break;
  288.         case -3:
  289.             acutPrintf(_T("(-3)\n"));
  290.         }
  291.         if ((i == 23) && (pBuf->rbnext != NULL)) {
  292.             i = 0;
  293.             acedGetString(0,
  294.                 _T("Press <ENTER> to continue..."), buf);
  295.         }
  296.     }
  297.     return;
  298. }
  299. // Initialization function called in acrxEntryPoint
  300. // during the kInitAppMsg case.  This is where commands
  301. // are added to the AcEd command stack.
  302. //
  303. void
  304. initApp()
  305. {
  306.     acedRegCmds->addCommand(_T("ASDK_EXTDICT_COMMANDS"),
  307.         _T("ASDK_CREATE"), _T("CREATE"), ACRX_CMD_MODAL,
  308.         createXrecord);
  309.     acedRegCmds->addCommand(_T("ASDK_EXTDICT_COMMANDS"),
  310.         _T("ASDK_LISTXREC"), _T("LISTXREC"), ACRX_CMD_MODAL,
  311.         listXrecord);
  312. }
  313. // Clean up function called in acrxEntryPoint during the
  314. // kUnloadAppMsg case.  This app's command group is
  315. // removed from the AcEd command stack.
  316. //
  317. void
  318. unloadApp()
  319. {
  320.     acedRegCmds->removeGroup(_T("ASDK_EXTDICT_COMMANDS"));
  321. }
  322. // ARX entry point.
  323. //
  324. AcRx::AppRetCode
  325. acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
  326. {
  327.     switch (msg) {
  328.     case AcRx::kInitAppMsg:
  329.         acrxDynamicLinker->unlockApplication(appId);
  330.                 acrxDynamicLinker->registerAppMDIAware(appId);
  331.         initApp();
  332.         break;
  333.     case AcRx::kUnloadAppMsg:
  334.         unloadApp();
  335.     }
  336.     return AcRx::kRetOK;
  337. }
复制代码

 

 

 

 

如何设置扩展字典的数据AcDbDictionary
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-2-5 19:59 , Processed in 0.073091 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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