如何修改OdResBufPtr变量?
大家好我尝试使用以下代码将一些扩展数据附加到现有实体:
OdResBufPtr pRb=OdResBuf::newRb(OdResBuf::kDxfRegAppName,strippname)
pRb->setNext(OdResBuf::newRb(OdResBuf::kdxfstring,myString))
pRb->last()->setNext(OdResBuf::newRb(OdResBuf::kDxfXdInteger16,someInteger))
OdResBufPtr-podresbufptrr=pEnt->xData(_T(“my_APP”)
OdString:myString=pOdResBufPtr->next()->getString()
OdInt16:someInteger=pOdResBufPtr->last()->getInt16()
到此为止还可以,但我如何修改我的someInteger并写回扩展数据
我尝试:
pOdResBufPtr->last()->setNext(OdResBuf::newRb(OdResBuf::kdxfxdInteger 16,someInteger++)
但不起作用,someInteger仍然具有旧值
任何IDEAlast()->setInt16( someInteger++ ) 嗨,丹尼尔
修改现有扩展数据的最佳方式是什么?我是否必须重新创建完整的OdResBufPtr变量,然后使用setXData()将新扩展数据重新附加到我的实体
似乎只有调用pOdResBufPtr->last()->setInt16(someInteger++),才不会记录新的整数值。
谢谢
稍微玩转这段代码,看看是否可以更新扩展数据。
#pragma once
class CommandDoIt : public OdStaticRxObject
{
public:
const OdString localName() const { return globalName(); }
const OdString groupName() const { return DD_T("DoIt"); }
const OdString globalName() const { return OdString("DoIt"); }
void execute(OdEdCommandContext* pCmdCtx)
{
OdDbCommandContextPtr pDbCmdCtx(pCmdCtx);
OdDbUserIOPtr pDbIO = pDbCmdCtx->dbUserIO();
OdDbDatabasePtr pDb = pDbCmdCtx->database();
//Always keap your head!!!
OdResBufPtr pHead = OdResBuf::newRb(OdResBuf::kDxfXdInteger16, (short)0);
OdResBufPtr pTail = pHead;
for(short i = 1 ; i setNext(OdResBuf::newRb(OdResBuf::kDxfXdInteger16, i));
}
for(OdResBufPtr pTemp = pHead; !pTemp.isNull() ; pTemp = pTemp->next())
{
sds_printf(_T("\n%d"), pTemp->getInt16());
}
for(OdResBufPtr pTemp = pHead; !pTemp.isNull() ; pTemp = pTemp->next())
{
pTemp->setInt16(short(pTemp->getInt16() + 100));
}
for(OdResBufPtr pTemp = pHead; !pTemp.isNull() ; pTemp = pTemp->next())
{
sds_printf(_T("\n%d"), pTemp->getInt16());
}
}
};
嗨丹尼尔!
谢谢你的例子,不幸的是,仍然不适合我。我有以下情况:对于实体,我尝试附加两个东西:字符串和整数。
使用 xData info 设置实体的第一个操作:
OdResBufPtr pHead = OdResBuf::newRb(OdResBuf::kDxfRegAppName, strAppName);
OdResBufPtr pTail = pHead;
pTail=pTail->setNext(OdResBuf::newRb(OdResBuf::kDxfXdAsciiString, myString));
pTail=pTail->setNext(OdResBuf::newRb(OdResBuf::kDxfXdInteger16, someInteger));
myObjId.safeOpenObject(OdDb::kForWrite)->setXData(pHead);
pHead.release();
pTail.release();
在我的代码中的某个时刻,我尝试只更改整数(这不再是一个索引)。ResBuf的其余部分保持不变!
我试过这个:
//second action: try to modify the integer xData
OdResBufPtr pHead=pEnt->xData(strAppName);
if(!pHead.isNull())
{
OdResBufPtr pTail = pHead;
pTail=pTail->next();
OdString myString=pTail->getString();
pTail=pTail->next();
OdInt16 someInteger=pTail->getInt16();
pTail->setInt16(someInteger++);
myObjId.safeOpenObject(OdDb::kForWrite)->setXData(pHead);
pHead.release();
pTail.release();
}
我尝试访问修改后的整数 xData - someInt - 但我仍然得到与第一点相同的初始值。我需要最快的解决方案,因为这个例程必须在大量的entites上工作(一千个也许更多),并且读/修改/写必须非常快。
怎么了?
话筒
请查看此代码
#pragma once
// (entget(car(entsel)) '("MYAPP"))
class CommandPutIt : public OdStaticRxObject
{
public:
const OdString localName() const { return globalName(); }
const OdString groupName() const { return DD_T("putIt"); }
const OdString globalName() const { return OdString("putIt"); }
void execute(OdEdCommandContext* pCmdCtx)
{
OdDbCommandContextPtr pDbCmdCtx(pCmdCtx);
OdDbUserIOPtr pDbIO = pDbCmdCtx->dbUserIO();
OdDbDatabasePtr pDb = pDbCmdCtx->database();
__int64 freq, start, end;
try
{
if(pDb.isNull())
throw OdError(eNoDatabase);
if(!pDb->newRegApp(DD_T("MYAPP")))
throw OdError("Can't Register appname");
OdDbSelectionSetPtr pSS = pDbIO->select(DD_T("Select Entities: "));
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
QueryPerformanceCounter((LARGE_INTEGER*)&start);
OdDbObjectIdArray ids = pSS->objectIdArray();
OdResBufPtr pHead = OdResBuf::newRb(OdResBuf::kDxfRegAppName,DD_T("MYAPP") );
OdResBufPtr pTail = pHead;
pTail = pTail->setNext(OdResBuf::newRb( OdResBuf::kDxfXdAsciiString, DD_T("String") ));
pTail = pTail->setNext(OdResBuf::newRb( OdResBuf::kDxfXdInteger16, (short)32 ));
for(size_t iter = 0 ; iter setXData(pHead);
}
}
catch (OdError& e)//++-- Catch OdExceptions
{
pDbIO->putString("\n" + e.description());
}
QueryPerformanceCounter((LARGE_INTEGER*)&end);
sds_printf(_T("\n%g Seconds\n"), (double)(end - start) / (double) freq);
}
};
class CommandGetIt : public OdStaticRxObject
{
public:
const OdString localName() const { return globalName(); }
const OdString groupName() const { return DD_T("GetIt"); }
const OdString globalName() const { return OdString("GetIt"); }
void execute(OdEdCommandContext* pCmdCtx)
{
OdDbCommandContextPtr pDbCmdCtx(pCmdCtx);
OdDbUserIOPtr pDbIO = pDbCmdCtx->dbUserIO();
OdDbDatabasePtr pDb = pDbCmdCtx->database();
__int64 freq, start, end;
try
{
if(pDb.isNull())
throw OdError(eNoDatabase);
OdDbSelectionSetPtr pSS = pDbIO->select(DD_T("Select Entities: "));
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
QueryPerformanceCounter((LARGE_INTEGER*)&start);
OdDbObjectIdArray ids = pSS->objectIdArray();
for(size_t iter = 0 ; iter xData(DD_T("MYAPP"));
if(pHead.isNull())
continue;
OdResBufPtr pTail = pHead;
pTail = pTail->next();
pTail->setString(DD_T("New String"));
pTail = pTail->next();
pTail->setInt16( (short) 64);
pEnt->setXData(pHead);
}
}
catch (OdError& e)//++-- Catch OdExceptions
{
pDbIO->putString("\n" + e.description());
}
QueryPerformanceCounter((LARGE_INTEGER*)&end);
sds_printf(_T("\n%g Seconds\n"), (double)(end - start) / (double) freq);
}
};
这套程序完美无瑕<这是我的错误<再次感谢你,丹尼尔<迈克
页:
[1]