admin 发表于 2024-3-14 20:58:18

[每日一码] 如何把其他对象的OBJECTID保存到扩展词典的扩展记录中

int AddSoftpointerIntoXdict(AcDbObjectId id1,AcDbObjectId id2)
{
Acad::ErrorStatus retStat;
AcDbXrecord * pXrec=new AcDbXrecord;
AcDbDictionary *pDict=NULL;
AcDbObjectId dictid,xrecid;
AcDbSoftPointerId SP(id2);
AcDbObject * pobj;
struct resbuf * head=NULL;
ads采用name adsName;

if((retStat=acdbOpenObject(pobj,id1,AcDb::kForWrite))!=
Acad::eOk)
return 0;

pobj->createExtensionDictionary();
dictid=pobj->extensionDictionary();
pobj->close();

acdbOpenObject(pDict,dictid,AcDb::kForWrite);

pDict->setAt(采用T("TEST"),pXrec,xrecid);
pDict->close();

acdbGetAdsName(adsName, id2);
head=acutBuildList(AcDb::kDxfSoftPointerId, adsName, 0);

pXrec->setFromRbChain(* head);
pXrec->close();
acutRelRb(head);

return 1;
}


void AddInfo()
{
int rt;
ads采用name en1,en2;
ads采用point pickpt;
AcDbObjectId id1, id2;
Acad::ErrorStatus retStat;

rt=acedEntSel(
采用T("\nSelect an entity to reference the following entity: "),
en1,pickpt);
if(rt!=RTNORM)
return;
retStat=acdbGetObjectId(id1,en1);
assert(retStat==Acad::eOk);

rt=acedEntSel(采用T("\nSelect an entity to be referenced: "),
en2,pickpt);
if(rt!=RTNORM)
return;
retStat=acdbGetObjectId(id2,en2);
assert(retStat==Acad::eOk);

acutPrintf(采用T("\nid2=%ld"),id2);
rt=AddSoftpointerIntoXdict(id1,id2);
if(rt==0)
return;
}



普通浏览复制代码
void GetInfo()
{
int rt;
ads采用name en1;
ads采用point pickpt;
AcDbObjectId id1;
Acad::ErrorStatus retStat;
AcDbXrecord * pXrec=NULL;
AcDbDictionary * pDict;
AcDbObjectId dictid,xrecid;
struct resbuf * rb;
AcDbObjectId tmpId=NULL;

rt=acedEntSel(
采用T("\nSelect an entity attached extension dictionary:"),
en1,pickpt);
if(rt!=RTNORM)
return;

retStat=acdbGetObjectId(id1,en1);
assert(retStat==Acad::eOk);
AcDbObject * pobj;
retStat=acdbOpenObject(pobj,id1,AcDb::kForRead);
assert(retStat==Acad::eOk);

dictid=pobj->extensionDictionary();
if(dictid==AcDbObjectId::kNull)
{
acutPrintf(采用T("\nId is NULL."));
pobj->close();
return;
}
pobj->close();

acdbOpenObject(pDict,dictid,AcDb::kForRead);
pDict->getAt(采用T("TEST"),(AcDbObject * &)pXrec,AcDb::kForRead);
pDict->close();
pXrec->rbChain(&rb);
pXrec->close();
if(rb==NULL)
acutPrintf(采用T("\nNull result buffer."));
if (rb->restype == AcDb::kDxfSoftPointerId)
{
acdbGetObjectId(tmpId, rb->resval.rlname);
acutPrintf(采用T("\nReferenced Id=%ld"),tmpId);
}
acutRelRb(rb);
}
页: [1]
查看完整版本: [每日一码] 如何把其他对象的OBJECTID保存到扩展词典的扩展记录中