/********resbuf 结果缓冲区示例********/
//1. 单个的 resbuf
//1.1 单个的 resbuf ,不需管理内存
struct resbuf rb11;
acedGetVar(_RXST("TILEMODE"), &rb11);
AcString xSpace;
if (rb11.resval.rint == 1) // 当前工作空间是模型空间
xSpace = ACDB_MODEL_SPACE;
else // 当前工作空间是图纸空间
xSpace = ACDB_PAPER_SPACE;
acutPrintf(_RXST("\n测试 resbuf ————当前工作空间为:%s"), xSpace);
//1.2 单个的 resbuf* ,必须管理内存
struct resbuf *rb12 = acutNewRb(RTSHORT);
acedGetVar(_RXST("TILEMODE"), rb12);
if (rb12->resval.rint == 1)
xSpace = ACDB_MODEL_SPACE;
else
xSpace = ACDB_PAPER_SPACE;
acutPrintf(_RXST("\n单个的 resbuf* 测试————当前工作空间为:%s"), xSpace);
acutRelRb(rb12); //调用acutRelRb()函数释放内存
acutPrintf(_RXST("\n"));
//2. 链表型 resbuf ,需手工管理内存(类型码建议使用DXF组代码,这可以使类型更丰富)
AcGePoint3d pt;
//2.1 创建链表(一次创建)
struct resbuf* rb21 = acutBuildList(kDxfRegAppName, _RXST("WJC"),
AcDb::kDxfXTextString, _RXST("Demo"),
AcDb::kDxfXReal, 3.14169265,
AcDb::kDxfInt32, 17,
AcDb::kDxfXdWorldXCoord, asDblArray(AcGePoint3d(1.0, 2.0, 3.0)),
RTNONE);
//读取
struct resbuf* rb21t = rb21; //从链表第一个位置开始读取
while (rb21t)
{
switch (rb21t->restype) // 结果类型要匹配
{
case AcDb::kDxfRegAppName:
acutPrintf(_RXST("\n单链 resbuf* 测试————注册程序名:%s"), rb21t->resval.rstring);
break;
case AcDb::kDxfXReal: // 多个相同类型的结果可自定义顺序变量加以区分
acutPrintf(_RXST("\n单链 resbuf* 测试————实数π:%f"), rb21t->resval.rreal);
break;
case AcDb::kDxfInt32:
acutPrintf(_RXST("\n单链 resbuf* 测试————整数:%d"), rb21t->resval.rint);
break;
case AcDb::kDxfXTextString:
acutPrintf(_RXST("\n单链 resbuf* 测试————字符串:%s"), rb21t->resval.rstring);
break;
case AcDb::kDxfXdWorldXCoord:
pt = asPnt3d(rb21t->resval.rpoint);
acutPrintf(_RXST("\n单链 resbuf* 测试————坐标:x=%f, y=%f, z=%f"), pt.x, pt.y, pt.z);
break;
default:
break;
}
rb21t = rb21t->rbnext; // 读取下一条
}
acutRelRb(rb21);//释放内存
acutPrintf(_RXST("\n"));
//2.2 创建链表(多次添加)
struct resbuf* rb22 = acutBuildList(kDxfRegAppName, _RXST("WJC"), RTNONE);
struct resbuf* rb22t = rb22;
rb22t->rbnext = acutBuildList(AcDb::kDxfXTextString, _RXST("Demo"), RTNONE);
rb22t = rb22t->rbnext; //调整链表当前位置
rb22t->rbnext = acutBuildList(AcDb::kDxfXReal, 3.14169265, RTNONE);
rb22t = rb22t->rbnext;
rb22t->rbnext = acutBuildList(AcDb::kDxfInt32, 17, RTNONE);
rb22t = rb22t->rbnext;
rb22t->rbnext = acutBuildList(AcDb::kDxfXdWorldXCoord, asDblArray(AcGePoint3d(1.0, 2.0, 3.0)), RTNONE);
rb22t = rb22t->rbnext;
rb22t->rbnext = acutBuildList(RTNONE);
//读取
rb22t = rb22; //从链表第一个位置开始读取
while (rb22t)
{
switch (rb22t->restype)
{
case AcDb::kDxfRegAppName:
acutPrintf(_RXST("\n多链 resbuf* 测试————注册程序名:%s"), rb22t->resval.rstring);
break;
case AcDb::kDxfXReal:
acutPrintf(_RXST("\n多链 resbuf* 测试————实数π:%f"), rb22t->resval.rreal);
break;
case AcDb::kDxfInt32:
acutPrintf(_RXST("\n多链 resbuf* 测试————整数:%d"), rb22t->resval.rint);
break;
case AcDb::kDxfXTextString:
acutPrintf(_RXST("\n多链 resbuf* 测试————字符串:%s"), rb22t->resval.rstring);
break;
case AcDb::kDxfXdWorldXCoord:
pt = asPnt3d(rb22t->resval.rpoint);
acutPrintf(_RXST("\n多链 resbuf* 测试————坐标:x=%f, y=%f, z=%f"), pt.x, pt.y, pt.z);
break;
default:
break;
}
rb22t = rb22t->rbnext; // 读取下一条
}
acutRelRb(rb22); // 释放内存
结果缓冲区 resbuf 常用用法总结
最新推荐文章于 2023-05-14 11:42:32 发布