C++ ARX二次开发扩展数据

一、本节课程
C++
ARX二次开发扩展数据

二、本节要讲解的知识点

1、如何向实体添加扩展数据

2、如何获得扩展数据并且显示出来

3、如何删除扩展数据

三、具体内容

1、为什么要使用扩展数据:在编程时,某些时候不可避免的要向图形中添加一些用户数据,例如,要将一条直线认为是输电线路、道路中心线、或者是其他的对象,有时候也需要将图形的编号等信息随着图形一起保存。

2、一个实体所附加扩展数据最大不能超过16K

3、向AcDbObject对象附加扩展数据的方法是:

virtual Acad::ErrorStatus setXData(

    const resbuf* xdata

);

获取对象的扩展数据的方法是:

virtual resbuf* xData(

    const ACHAR* regappName = nullptr

) const;

  xData

xData 

Returns a linked list of resbuf structures containing a copy of the xdata for the object. If regappName == NULL is passed in, all xdata is returned, otherwise only the xdata for the specified name is returned. If not all xdata is required, but the xdata for more than one regappName is desired, then multiple calls to this member function must be made--one for each regappName.
The caller of this function is responsible for releasing the memory used by the resbuf list that is returned. The most commonly used way to deallocate such a list is via the acutRelRb()... more 

4、设置扩展数据、获取扩展数据的实例

static void YunyouMyGroupAddXData()

{

AcDbEntity *pEnt=NULL;

AcGePoint3d pickPoint;

if (CSelectUtil::PromptSelctEnts(TEXT("\n选择所要添加扩展数据的实体:"),AcDbEntity::desc(),pEnt,pickPoint))

{

CString appName=TEXT("XDataApp");

acdbRegApp(appName);

struct  resbuf *rb=acutBuildList(AcDb::kDxfRegAppName,appName,

AcDb::kDxfXdAsciiString,TEXT("字符串测试数据"),

AcDb::kDxfXdInteger32,2,

AcDb::kDxfXdReal,3.14,

AcDb::kDxfXdWorldXCoord,asDblArray(pickPoint),

RTNONE);

pEnt->setXData(rb);

acutRelRb(rb);

acutPrintf(TEXT("\n成功为实体添加了扩展数据"));

pEnt->close();

}

结果显示我们成功地拾取到实体,并且将扩展数据添加到选择的实体上,应用ARXDBG工具查看到了我们添加的扩展数据。

 

四、总结

1、提示用户选择实体的函数封装,函数封装是实现代码重用的好方法,能节省大量工作量。

2、成功地实现了扩展数据的添加,ARXDBG工具是查看各种实体信息的有力工具。

3、扩展数据的查看和删除命令下节课实现。


视频课程由yunyou.ke.qq.com提供

猜你喜欢

转载自blog.csdn.net/yunyouxy/article/details/81036251
今日推荐