📄 exam06b.cpp
字号:
#include <stdlib.h>
#include <rxobject.h>
#include <rxregsvc.h>
#include <aced.h>
#include <dbsymtb.h>
#include <dbapserv.h>
#include <adslib.h>
#include <dbxrecrd.h>
void createXrecord();
void listXrecord();
void printList(struct resbuf* pBuf);
void initApp();
void unloadApp();
extern "C"
AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*);
void
createXrecord()
{
AcDbDictionary *pNamedobj, *pDict;
acdbHostApplicationServices()->workingDatabase()
->getNamedObjectsDictionary(pNamedobj, AcDb::kForWrite);
if (pNamedobj->getAt("ASDK_DICT", (AcDbObject*&) pDict,
AcDb::kForWrite) == Acad::eKeyNotFound)
{
pDict = new AcDbDictionary;
AcDbObjectId DictId;
pNamedobj->setAt("ASDK_DICT", pDict, DictId);
}
pNamedobj->close();
AcDbXrecord *pXrec = new AcDbXrecord;
AcDbObjectId xrecObjId;
pDict->setAt("XREC1", pXrec, xrecObjId);
pDict->close();
struct resbuf *pHead;
ads_point testpt = {1.0, 2.0, 0.0};
pHead = acutBuildList(AcDb::kDxfText,
"This is a test Xrecord list",
AcDb::kDxfXCoord, testpt,
AcDb::kDxfReal, 3.14159,
AcDb::kDxfAngle, 3.14159,
AcDb::kDxfColor, 1,
AcDb::kDxfInt16, 180,
0);
pXrec->setFromRbChain(*pHead);
acutRelRb(pHead);
pXrec->close();
}
void
listXrecord()
{
AcDbDictionary *pNamedobj;
acdbHostApplicationServices()->workingDatabase()
->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead);
AcDbDictionary *pDict;
pNamedobj->getAt("ASDK_DICT", (AcDbObject*&)pDict,
AcDb::kForRead);
pNamedobj->close();
AcDbXrecord *pXrec;
pDict->getAt("XREC1", (AcDbObject*&) pXrec,
AcDb::kForRead);
pDict->close();
struct resbuf *pRbList;
pXrec->rbChain(&pRbList);
pXrec->close();
printList(pRbList);
acutRelRb(pRbList);
}
void
printList(struct resbuf* pBuf)
{
int rt, i;
char buf[133];
for (i = 0;pBuf != NULL;i++, pBuf = pBuf->rbnext) {
if (pBuf->restype < 0)
rt = pBuf->restype;
else if (pBuf->restype < 10)
rt = RTSTR;
else if (pBuf->restype < 38)
rt = RT3DPOINT;
else if (pBuf->restype < 60)
rt = RTREAL;
else if (pBuf->restype < 80)
rt = RTSHORT;
else if (pBuf->restype < 100)
rt = RTLONG;
else if (pBuf->restype < 106)
rt = RTSTR;
else if (pBuf->restype < 148)
rt = RTREAL;
else if (pBuf->restype < 290)
rt = RTSHORT;
else if (pBuf->restype < 320)
rt = RTSTR;
else if (pBuf->restype < 370)
rt = RTENAME;
else if (pBuf->restype < 999)
rt = RT3DPOINT;
else
rt = pBuf->restype;
switch (rt) {
case RTSHORT:
if (pBuf->restype == RTSHORT)
acutPrintf(
"RTSHORT : %d\n", pBuf->resval.rint);
else
acutPrintf("(%d . %d)\n", pBuf->restype,
pBuf->resval.rint);
break;
case RTREAL:
if (pBuf->restype == RTREAL)
acutPrintf(
"RTREAL : %0.3f\n", pBuf->resval.rreal);
else
acutPrintf("(%d . %0.3f)\n",
pBuf->restype, pBuf->resval.rreal);
break;
case RTSTR:
if (pBuf->restype == RTSTR)
acutPrintf(
"RTSTR : %s\n", pBuf->resval.rstring);
else
acutPrintf("(%d . \"%s\")\n",
pBuf->restype, pBuf->resval.rstring);
break;
case RT3DPOINT:
if (pBuf->restype == RT3DPOINT)
acutPrintf(
"RT3DPOINT : %0.3f, %0.3f, %0.3f\n",
pBuf->resval.rpoint[X],
pBuf->resval.rpoint[Y],
pBuf->resval.rpoint[Z]);
else
acutPrintf("(%d %0.3f %0.3f %0.3f)\n",
pBuf->restype,
pBuf->resval.rpoint[X],
pBuf->resval.rpoint[Y],
pBuf->resval.rpoint[Z]);
break;
case RTLONG:
acutPrintf("RTLONG : %dl\n", pBuf->resval.rlong);
break;
case -1:
case RTENAME:
acutPrintf("(%d . <Entity name: %8lx>)\n",
pBuf->restype, pBuf->resval.rlname[0]);
break;
case -3:
acutPrintf("(-3)\n");
}
if ((i == 23) && (pBuf->rbnext != NULL)) {
i = 0;
acedGetString(0,
"Press <ENTER> to continue...", buf);
}
}
return;
}
void
initApp()
{
acedRegCmds->addCommand("EXAM06B",
"CREATE", "CREATE", ACRX_CMD_MODAL,
createXrecord);
acedRegCmds->addCommand("EXAM06B",
"LISTXREC", "LISTXREC", ACRX_CMD_MODAL,
listXrecord);
}
void
unloadApp()
{
acedRegCmds->removeGroup("EXAM06B");
}
AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
switch (msg) {
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(appId);
acrxDynamicLinker->registerAppMDIAware(appId);
initApp();
break;
case AcRx::kUnloadAppMsg:
unloadApp();
}
return AcRx::kRetOK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -