资源描述:
《在objectarx中创建对象》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、在ObjectARX中创建对象本节中的ObjectARX源代码创建了与之前完全相同的实体(直线和圆),并演示了创建一个新层、改变线的颜色和添加到组词典中的过程创建实体下列代码创建了直线并将其添加到模型空间块表记录中:AcDbObjectldcreateLine()//创建直线{AcGePoint3dstartPt(4.0,2.0,0.0);//起点AcGePoint3dendPt(10.0,7.0,0.0);//终点AcDbLine*pLine=newAcDbLine(startPt,endPt);//内存中创建新的直线AcDbBlockTable*
2、pBlockTable;acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable,AcDb::kForRead);AcDbBlockTableRecord*pBlockTableRecord;pBlockTable->getAt(ACDB_MODEL一SPACE,pBlockTableRecord,AcDb::kForWrite);pBlockTable->close();AcDbObjectldlineld;pBlockTableRecord->appe
3、ndAcDbEntity(lineld,pLine);pBlockTableRecord->close();pLine->close();returnlineld;}createLine()程序从当前图形中获取块表,然后以写模式打幵模型空间块表记录.关闭块表后添加实体到块表记录并关闭块表记录和实体注意当用完任何ObjectARX对象后,必须尽早地将其关闭下面的createCircle()程序创建一个圆并将其添加到模型空间块表记录中AcDbObjectldcreateCircle()AcGePoint3dcenter(9.0,3.0,0.0);AcGe
4、Vector3dnormal(0.0,0.0,1,0);AcDbCircle*pCirc=newAcDbCircle(center,normal,2.0);AcDbBlockTable*pBlockTable;acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable,AcDb::kForRead);AcDbBlockTableRecord*pBlockTableRecord;pBlockTable->getAt(ACDB_MODEL_SPACE,pBloc
5、kTableRecord,AcDb::kForWrite);pBlockTable->close();AcDbObjectldcircleld;pBlockTableRecord->appendAcDbEntity(circleld,pCirc);pBlockTableRecord->close();pCirc->close();returncircleld;}下面的代码从数据库中获得层表,创建一个新的层表记录,并将其命名为ASDK_MYLAYER,然后将层表记录添加到层表中voidcreateNewLayer(){AcDbLayerTable*pL
6、ayerTable;acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTable,AcDb::kForWrite);AcDbLayerTableRecord*pLayerTableRecord=newAcDbLayerTableRecord;pLayerTableRecord->setName("ASDK_MYLAYER");//Defaultsareusedforotherpropertiesof//thelayeriftheyarenototherwise
7、specified.IIpLayerTable->add(pLayerTableRecord);pLayerTable->close();pLayerTableRecord->close();}丁开和关闭ObjectARX对象上述所有程序的例子都说明了打开和关闭对象的协议,每当我们操作数据库驻留对象时都要遵守该协议.该协议确保当对象被访问时在物理内存中,而当对象未被访问时可以被分页存储到磁盘中。在我们可以修改对象之前,必须打幵它,例如:acdbOpenObject(pObject,objld,AcDb::kForWrite);打开函数有一个模式参数,
8、用来说明要打开的对象是用于读、写或是通知操作.当以写模式打开对象时,我们可以对其进行修改;当我们使用完对象后